/*input
5
1 8 7 2 4
9 7 2 9 3

*/

#include <bits/stdc++.h>

using namespace std;

typedef long long ll;
typedef unsigned long long ull;
typedef pair<int,int> PII;
typedef pair<ll , ll> PLL;
typedef long double ld;

#define pb push_back
#define all(c) c.begin(),c.end()
#define allr(c) c.rbegin(),c.rend()
int mod = 998244353;
#define PI 3.14159265
#define endl '\n'
#define debug(x) cout << #x << " = " << x << endl;

template < typename T > T GCD(T a, T b)            { ll t; while(a) { t = a; a = b % a; b = t; } return b; }
template < typename T > string toString(T a)       { return to_string(a); }
template < typename T > void toInt(string s, T &x) { stringstream str(s); str >> x;}
inline int add(int x, int y){ x += y; if(x >= mod) x -= mod; return x;}
inline int sub(int x, int y){ x -= y; if(x < 0) x += mod; return x;}
inline int mul(int x, int y){ return (x * 1ll * y) % mod;}
inline int powr(int a, ll b){
    int x = 1 % mod;
    while(b){
        if(b & 1) x = mul(x, a);
        a = mul(a, a);
        b >>= 1;
    }
    return x;
}
inline int inv(int a){ return powr(a, mod - 2);}

int main()
{
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);

  int n;
  cin >> n;
  ll v;
  vector <ll> vec1, vec2;
  ll time = 0;
  for (int i = 0; i < n; i++) {
    cin >> v;
    time = ((i + 1) * (n - i));
    vec1.pb((v * time) % mod);
  }
  for (int i = 0; i < n; i++) {
    cin >> v;
    vec2.pb(v);
  }
  sort(all(vec1));
  sort(allr(vec2));
  ll ans = 0;
  for (int i = 0; i < n; i++) {
    ans = ((ans % mod) + ((vec1[i] % mod) * 1ll * (vec2[i] % mod)) % mod) % mod;
    if (ans >= mod) {
      ans %= mod;
    }
    if (ans < 0) {
      ans += mod;
    }
    ans %= mod;
  }
  ans %= mod;
  if (ans < 0) {
    ans += mod;
  }
  cout << ans % mod << endl;
  return 0;
}


#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const ll mod = 998244353;
int main()
{
	int t=1;
	//cin>>t;
	while(t--)
	{
		int n;
		cin>>n;
		vector<ll>a(n) , b(n);
		for(int i=0;i<n;i++)
			cin>>a[i];
		for(int i=0;i<n;i++)
			cin>>b[i];
		vector<ll> val(n);
		for(ll i=0;i<n;i++)
		{
			ll x = (i+1) * (n-i) * 1ll;
			a[i] = (a[i] * x * 1ll );
		}
		for (int i = 0; i < n; i++) {
	//		val[i] = (i + 1) * 1ll * (n - i) * a[i];
			//val[i].second = i;
		}
		sort(a.begin(),a.end());
		sort(b.rbegin(),b.rend());
		ll ans = 0;
		for(int i=0;i<n;i++)
		{
		//	cout<<a[i]<<" "<<b[i]<<endl;
			ans = ( ans + ((a[i] % mod) * b[i] * 1ll) % mod ) % mod ;
		}
		cout<<ans<<endl;
	}
    return 0;
}


#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const ll mod = 998244353;
int main()
{
	int t=1;
	//cin>>t;
	while(t--)
	{
		ll n;
		cin>>n;
		vector<ll>a(n) , b(n);
		for(int i=0;i<n;i++)
			cin>>a[i];
		for(int i=0;i<n;i++)
			cin>>b[i];
		vector<ll> val(n);
		for(ll i=0;i<n;i++)
		{
			ll x = ll((i+1) * (n-i)) ;
			a[i] = (a[i] * x * 1ll );
		}
		for (int i = 0; i < n; i++) {
	//		val[i] = (i + 1) * 1ll * (n - i) * a[i];
			//val[i].second = i;
		}
		sort(a.begin(),a.end());
		sort(b.rbegin(),b.rend());
		ll ans = 0;
		for(int i=0;i<n;i++)
		{
		//	cout<<a[i]<<" "<<b[i]<<endl;
			ans = ( ans + ((a[i] % mod) * b[i] * 1ll) % mod ) % mod ;
		}
		cout<<ans<<endl;
	}
    return 0;
}


#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const ll mod = 998244353;
int main()
{
	int t=1;
	//cin>>t;
	while(t--)
	{
		ll n;
		cin>>n;
		vector<ll>a(n) , b(n);
		for(int i=0;i<n;i++)
			cin>>a[i];
		for(int i=0;i<n;i++)
			cin>>b[i];
		vector<ll> val(n);
		for(int i=0;i<n;i++)
		{
			ll x = ll((i+1) * (n-i)) ;
			a[i] = (a[i] * x * 1ll );
		}
		for (int i = 0; i < n; i++) {
	//		val[i] = (i + 1) * 1ll * (n - i) * a[i];
			//val[i].second = i;
		}
		sort(a.begin(),a.end());
		sort(b.rbegin(),b.rend());
		ll ans = 0;
		for(int i=0;i<n;i++)
		{
		//	cout<<a[i]<<" "<<b[i]<<endl;
			ans = ( ans + ((a[i] % mod) * b[i] * 1ll) % mod ) % mod ;
		}
		cout<<ans<<endl;
	}
    return 0;
}


#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
#define mod 998244353
int main()
{
	int t=1;
	//cin>>t;
	while(t--)
	{
		int n;
		cin>>n;
		ll a[n] , b[n];
		for(int i=0;i<n;i++)
			cin>>a[i];
		for(int i=0;i<n;i++)
			cin>>b[i];
		for(int i=0;i<n;i++)
		{
			ll x = ((i+1) * (n-i));
			a[i] = (a[i] * x)  ;
		}
		sort(a,a+n);
		sort(b,b+n);
		ll ans = 0;
		for(int i=0;i<n;i++)
		{
		//	cout<<a[i]<<" "<<b[i]<<endl;
			ans = ( ans + ((a[i]% mod) * b[n-1-i] * 1ll)%mod ) % mod;
		}
		cout<<ans<<endl;
	}
    return 0;
}


#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const ll mod = 998244353;
int main()
{
	int t=1;
	//cin>>t;
	while(t--)
	{
		int n;
		cin>>n;
		vector<ll>a(n) , b(n);
		for(int i=0;i<n;i++)
			cin>>a[i];
		for(int i=0;i<n;i++)
			cin>>b[i];
		vector<ll> val(n);
		for(int i=0;i<n;i++)
		{
			a[i] = (a[i] * (i+1) * (n-i) * 1ll );
		}
		for (int i = 0; i < n; i++) {
	//		val[i] = (i + 1) * 1ll * (n - i) * a[i];
			//val[i].second = i;
		}
		sort(a.begin(),a.end());
		sort(b.rbegin(),b.rend());
		ll ans = 0;
		for(int i=0;i<n;i++)
		{
		//	cout<<a[i]<<" "<<b[i]<<endl;
			ans = ( ans + ((a[i] % mod) * b[i] * 1ll) % mod ) % mod ;
		}
		cout<<ans<<endl;
	}
    return 0;
}


#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const ll mod = 998244353;
int main()
{
	int t=1;
	//cin>>t;
	while(t--)
	{
		int n;
		cin>>n;
		vector<ll>a(n) , b(n);
		for(int i=0;i<n;i++)
			cin>>a[i];
		for(int i=0;i<n;i++)
			cin>>b[i];
		vector<ll> val(n);
		for(int i=0;i<n;i++)
		{
			ll x = ll((i+1) * (n-i)) ;
			a[i] = (a[i] * x * 1ll );
		}
		for (int i = 0; i < n; i++) {
	//		val[i] = (i + 1) * 1ll * (n - i) * a[i];
			//val[i].second = i;
		}
		sort(a.begin(),a.end());
		sort(b.rbegin(),b.rend());
		ll ans = 0;
		for(int i=0;i<n;i++)
		{
		//	cout<<a[i]<<" "<<b[i]<<endl;
			ans = ( ans + ((a[i] % mod) * b[i] * 1ll) % mod ) % mod ;
		}
		cout<<ans<<endl;
	}
    return 0;
}


#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const ll mod = 998244353;
int main()
{
	int t=1;
	//cin>>t;
	while(t--)
	{
		int n;
		cin>>n;
		vector<ll>a(n) , b(n);
		for(int i=0;i<n;i++)
			cin>>a[i];
		for(int i=0;i<n;i++)
			cin>>b[i];
		vector<ll> val(n);
		for(int i=0;i<n;i++)
		{
			val[i] = (a[i] * (i+1) * 1ll * (n-i) );
		}
		for (int i = 0; i < n; i++) {
	//		val[i] = (i + 1) * 1ll * (n - i) * a[i];
			//val[i].second = i;
		}
		sort(val.begin(),val.end());
		sort(b.rbegin(),b.rend());
		ll ans = 0;
		for(int i=0;i<n;i++)
		{
		//	cout<<a[i]<<" "<<b[i]<<endl;
			ans = ( ans + ((val[i] % mod) * b[i] * 1ll) % mod ) % mod ;
		}
		cout<<ans<<endl;
	}
    return 0;
}


#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const ll mod = 998244353;
int main()
{
	int t=1;
	//cin>>t;
	while(t--)
	{
		int n;
		cin>>n;
		vector<ll>a(n) , b(n);
		for(int i=0;i<n;i++)
			cin>>a[i];
		for(int i=0;i<n;i++)
			cin>>b[i];
		for(int i=0;i<n;i++)
		{
			ll x = ((i+1) * (n-i));
			a[i] = (a[i] * x) * 1ll ;
		}
		sort(a.begin(),a.end());
		sort(b.rbegin(),b.rend());
		ll ans = 0;
		for(int i=0;i<n;i++)
		{
		//	cout<<a[i]<<" "<<b[i]<<endl;
			ans = ( ans + ((a[i] % mod) * b[i] * 1ll) % mod ) % mod ;
		}
		cout<<ans<<endl;
	}
    return 0;
}


#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const ll mod = 998244353;
int main()
{
	int t=1;
	//cin>>t;
	while(t--)
	{
		int n;
		cin>>n;
		vector<ll>a(n) , b(n);
		for(int i=0;i<n;i++)
			cin>>a[i];
		for(int i=0;i<n;i++)
			cin>>b[i];
		vector<ll> val(n);
		for(int i=0;i<n;i++)
		{
			ll x = ((i+1) * (n-i));
			val[i] = (a[i] * x) * 1ll ;
		}
		for (int i = 0; i < n; i++) {
	//		val[i] = (i + 1) * 1ll * (n - i) * a[i];
			//val[i].second = i;
		}
		sort(val.begin(),val.end());
		sort(b.rbegin(),b.rend());
		ll ans = 0;
		for(int i=0;i<n;i++)
		{
		//	cout<<a[i]<<" "<<b[i]<<endl;
			ans = ( ans + ((val[i] % mod) * b[i] * 1ll) % mod ) % mod ;
		}
		cout<<ans<<endl;
	}
    return 0;
}


#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const ll mod = 998244353;
int main()
{
	int t=1;
	//cin>>t;
	while(t--)
	{
		int n;
		cin>>n;
		vector<ll>a(n) , b(n);
		for(int i=0;i<n;i++)
			cin>>a[i];
		for(int i=0;i<n;i++)
			cin>>b[i];
		for(int i=0;i<n;i++)
		{
//			ll x = ((i+1) * (n-i));
	//		a[i] = (a[i] * x) * 1ll ;
		}
		vector<pair<ll,int > > val(n);
		for (int i = 0; i < n; i++) {
			val[i].first = (i + 1) * 1ll * (n - i) * a[i];
			val[i].second = i;
		}
		sort(val.begin(),val.end());
		sort(b.rbegin(),b.rend());
		ll ans = 0;
		for(int i=0;i<n;i++)
		{
		//	cout<<a[i]<<" "<<b[i]<<endl;
			ans = ( ans + ((val[i].first % mod) * b[i] * 1ll) % mod ) % mod ;
		}
		cout<<ans<<endl;
	}
    return 0;
}


#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
#define mod 998244353
int main()
{
	int t=1;
	//cin>>t;
	while(t--)
	{
		int n;
		cin>>n;
		ll a[n] , b[n];
		for(int i=0;i<n;i++)
			cin>>a[i];
		for(int i=0;i<n;i++)
			cin>>b[i];
		for(int i=0;i<n;i++)
		{
			ll x = ((i+1) * (n-i)) % mod ;
			a[i] = (a[i] * x) % mod ;
		}
		sort(a,a+n);
		sort(b,b+n);
		ll ans = 0;
		for(int i=0;i<n;i++)
		{
		//	cout<<a[i]<<" "<<b[i]<<endl;
			ans = ( ans + (a[i]*b[n-1-i])%mod ) % mod;
		}
		cout<<ans<<endl;
	}
    return 0;
}


#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
#define mod 998244353
int main()
{
	int t=1;
	//cin>>t;
	while(t--)
	{
		int n;
		cin>>n;
		ll a[n] , b[n];
		for(int i=0;i<n;i++)
			cin>>a[i];
		for(int i=0;i<n;i++)
			cin>>b[i];
		for(int i=0;i<n;i++)
		{
			ll x = (i+1) * (n-i);
			a[i] = a[i] * x ;
		}
		sort(a,a+n);
		sort(b,b+n);
		ll ans = 0;
		for(int i=0;i<n;i++)
		{
		//	cout<<a[i]<<" "<<b[i]<<endl;
			ans = ( ans + (a[i]*b[n-1-i])%mod ) % mod;
		}
		cout<<ans<<endl;
	}
    return 0;
}


#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const ll mod = 998244353;
int main()
{
	int t=1;
	//cin>>t;
	while(t--)
	{
		int n;
		cin>>n;
		vector<ll>a(n) , b(n);
		for(int i=0;i<n;i++)
			cin>>a[i];
		for(int i=0;i<n;i++)
			cin>>b[i];
		vector<ll> val(n);
		for(int i=0;i<n;i++)
		{
			ll x = (i+1) * (n-i) * 1ll;
			a[i] = (a[i] * x * 1ll );
		}
		for (int i = 0; i < n; i++) {
	//		val[i] = (i + 1) * 1ll * (n - i) * a[i];
			//val[i].second = i;
		}
		sort(a.begin(),a.end());
		sort(b.rbegin(),b.rend());
		ll ans = 0;
		for(int i=0;i<n;i++)
		{
		//	cout<<a[i]<<" "<<b[i]<<endl;
			ans = ( ans + ((a[i] % mod) * b[i] * 1ll) % mod ) % mod ;
		}
		cout<<ans<<endl;
	}
    return 0;
}


#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const ll mod = 998244353;
int main()
{
	int t=1;
	//cin>>t;
	while(t--)
	{
		int n;
		cin>>n;
		vector<ll>a(n) , b(n);
		for(int i=0;i<n;i++)
			cin>>a[i];
		for(int i=0;i<n;i++)
			cin>>b[i];
		vector<ll> val(n);
		for(int i=0;i<n;i++)
		{
			ll x = (i+1) * (n-i);
			a[i] = (a[i] * x * 1ll );
		}
		for (int i = 0; i < n; i++) {
	//		val[i] = (i + 1) * 1ll * (n - i) * a[i];
			//val[i].second = i;
		}
		sort(a.begin(),a.end());
		sort(b.rbegin(),b.rend());
		ll ans = 0;
		for(int i=0;i<n;i++)
		{
		//	cout<<a[i]<<" "<<b[i]<<endl;
			ans = ( ans + ((a[i] % mod) * b[i] * 1ll) % mod ) % mod ;
		}
		cout<<ans<<endl;
	}
    return 0;
}


#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const ll mod = 998244353;
int main()
{
	int t=1;
	//cin>>t;
	while(t--)
	{
		int n;
		cin>>n;
		vector<ll>a(n) , b(n);
		for(int i=0;i<n;i++)
			cin>>a[i];
		for(int i=0;i<n;i++)
			cin>>b[i];
		vector<ll> val(n);
		for(int i=0;i<n;i++)
		{
			a[i] = (a[i] * (i+1) * 1ll * (n-i) );
		}
		for (int i = 0; i < n; i++) {
	//		val[i] = (i + 1) * 1ll * (n - i) * a[i];
			//val[i].second = i;
		}
		sort(a.begin(),a.end());
		sort(b.rbegin(),b.rend());
		ll ans = 0;
		for(int i=0;i<n;i++)
		{
		//	cout<<a[i]<<" "<<b[i]<<endl;
			ans = ( ans + ((a[i] % mod) * b[i] * 1ll) % mod ) % mod ;
		}
		cout<<ans<<endl;
	}
    return 0;
}


#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const ll mod = 998244353;
int main()
{
	int t=1;
	//cin>>t;
	while(t--)
	{
		int n;
		cin>>n;
		vector<ll>a(n) , b(n);
		for(int i=0;i<n;i++)
			cin>>a[i];
		for(int i=0;i<n;i++)
			cin>>b[i];
		for(int i=0;i<n;i++)
		{
//			ll x = ((i+1) * (n-i));
	//		a[i] = (a[i] * x) * 1ll ;
		}
		vector<ll> val(n);
		for (int i = 0; i < n; i++) {
			val[i] = (i + 1) * 1ll * (n - i) * a[i];
			//val[i].second = i;
		}
		sort(val.begin(),val.end());
		sort(b.rbegin(),b.rend());
		ll ans = 0;
		for(int i=0;i<n;i++)
		{
		//	cout<<a[i]<<" "<<b[i]<<endl;
			ans = ( ans + ((val[i] % mod) * b[i] * 1ll) % mod ) % mod ;
		}
		cout<<ans<<endl;
	}
    return 0;
}


#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
#define mod 998244353
int main()
{
	int t=1;
	//cin>>t;
	while(t--)
	{
		int n;
		cin>>n;
		ll a[n] , b[n];
		for(int i=0;i<n;i++)
			cin>>a[i];
		for(int i=0;i<n;i++)
			cin>>b[i];
		for(int i=0;i<n;i++)
		{
			ll x = ((i+1) * (n-i) % mod ;
			a[i] = (a[i] * x) % mod ;
		}
		sort(a,a+n);
		sort(b,b+n);
		ll ans = 0;
		for(int i=0;i<n;i++)
		{
		//	cout<<a[i]<<" "<<b[i]<<endl;
			ans = ( ans + (a[i]*b[n-1-i])%mod ) % mod;
		}
		cout<<ans<<endl;
	}
    return 0;
}


#include<bits/stdc++.h>
using namespace std;
#define pb push_back
#define int long long
#define pii pair<int,int>
#define ff first
#define ss second
#define mii map<int,int>
#define si set<int>
#define sti stack<int>
#define qi queue<int>
#define vi vector<int>
const int M=998244353;

int Sum(int a[],int n)
{
    int ans=0;
    for(int i=0;i<n;i++)
        ans=(ans+((a[i]%M*(i+1)%M)%M*(n-i)%M)%M)%M;
    return ans;
}

int32_t main()
{
	int n;
	cin>>n;
	int a[n],b[n];
	int x[n],y[n];

	for(int i=0;i<n;i++)
		cin>>a[i],x[i]=a[i];
	sort(x,x+n);
	for(int i=0;i<n;i++)
		cin>>b[i];
	sort(b,b+n);
	for(int i=0;i<n;i++)
		y[i]=b[n-1-i];

	multimap <int,int> m;
	for(int i=0;i<n;i++)
		m.insert(pii(x[i],y[i]));

	for(int i=0;i<n;i++)
	{
		multimap <int,int>:: iterator it;
		it=m.find(a[i]);
		b[i]=it->ss;
		m.erase(it);
	}
	/*for(int i=0;i<n;i++)
		cout<<a[i]<<" "<<b[i]<<endl;*/
	int A[n];
	for(int i=0;i<n;i++)
		A[i]=a[i]*b[i];
	cout<<Sum(A,n);
}


#include<bits/stdc++.h>
using namespace std;
#define pb push_back
#define int long long
#define pii pair<int,int>
#define ff first
#define ss second
#define mii map<int,int>
#define si set<int>
#define sti stack<int>
#define qi queue<int>
#define vi vector<int>
#define M 998244353

/*int Sum(int a[],int n)
{
    int ans=0;
    for(int i=0;i<n;i++)
        ans=(ans+((a[i]%M*(i+1)%M)%M*(n-i)%M)%M)%M;
    return ans;
}*/

int32_t main()
{
	int n;
	cin>>n;
	int a[n],b[n];
	int x[n],y[n];
	for(int i=0;i<n;i++)
	{
		cin>>a[i];
		a[i]=a[i]*(i+1);
		a[i]=a[i]*(n-i);
		x[i]=a[i];
	}
	sort(x,x+n);
	for(int i=0;i<n;i++)
		cin>>b[i];
	sort(b,b+n);
	for(int i=0;i<n;i++)
		y[i]=b[n-1-i];

	multimap <int,int> m;
	for(int i=0;i<n;i++)
		m.insert(pii(x[i],y[i]));

	for(int i=0;i<n;i++)
	{
		multimap <int,int>:: iterator it;
		it=m.find(a[i]);
		b[i]=it->ss;
		m.erase(it);
	}
	/*for(int i=0;i<n;i++)
		cout<<a[i]<<" "<<b[i]<<endl;*/
	int A[n];
	int ans=0,sum;
	for(int i=0;i<n;i++)
	{
		sum=(a[i]%M*b[i]%M)%M;
		ans=(ans%M+sum%M)%M;
	}
	cout<<ans<<endl;
}


#include<bits/stdc++.h>
using namespace std;
#define pb push_back
#define int long long
#define pii pair<int,int>
#define ff first
#define ss second
#define mii map<int,int>
#define si set<int>
#define sti stack<int>
#define qi queue<int>
#define vi vector<int>
const int M=998244353;

int Sum(int a[],int n)
{
    int ans=0;
    for(int i=0;i<n;i++)
        ans+=((a[i]%M*(i+1)%M)%M*(n-i)%M)%M;
    return ans;
}

int32_t main()
{
	int n;
	cin>>n;
	int a[n],b[n];
	int x[n],y[n];

	for(int i=0;i<n;i++)
		cin>>a[i],x[i]=a[i];
	sort(x,x+n);
	for(int i=0;i<n;i++)
		cin>>b[i];
	sort(b,b+n);
	for(int i=0;i<n;i++)
		y[i]=b[n-1-i];

	multimap <int,int> m;
	for(int i=0;i<n;i++)
		m.insert(pii(x[i],y[i]));

	for(int i=0;i<n;i++)
	{
		multimap <int,int>:: iterator it;
		it=m.find(a[i]);
		b[i]=it->ss;
		m.erase(it);
	}
	for(int i=0;i<n;i++)
		cout<<a[i]<<" "<<b[i]<<endl;

	int A[n];
	for(int i=0;i<n;i++)
		A[i]=a[i]*b[i];

	cout<<Sum(A,n);
}


#include<bits/stdc++.h>
using namespace std;
#define pb push_back
#define int long long
#define pii pair<int,int>
#define ff first
#define ss second
#define mii map<int,int>
#define si set<int>
#define sti stack<int>
#define qi queue<int>
#define vi vector<int>
const int M=998244353;

int Sum(int a[],int n)
{
    int ans=0;
    for(int i=0;i<n;i++)
        ans+=((a[i]*(i+1))%M*(n-i))%M;
    return ans;
}

int32_t main()
{
	int n;
	cin>>n;
	int a[n],b[n];
	int x[n],y[n];

	for(int i=0;i<n;i++)
		cin>>a[i],x[i]=a[i];
	sort(x,x+n);
	for(int i=0;i<n;i++)
		cin>>y[i];
	sort(y,y+n,greater<int>());

	multimap <int,int> m;
	for(int i=0;i<n;i++)
		m.insert(pii(x[i],y[i]));

	for(int i=0;i<n;i++)
	{
		multimap <int,int>:: iterator it;
		it=m.find(a[i]);
		b[i]=it->ss;
		m.erase(it);
	}
	int A[n];
	for(int i=0;i<n;i++)
		A[i]=a[i]*b[i];
	cout<<Sum(A,n);
}


#include<bits/stdc++.h>
using namespace std;
#define pb push_back
#define int long long
#define pii pair<int,int>
#define ff first
#define ss second
#define mii map<int,int>
#define si set<int>
#define sti stack<int>
#define qi queue<int>
#define vi vector<int>
#define M 998244353

/*int Sum(int a[],int n)
{
    int ans=0;
    for(int i=0;i<n;i++)
        ans=(ans+((a[i]%M*(i+1)%M)%M*(n-i)%M)%M)%M;
    return ans;
}*/

int32_t main()
{
	int n;
	cin>>n;
	int a[n],b[n];
	int x[n],y[n];
	for(int i=0;i<n;i++)
	{
		cin>>a[i];
		/*a[i]=a[i]*(i+1);
		a[i]=a[i]*(n-i);*/
		x[i]=a[i];
	}
	sort(x,x+n);
	for(int i=0;i<n;i++)
		cin>>b[i];
	sort(b,b+n);
	for(int i=0;i<n;i++)
		y[i]=b[n-1-i];

	multimap <int,int> m;
	for(int i=0;i<n;i++)
		m.insert(pii(x[i],y[i]));

	for(int i=0;i<n;i++)
	{
		multimap <int,int>:: iterator it;
		it=m.find(a[i]);
		b[i]=it->ss;
		m.erase(it);
	}
	/*for(int i=0;i<n;i++)
		cout<<a[i]<<" "<<b[i]<<endl;*/
	int A[n];
	int ans=0,sum;
	for(int i=0;i<n;i++)
	{
		sum=(a[i]%M*b[i]%M)%M;
		sum=(sum%M*(n-i)%M)%M;
		sum=(sum%M*(i-1)%M)%M;
		ans=(ans%M+sum%M)%M;
	}
	cout<<ans<<endl;
}


#include<bits/stdc++.h>
using namespace std;
#define pb push_back
#define int long long
#define pii pair<int,int>
#define ff first
#define ss second
#define mii map<int,int>
#define si set<int>
#define sti stack<int>
#define qi queue<int>
#define vi vector<int>
const int M=998244353;

int Sum(int a[],int n)
{
    int ans=0;
    for(int i=0;i<n;i++)
        ans+=((a[i]%M*(i+1)%M)%M*(n-i)%M)%M;
    return ans;
}

int32_t main()
{
	int n;
	cin>>n;
	int a[n],b[n];
	int x[n],y[n];

	for(int i=0;i<n;i++)
		cin>>a[i],x[i]=a[i];
	sort(x,x+n);
	for(int i=0;i<n;i++)
		cin>>b[i];
	sort(b,b+n);
	for(int i=0;i<n;i++)
		y[i]=b[n-1-i];

	multimap <int,int> m;
	for(int i=0;i<n;i++)
		m.insert(pii(x[i],y[i]));

	for(int i=0;i<n;i++)
	{
		multimap <int,int>:: iterator it;
		it=m.find(a[i]);
		b[i]=it->ss;
		m.erase(it);
	}
	/*for(int i=0;i<n;i++)
		cout<<a[i]<<" "<<b[i]<<endl;*/

	int A[n];
	for(int i=0;i<n;i++)
		A[i]=a[i]*b[i];

	cout<<Sum(A,n);
}


#include<bits/stdc++.h>
using namespace std;
#define pb push_back
#define int long long
#define pii pair<int,int>
#define ff first
#define ss second
#define mii map<int,int>
#define si set<int>
#define sti stack<int>
#define qi queue<int>
#define vi vector<int>
#define M 998244353

/*int Sum(int a[],int n)
{
    int ans=0;
    for(int i=0;i<n;i++)
        ans=(ans+((a[i]%M*(i+1)%M)%M*(n-i)%M)%M)%M;
    return ans;
}*/

int32_t main()
{
	int n;
	cin>>n;
	int a[n],b[n];
	int x[n],y[n];
	for(int i=0;i<n;i++)
		cin>>a[i],x[i]=a[i];
	sort(x,x+n);
	for(int i=0;i<n;i++)
		cin>>b[i];
	sort(b,b+n);
	for(int i=0;i<n;i++)
		y[i]=b[n-1-i];

	multimap <int,int> m;
	for(int i=0;i<n;i++)
		m.insert(pii(x[i],y[i]));

	for(int i=0;i<n;i++)
	{
		multimap <int,int>:: iterator it;
		it=m.lower_bound(a[i]);
		b[i]=it->ss;
		m.erase(it);
	}
	/*for(int i=0;i<n;i++)
		cout<<a[i]<<" "<<b[i]<<endl;*/
	int A[n];
	int ans=0;
	for(int i=0;i<n;i++)
		ans=((((a[i]*b[i])%M*(i+1))%M*(n-i))%M+ans)%M;
	cout<<ans<<endl;
}


#include<bits/stdc++.h>
using namespace std;
#define pb push_back
#define int long long
#define pii pair<int,int>
#define ff first
#define ss second
#define mii map<int,int>
#define si set<int>
#define sti stack<int>
#define qi queue<int>
#define vi vector<int>
#define M 998244353

/*int Sum(int a[],int n)
{
    int ans=0;
    for(int i=0;i<n;i++)
        ans=(ans+((a[i]%M*(i+1)%M)%M*(n-i)%M)%M)%M;
    return ans;
}*/

int32_t main()
{
	int n;
	cin>>n;
	int a[n],b[n];
	int x[n],y[n];
	for(int i=0;i<n;i++)
	{
		cin>>a[i];
		/*a[i]=a[i]*(i+1);
		a[i]=a[i]*(n-i);*/
		x[i]=a[i];
	}
	sort(x,x+n);
	for(int i=0;i<n;i++)
		cin>>b[i];
	sort(b,b+n);
	for(int i=0;i<n;i++)
		y[i]=b[n-1-i];

	multimap <int,int> m;
	for(int i=0;i<n;i++)
		m.insert(pii(x[i],y[i]));

	for(int i=0;i<n;i++)
	{
		multimap <int,int>:: iterator it;
		it=m.find(a[i]);
		b[i]=it->ss;
		m.erase(it);
	}
	/*for(int i=0;i<n;i++)
		cout<<a[i]<<" "<<b[i]<<endl;*/
	int A[n];
	int ans=0,sum;
	for(int i=0;i<n;i++)
	{
		sum=(a[i]%M*b[i]%M*)%M;
		sum=(sum%M*(n-i)%M)%M;
		sum=(sum%M*(i-1)%M)%M;
		ans=(ans%M+sum%M)%M;
	}
	cout<<ans<<endl;
}


#include<bits/stdc++.h>
using namespace std;
#define pb push_back
#define int long long
#define pii pair<int,int>
#define ff first
#define ss second
#define mii map<int,int>
#define si set<int>
#define sti stack<int>
#define qi queue<int>
#define vi vector<int>
const int M=998244353;

int Sum(int a[],int n)
{
    int ans=0;
    for(int i=0;i<n;i++)
        ans=(ans+((a[i]%M*(i+1)%M)%M*(n-i)%M)%M)%M;
    return ans;
}

int32_t main()
{
	int n;
	cin>>n;
	int a[n],b[n];
	int x[n],y[n];
	for(int i=0;i<n;i++)
		cin>>a[i],x[i]=a[i];
	sort(x,x+n);
	for(int i=0;i<n;i++)
		cin>>b[i];
	sort(b,b+n);
	for(int i=0;i<n;i++)
		y[i]=b[n-1-i];

	multimap <int,int> m;
	for(int i=0;i<n;i++)
		m.insert(pii(x[i],y[i]));

	for(int i=0;i<n;i++)
	{
		multimap <int,int>:: iterator it;
		it=m.find(a[i]);
		b[i]=it->ss;
		m.erase(it);
	}
	/*for(int i=0;i<n;i++)
		cout<<a[i]<<" "<<b[i]<<endl;*/
	int A[n];
	for(int i=0;i<n;i++)
		A[i]=(a[i]*b[i])%M;
	cout<<Sum(A,n);
}


#include<bits/stdc++.h>
using namespace std;
#define pb push_back
#define int long long
#define pii pair<int,int>
#define ff first
#define ss second
#define mii map<int,int>
#define si set<int>
#define sti stack<int>
#define qi queue<int>
#define vi vector<int>
const int M=998244353;

int Sum(int a[],int n)
{
    int ans=0;
    for(int i=0;i<n;i++)
        ans+=((a[i]%M*(i+1)%M)%M*(n-i)%M)%M;
    return ans;
}

int32_t main()
{
	int n;
	cin>>n;
	int a[n],b[n];
	int x[n],y[n];

	for(int i=0;i<n;i++)
		cin>>a[i],x[i]=a[i];
	sort(x,x+n);
	for(int i=0;i<n;i++)
		cin>>y[i];
	sort(y,y+n,greater<int>());

	multimap <int,int> m;
	for(int i=0;i<n;i++)
		m.insert(pii(x[i],y[i]));

	for(int i=0;i<n;i++)
	{
		multimap <int,int>:: iterator it;
		it=m.find(a[i]);
		b[i]=it->ss;
		m.erase(it);
	}
	int A[n];
	for(int i=0;i<n;i++)
		A[i]=a[i]*b[i];
	cout<<Sum(A,n);
}


#include<bits/stdc++.h>
using namespace std ;

typedef long long ll ;

#define Size(x)                x.size()
#define debug(x)               cerr << #x << " : " << x << endl
#define debug_vect(v)          for (int i = 0 ; i < Size(v) ; i++) cerr << i << " : " << v[i] << " ,"

const int MAXN = 2e5 ;
const int MOD = 998244353 ;

ll n ,ans ;

bool cmpa (int a ,int b){
	return(a < b) ;
}
bool cmpb (int a ,int b){
	return(a > b) ;
}

int add(int a ,int b){
	int c = a + b ;
	if (c >= MOD){
		c -= MOD ;
	}
	if (c < 0){
		c += MOD ;
	}
	return c ;
}
int mul(ll a ,ll b){
	int c = 1LL * a * b % MOD ;
	return c ;
}

int main (){
	cin >> n ;
	vector <int> a(n) ,b(n) ;
	vector <pair<ll ,int>> part(n) ;
	for (int i = 0 ; i < n ; i++){
		cin >> a[i] ;
	}
	for (int i = 0 ; i < n ; i++){
		cin >> b[i] ;
	}
	for (int i = 0 ; i < n ; i++){
		part[i].first =  (i + 1) * 1ll * a[i] * (n - i) ;
		part[i].second = i ;
	}
	sort(part.rbegin() ,part.rend()) ;
	sort(b.begin() ,b.end()) ;
	for (int i = 0 ; i < n ; i++){
		ans = (ans + (part[i].first % MOD * 1ll * b[i]) % MOD )% MOD ;
	}
	cout << ans  ;
	return 0 ;
}


#include<bits/stdc++.h>
using namespace std ;

typedef long long ll ;

#define Size(x)                x.size()
#define debug(x)               cerr << #x << " : " << x << endl
#define debug_vect(v)          for (int i = 0 ; i < Size(v) ; i++) cerr << i << " : " << v[i] << " ,"

const int MAXN = 2e5 ;
const int MOD = 998244353 ;

ll n ,ans ,a[MAXN] ,b[MAXN] ,part[MAXN] ;

bool cmpa (int a ,int b){
	return(a < b) ;
}
bool cmpb (int a ,int b){
	return(a > b) ;
}

int add(int a ,int b){
	int c = a + b ;
	if (c >= MOD){
		c -= MOD ;
	}
	if (c < 0){
		c += MOD ;
	}
	return c ;
}
int mul(ll a ,ll b){
	int c = 1LL * a * b % MOD ;
	return c ;
}

int main (){
	cin >> n ;
	for (int i = 0 ; i < n ; i++){
		cin >> a[i] ;
	}
	for (int i = 0 ; i < n ; i++){
		cin >> b[i] ;
	}
	for (int i = 0 ; i < n ; i++){
		a[i] = 1LL * a[i] * (i + 1) * (n - i) ;
	}
	sort(a ,a + n ,cmpa) ;
	sort(b ,b + n) ;
	for (int i = 0 ; i < n ; i++){
		ans = (ans + (a[i] % MOD * 1LL * b[i]) % MOD )% MOD ;
	}
	cout << ans  ;
	return 0 ;
}


#include<bits/stdc++.h>
using namespace std ;

typedef long long ll ;

#define Size(x)                x.size()
#define debug(x)               cerr << #x << " : " << x << endl
#define debug_vect(v)          for (int i = 0 ; i < Size(v) ; i++) cerr << i << " : " << v[i] << " ,"

const int MAXN = 2e5 ;
const int MOD = 998244353 ;

ll n ,ans ,a[MAXN] ,b[MAXN] ,part[MAXN] ;

bool cmpa (int a ,int b){
	return(a < b) ;
}
bool cmpb (int a ,int b){
	return(a > b) ;
}

int add(int a ,int b){
	int c = a + b ;
	if (c >= MOD){
		c -= MOD ;
	}
	if (c < 0){
		c += MOD ;
	}
	return c ;
}
int mul(ll a ,ll b){
	int c = 1LL * a * b % MOD ;
	return c ;
}

int main (){
	cin >> n ;
	for (int i = 0 ; i < n ; i++){
		cin >> a[i] ;
	}
	for (int i = 0 ; i < n ; i++){
		cin >> b[i] ;
	}
	for (int i = 1 ; i <= n ; i++){
		a[i - 1] = 1LL * a[i - 1] * i * (n - i + 1) ;
	}
	sort(a ,a + n ,cmpa) ;
	sort(b ,b + n ,cmpb) ;
	for (int i = 0 ; i < n ; i++){
		part[i] = mul(a[i] % MOD,b[i]) ;
	}
	for (int i = 0 ; i < n ; i++){
		ans += part[i] ;
		ans %= MOD ;
	}
	cout << ans  ;
	return 0 ;
}


#include<bits/stdc++.h>
using namespace std ;

typedef long long ll ;

#define Size(x)                x.size()
#define debug(x)               cerr << #x << " : " << x << endl
#define debug_vect(v)          for (int i = 0 ; i < Size(v) ; i++) cerr << i << " : " << v[i] << " ,"

const int MAXN = 2e5 ;
const int MOD = 998244353 ;

ll n ,ans ,a[MAXN] ,b[MAXN] ,part[MAXN] ;

bool cmpa (int a ,int b){
	return(a < b) ;
}
bool cmpb (int a ,int b){
	return(a > b) ;
}

int add(int a ,int b){
	int c = a + b ;
	if (c >= MOD){
		c -= MOD ;
	}
	if (c < 0){
		c += MOD ;
	}
	return c ;
}
int mul(int a ,int b){
	int c = 1LL * a * b % MOD ;
	return c ;
}

int main (){
	cin >> n ;
	for (int i = 0 ; i < n ; i++){
		cin >> a[i] ;
	}
	for (int i = 0 ; i < n ; i++){
		cin >> b[i] ;
	}
	for (int i = 1 ; i <= n ; i++){
		a[i - 1] = a[i - 1] * i * (n - i + 1) ;
	}
	sort(a ,a + n ,cmpa) ;
	sort(b ,b + n ,cmpb) ;
	for (int i = 0 ; i < n ; i++){
		part[i] = mul(a[i] ,b[i]) ;
	}
	for (int i = 0 ; i < n ; i++){
		cout << part[i] << " " ;
	}
	for (int i = 0 ; i < n ; i++){
		ans += part[i] ;
	}
	cout << ans ;
	return 0 ;
}


#include<bits/stdc++.h>
using namespace std ;

typedef long long ll ;

#define Size(x)                x.size()
#define debug(x)               cerr << #x << " : " << x << endl
#define debug_vect(v)          for (int i = 0 ; i < Size(v) ; i++) cerr << i << " : " << v[i] << " ,"

const int MAXN = 2e5 ;
const int MOD = 998244353 ;

ll n ,ans ,a[MAXN] ,b[MAXN] ,part[MAXN] ;

bool cmpa (int a ,int b){
	return(a < b) ;
}
bool cmpb (int a ,int b){
	return(a > b) ;
}

int add(int a ,int b){
	int c = a + b ;
	if (c >= MOD){
		c -= MOD ;
	}
	if (c < 0){
		c += MOD ;
	}
	return c ;
}
int mul(int a ,int b){
	int c = 1LL * a * b % MOD ;
	return c ;
}

int main (){
	cin >> n ;
	for (int i = 0 ; i < n ; i++){
		cin >> a[i] ;
	}
	for (int i = 0 ; i < n ; i++){
		cin >> b[i] ;
	}
	for (int i = 1 ; i <= n ; i++){
		a[i - 1] = a[i - 1] * i * (n - i + 1) ;
	}
	sort(a ,a + n ,cmpa) ;
	sort(b ,b + n ,cmpb) ;
	for (int i = 0 ; i < n ; i++){
		part[i] = mul(a[i] ,b[i]) ;
	}
	for (int i = 0 ; i < n ; i++){
		ans += part[i] ;
	}
	cout << ans % MOD ;
	return 0 ;
}


#include<bits/stdc++.h>
using namespace std ;

typedef long long ll ;

#define Size(x)                x.size()
#define debug(x)               cerr << #x << " : " << x << endl
#define debug_vect(v)          for (int i = 0 ; i < Size(v) ; i++) cerr << i << " : " << v[i] << " ,"

const int MAXN = 2e5 ;
const int MOD = 998244353 ;

ll n ,ans ,a[MAXN] ,b[MAXN] ,part[MAXN] ;

bool cmpa (int a ,int b){
	return(a < b) ;
}
bool cmpb (int a ,int b){
	return(a > b) ;
}

int add(int a ,int b){
	int c = a + b ;
	if (c >= MOD){
		c -= MOD ;
	}
	if (c < 0){
		c += MOD ;
	}
	return c ;
}
int mul(ll a ,ll b){
	int c = 1LL * a * b % MOD ;
	return c ;
}

int main (){
	cin >> n ;
	for (int i = 0 ; i < n ; i++){
		cin >> a[i] ;
	}
	for (int i = 0 ; i < n ; i++){
		cin >> b[i] ;
	}
	for (int i = 0 ; i < n ; i++){
		a[i] = 1LL * a[i] * (i + 1) * (n - i) ;
	}
	sort(a ,a + n ,cmpb) ;
	sort(b ,b + n) ;
	for (int i = 0 ; i < n ; i++){
		ans = (ans + (a[i] % MOD * 1LL * b[i]) % MOD )% MOD ;
	}
	cout << ans  ;
	return 0 ;
}


#include<bits/stdc++.h>
using namespace std ;

typedef long long ll ;

#define Size(x)                x.size()
#define debug(x)               cerr << #x << " : " << x << endl
#define debug_vect(v)          for (int i = 0 ; i < Size(v) ; i++) cerr << i << " : " << v[i] << " ,"

const int MAXN = 2e5 ;
const int MOD = 998244353 ;

ll n ,ans ,a[MAXN] ,b[MAXN] ,part[MAXN] ;

bool cmpa (int a ,int b){
	return(a < b) ;
}
bool cmpb (int a ,int b){
	return(a > b) ;
}

int add(int a ,int b){
	int c = a + b ;
	if (c >= MOD){
		c -= MOD ;
	}
	if (c < 0){
		c += MOD ;
	}
	return c ;
}
int mul(ll a ,ll b){
	int c = 1LL * a * b % MOD ;
	return c ;
}

int main (){
	cin >> n ;
	for (int i = 0 ; i < n ; i++){
		cin >> a[i] ;
	}
	for (int i = 0 ; i < n ; i++){
		cin >> b[i] ;
	}
	for (int i = 0 ; i < n ; i++){
		a[i] = 1LL * a[i] * (i + 1) * (n - i) ;
	}
	sort(a ,a + n ,cmpa) ;
	sort(b ,b + n ,cmpb) ;
	for (int i = 0 ; i < n ; i++){
		ans = (ans + (a[i] % MOD * 1LL * b[i]) % MOD )% MOD ;
	}
	cout << ans  ;
	return 0 ;
}


#include<bits/stdc++.h>
using namespace std ;

typedef long long ll ;

#define Size(x)                x.size()
#define debug(x)               cerr << #x << " : " << x << endl
#define debug_vect(v)          for (int i = 0 ; i < Size(v) ; i++) cerr << i << " : " << v[i] << " ,"

const int MAXN = 2e5 ;
const int MOD = 998244353 ;

ll n ,ans ,a[MAXN] ,b[MAXN] ,part[MAXN] ;

bool cmpa (int a ,int b){
	return(a < b) ;
}
bool cmpb (int a ,int b){
	return(a > b) ;
}

int add(int a ,int b){
	int c = a + b ;
	if (c >= MOD){
		c -= MOD ;
	}
	if (c < 0){
		c += MOD ;
	}
	return c ;
}
int mul(ll a ,ll b){
	int c = 1LL * a * b % MOD ;
	return c ;
}

int main (){
	cin >> n ;
	for (int i = 0 ; i < n ; i++){
		cin >> a[i] ;
	}
	for (int i = 0 ; i < n ; i++){
		cin >> b[i] ;
	}
	for (int i = 1 ; i <= n ; i++){
		a[i - 1] = 1LL * a[i - 1] * i * (n - i + 1) ;
	}
	sort(a ,a + n ,cmpa) ;
	sort(b ,b + n ,cmpb) ;
	for (int i = 0 ; i < n ; i++){
		part[i] = mul(a[i] ,b[i]) ;
	}
	for (int i = 0 ; i < n ; i++){
		ans += part[i] ;
	}
	cout << ans % MOD ;
	return 0 ;
}


#include<bits/stdc++.h>
using namespace std ;

typedef long long ll ;

#define Size(x)                x.size()
#define debug(x)               cerr << #x << " : " << x << endl
#define debug_vect(v)          for (int i = 0 ; i < Size(v) ; i++) cerr << i << " : " << v[i] << " ,"

const int MAXN = 2e5 ;
const int MOD = 998244353 ;

ll n ,ans ,a[MAXN] ,b[MAXN] ,part[MAXN] ;

bool cmpa (int a ,int b){
	return(a < b) ;
}
bool cmpb (int a ,int b){
	return(a > b) ;
}

int add(int a ,int b){
	int c = a + b ;
	if (c >= MOD){
		c -= MOD ;
	}
	if (c < 0){
		c += MOD ;
	}
	return c ;
}
int mul(int a ,int b){
	int c = 1LL * a * b % MOD ;
	return c ;
}

int main (){
	cin >> n ;
	for (int i = 0 ; i < n ; i++){
		cin >> a[i] ;
	}
	for (int i = 0 ; i < n ; i++){
		cin >> b[i] ;
	}
	for (int i = 1 ; i <= n ; i++){
		a[i - 1] = a[i - 1] * i * (n - i + 1) ;
	}
	sort(a ,a + n ,cmpa) ;
	sort(b ,b + n ,cmpb) ;
	for (int i = 0 ; i < n ; i++){
		part[i] = mul(a[i] ,b[i]) ;
	}
	for (int i = 0 ; i < n ; i++){
		ans = add(part[i] , ans) ;
	}
	cout << ans ;
	return 0 ;
}


#include<bits/stdc++.h>
using namespace std ;

typedef long long ll ;

#define Size(x)                x.size()
#define debug(x)               cerr << #x << " : " << x << endl
#define debug_vect(v)          for (int i = 0 ; i < Size(v) ; i++) cerr << i << " : " << v[i] << " ,"

const int MAXN = 2e5 ;
const int MOD = 998244353 ;

ll n ,ans ,a[MAXN] ,b[MAXN] ;

bool cmpa (int a ,int b){
	return(a < b) ;
}
bool cmpb (int a ,int b){
	return(a > b) ;
}

int add(int a ,int b){
	int c = a + b ;
	if (c >= MOD){
		c -= MOD ;
	}
	if (c < 0){
		c += MOD ;
	}
	return c ;
}
int mul(int a ,int b){
	int c = 1LL * a * b % MOD ;
	return c ;
}

int main (){
	cin >> n ;
	for (int i = 0 ; i < n ; i++){
		cin >> a[i] ;
	}
	for (int i = 0 ; i < n ; i++){
		cin >> b[i] ;
	}
	for (int i = 0 ; i < n ; i++){
		a[i] = 1ll * (i + 1) * (n - i) * a[i] ;
	}
	sort(a ,a + n ,cmpa) ;
	sort(b ,b + n ,cmpb) ;
	for (int i = 0 ; i < n ; i++){
		ans = (ans + (a[i] % MOD * 1ll * b[i]) % MOD) % MOD ;
	}
	cout << ans ;
	return 0 ;
}


#include<bits/stdc++.h>
using namespace std ;

typedef long long ll ;

#define Size(x)                x.size()
#define debug(x)               cerr << #x << " : " << x << endl
#define debug_vect(v)          for (int i = 0 ; i < Size(v) ; i++) cerr << i << " : " << v[i] << " ,"

const int MAXN = 2e5 ;
const int MOD = 998244353 ;

ll n ,ans ,a[MAXN] ,b[MAXN] ,part[MAXN] ;

bool cmpa (int a ,int b){
	return(a < b) ;
}
bool cmpb (int a ,int b){
	return(a > b) ;
}

ll add(ll a ,ll b){
	ll c = a + b ;
	if (c >= MOD){
		c -= MOD ;
	}
	if (c < 0){
		c += MOD ;
	}
	return c ;
}
ll mul(ll a ,ll b){
	ll c = 1LL * a * b % MOD ;
	return c ;
}

int main (){
	cin >> n ;
	for (int i = 0 ; i < n ; i++){
		cin >> a[i] ;
	}
	for (int i = 0 ; i < n ; i++){
		cin >> b[i] ;
	}
	for (int i = 1 ; i <= n ; i++){
		a[i - 1] = mul(mul(a[i - 1] , i) , (n - i + 1));
	}
	sort(a ,a + n ,cmpa) ;
	sort(b ,b + n ,cmpb) ;
	for (int i = 0 ; i < n ; i++){
		part[i] = mul(a[i] ,b[i]) ;
	}
	for (int i = 0 ; i < n ; i++){
		ans += part[i] ;
	}
	cout << ans % MOD ;
	return 0 ;
}


#include<bits/stdc++.h>
using namespace std ;

typedef long long ll ;

#define Size(x)                x.size()
#define debug(x)               cerr << #x << " : " << x << endl
#define debug_vect(v)          for (int i = 0 ; i < Size(v) ; i++) cerr << i << " : " << v[i] << " ,"

const int MAXN = 2e5 ;
const int MOD = 998244353 ;

ll n ,ans ,a[MAXN] ,b[MAXN] ,part[MAXN] ;

bool cmpa (int a ,int b){
	return(a < b) ;
}
bool cmpb (int a ,int b){
	return(a > b) ;
}

int add(int a ,int b){
	int c = a + b ;
	if (c >= MOD){
		c -= MOD ;
	}
	if (c < 0){
		c += MOD ;
	}
	return c ;
}
int mul(int a ,int b){
	int c = 1LL * a * b % MOD ;
	return c ;
}

int main (){
	cin >> n ;
	for (int i = 0 ; i < n ; i++){
		cin >> a[i] ;
	}
	for (int i = 0 ; i < n ; i++){
		cin >> b[i] ;
	}
	for (int i = 1 ; i <= n ; i++){
		a[i - 1] = a[i - 1] * i * (n - i + 1) ;
	}
	sort(a ,a + n ,cmpa) ;
	sort(b ,b + n ,cmpb) ;
	for (int i = 0 ; i < n ; i++){
		part[i] = mul(a[i] ,b[i]) ;
	}
	for (int i = 0 ; i < n ; i++){
		ans += part[i] ;
	}
	cout << ans ;
	return 0 ;
}


#include<bits/stdc++.h>
using namespace std ;

typedef long long ll ;

#define Size(x)                x.size()
#define debug(x)               cerr << #x << " : " << x << endl
#define debug_vect(v)          for (int i = 0 ; i < Size(v) ; i++) cerr << i << " : " << v[i] << " ,"

const int MAXN = 2e5 ;
const int MOD = 998244353 ;

ll n ,ans ;

bool cmpa (int a ,int b){
	return(a < b) ;
}
bool cmpb (int a ,int b){
	return(a > b) ;
}

int add(int a ,int b){
	int c = a + b ;
	if (c >= MOD){
		c -= MOD ;
	}
	if (c < 0){
		c += MOD ;
	}
	return c ;
}
int mul(ll a ,ll b){
	int c = 1LL * a * b % MOD ;
	return c ;
}

int main (){
	cin >> n ;
	vector <int> a(n) ,b(n) ;
	vector <ll> part(n) ;
	for (int i = 0 ; i < n ; i++){
		cin >> a[i] ;
	}
	for (int i = 0 ; i < n ; i++){
		cin >> b[i] ;
	}
	for (int i = 0 ; i < n ; i++){
		part[i] =  (i + 1) * 1ll * a[i] * (n - i) ;
	}
	sort(part.rbegin() ,part.rend()) ;
	sort(b.begin() ,b.end()) ;
	for (int i = 0 ; i < n ; i++){
		ans = (ans + (part[i] % MOD * 1ll * b[i]) % MOD )% MOD ;
	}
	cout << ans  ;
	return 0 ;
}


#include<bits/stdc++.h>
using namespace std ;

typedef long long ll ;

#define Size(x)                x.size()
#define debug(x)               cerr << #x << " : " << x << endl
#define debug_vect(v)          for (int i = 0 ; i < Size(v) ; i++) cerr << i << " : " << v[i] << " ,"

const int MAXN = 2e5 ;
const int MOD = 998244353 ;

ll n ,ans ,a[MAXN] ,b[MAXN] ,part[MAXN] ;

bool cmpa (int a ,int b){
	return(a < b) ;
}
bool cmpb (int a ,int b){
	return(a > b) ;
}

int add(int a ,int b){
	int c = a + b ;
	if (c >= MOD){
		c -= MOD ;
	}
	if (c < 0){
		c += MOD ;
	}
	return c ;
}
int mul(int a ,int b){
	int c = 1LL * a * b % MOD ;
	return c ;
}

int main (){
	cin >> n ;
	for (int i = 0 ; i < n ; i++){
		cin >> a[i] ;
	}
	for (int i = 0 ; i < n ; i++){
		cin >> b[i] ;
	}
	for (int i = 0 ; i < n ; i++){
		a[i] = 1ll * (i + 1) * (n - i) * a[i] ;
	}
	sort(a ,a + n ,cmpa) ;
	sort(b ,b + n ,cmpb) ;
	for (int i = 0 ; i < n ; i++){
		part[i] = mul(a[i] % MOD ,b[i]) ;
	}
	for (int i = 0 ; i < n ; i++){
		ans = add(ans ,part[i]) ;
	}
	cout << ans ;
	return 0 ;
}


#include<bits/stdc++.h>
using namespace std ;

typedef long long ll ;

#define Size(x)                x.size()
#define debug(x)               cerr << #x << " : " << x << endl
#define debug_vect(v)          for (int i = 0 ; i < Size(v) ; i++) cerr << i << " : " << v[i] << " ,"

const int MAXN = 2e5 ;
const int MOD = 998244353 ;

ll n ,ans ,a[MAXN] ,b[MAXN] ;

bool cmpa (int a ,int b){
	return(a < b) ;
}
bool cmpb (int a ,int b){
	return(a > b) ;
}

int add(int a ,int b){
	int c = a + b ;
	if (c >= MOD){
		c -= MOD ;
	}
	if (c < 0){
		c += MOD ;
	}
	return c ;
}
int mul(int a ,int b){
	int c = 1LL * a * b % MOD ;
	return c ;
}

int main (){
	cin >> n ;
	for (int i = 0 ; i < n ; i++){
		cin >> a[i] ;
	}
	for (int i = 0 ; i < n ; i++){
		cin >> b[i] ;
	}
	for (int i = 0 ; i < n ; i++){
		a[i] = 1ll * (i + 1) * (n - i) * a[i] ;
	}
	sort(a ,a + n ) ;
	sort(b ,b + n ) ;
	reverse(a , a + n) ;
	for (int i = 0 ; i < n ; i++){
		ans = (ans + (a[i] % MOD * 1ll * b[i]) % MOD) % MOD ;
	}
	cout << ans ;
	return 0 ;
}


#include<bits/stdc++.h>
using namespace std ;

typedef long long ll ;

#define Size(x)                x.size()
#define debug(x)               cerr << #x << " : " << x << endl
#define debug_vect(v)          for (int i = 0 ; i < Size(v) ; i++) cerr << i << " : " << v[i] << " ,"

const int MAXN = 2e5 ;
const int MOD = 998244353 ;

ll n ,ans ,a[MAXN] ,b[MAXN] ,part[MAXN] ;

bool cmpa (int a ,int b){
	return(a < b) ;
}
bool cmpb (int a ,int b){
	return(a > b) ;
}

int add(int a ,int b){
	int c = a + b ;
	if (c >= MOD){
		c -= MOD ;
	}
	if (c < 0){
		c += MOD ;
	}
	return c ;
}
int mul(int a ,int b){
	int c = 1LL * a * b % MOD ;
	return c ;
}

int main (){
	cin >> n ;
	for (int i = 0 ; i < n ; i++){
		cin >> a[i] ;
	}
	for (int i = 0 ; i < n ; i++){
		cin >> b[i] ;
	}
	for (int i = 0 ; i < n ; i++){
		a[i] = 1ll * (i + 1) * (n - i) * a[i] ;
	}
	sort(a ,a + n ,cmpa) ;
	sort(b ,b + n ,cmpb) ;
	for (int i = 0 ; i < n ; i++){
		part[i] = mul(a[i] ,b[i]) ;
	}
	for (int i = 0 ; i < n ; i++){
		ans = add(ans ,part[i] % MOD) ;
	}
	cout << ans ;
	return 0 ;
}


#include<bits/stdc++.h>
using namespace std ;

typedef long long ll ;

#define Size(x)                x.size()
#define debug(x)               cerr << #x << " : " << x << endl
#define debug_vect(v)          for (int i = 0 ; i < Size(v) ; i++) cerr << i << " : " << v[i] << " ,"

const int MAXN = 2e5 ;
const int MOD = 998244353 ;

ll n ,ans ;

bool cmpa (int a ,int b){
	return(a < b) ;
}
bool cmpb (int a ,int b){
	return(a > b) ;
}

int add(int a ,int b){
	int c = a + b ;
	if (c >= MOD){
		c -= MOD ;
	}
	if (c < 0){
		c += MOD ;
	}
	return c ;
}
int mul(ll a ,ll b){
	int c = 1LL * a * b % MOD ;
	return c ;
}

int main (){
	cin >> n ;
	vector <int> a(n) ,b(n) ;
	vector <pair<ll ,int>> part(n) ;
	for (int i = 0 ; i < n ; i++){
		cin >> a[i] ;
	}
	for (int i = 0 ; i < n ; i++){
		cin >> b[i] ;
	}
	for (int i = 0 ; i < n ; i++){
		part[i].first =  (i + 1) * 1ll * a[i] * (n - i) ;
		part[i].second = i ;
	}
	sort(part.begin() ,part.end()) ;
	sort(b.begin() ,b.end()) ;
	for (int i = 0 ; i < n ; i++){
		ans = (ans + (part[i].first % MOD * 1ll * b[i]) % MOD )% MOD ;
	}
	cout << ans  ;
	return 0 ;
}


#include<bits/stdc++.h>
using namespace std ;

typedef long long ll ;

#define Size(x)                x.size()
#define debug(x)               cerr << #x << " : " << x << endl
#define debug_vect(v)          for (int i = 0 ; i < Size(v) ; i++) cerr << i << " : " << v[i] << " ,"

const int MAXN = 2e5 ;
const int MOD = 998244353 ;

ll n ,ans ;

bool cmpa (int a ,int b){
	return(a < b) ;
}
bool cmpb (int a ,int b){
	return(a > b) ;
}

int add(int a ,int b){
	int c = a + b ;
	if (c >= MOD){
		c -= MOD ;
	}
	if (c < 0){
		c += MOD ;
	}
	return c ;
}
int mul(ll a ,ll b){
	int c = 1LL * a * b % MOD ;
	return c ;
}

int main (){
	cin >> n ;
	vector <int> a(n) ,b(n) ;
	vector <pair<ll ,int>> part(n) ;
	for (int i = 0 ; i < n ; i++){
		cin >> a[i] ;
	}
	for (int i = 0 ; i < n ; i++){
		cin >> b[i] ;
	}
	for (int i = 0 ; i < n ; i++){
		part[i].first =  (i + 1) * 1ll * a[i] * (n - i) ;
	}
	sort(part.rbegin() ,part.rend()) ;
	sort(b.begin() ,b.end()) ;
	for (int i = 0 ; i < n ; i++){
		ans = (ans + (part[i].first % MOD * 1ll * b[i]) % MOD )% MOD ;
	}
	cout << ans  ;
	return 0 ;
}


#include<bits/stdc++.h>
using namespace std ;

typedef long long ll ;

#define Size(x)                x.size()
#define debug(x)               cerr << #x << " : " << x << endl
#define debug_vect(v)          for (int i = 0 ; i < Size(v) ; i++) cerr << i << " : " << v[i] << " ,"

const int MAXN = 2e5 ;
const int MOD = 998244353 ;

ll n ,ans ;

bool cmpa (int a ,int b){
	return(a < b) ;
}
bool cmpb (int a ,int b){
	return(a > b) ;
}

int add(int a ,int b){
	int c = a + b ;
	if (c >= MOD){
		c -= MOD ;
	}
	if (c < 0){
		c += MOD ;
	}
	return c ;
}
int mul(ll a ,ll b){
	int c = 1LL * a * b % MOD ;
	return c ;
}

int main (){
	cin >> n ;
	vector <int> a(n) ,b(n) ;
	vector <pair<ll ,int>> part(n) ;
	for (int i = 0 ; i < n ; i++){
		cin >> a[i] ;
	}
	for (int i = 0 ; i < n ; i++){
		cin >> b[i] ;
	}
	for (int i = 0 ; i < n ; i++){
		part[i].first = 1ll * a[i] * (i + 1) * (n - i) ;
		part[i].second = i ;
	}
	sort(a.rbegin() ,a.rend()) ;
	sort(b.begin() ,b.end()) ;
	for (int i = 0 ; i < n ; i++){
		ans = (ans + (part[i].first % MOD * 1ll * b[i]) % MOD )% MOD ;
	}
	cout << ans  ;
	return 0 ;
}


#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define pb push_back
#define mp make_pair
typedef pair<int , int>  pii;
const long long mod=998244353;
int main()
{
	int n;
	cin>>n;

	ll a , b[n];
	vector<pair<long long ,int> > v;
	for(int i=0;i<n;i++)
	{

	cin>>a;
	a=a*(i+1)*1ll*(n-i);
	a%=mod;
	v.pb(mp(a, i));
	}
	for(int i=0;i<n;i++)
	cin>>b[i];

	sort(v.rbegin() , v.rend());
	sort(b,b+n);

	ll sum=0;
	for(int i =0 ;i<n;i++)
	{
	  sum = (sum + (v[i].first * 1ll * b[i]) % mod) % mod;

	}
	cout<<sum<<endl;
	return 0;
}


#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define pb push_back
#define mp make_pair
typedef pair<int , int>  pii;
const int mod=998244353;
int main()
{
	int n;
	cin>>n;

	ll a[n] , b[n];
	vector<pii> v;
	for(int i=0;i<n;i++)
	{

	cin>>a[i];
	v.pb(mp(a[i], i));
	}
	for(int i=0;i<n;i++)
	cin>>b[i];

	sort(v.begin() , v.end());
	sort(b,b+n ,greater<int>());
	ll temp[n];
	ll ans[n];

	for(int i=0;i<n;i++)
	{
		temp[v[i].second]=b[i];
	}
	for(int i=0;i<n;i++)
	{
	ans[i]=a[i]*temp[i];
	ans[i]%=mod;
	}
	ll sum=0;
	for(int i =0 ;i<n;i++)
	{
	  sum+=((i+1)*(n-i)*ans[i])%mod;
	  sum%=mod;
	}
	cout<<sum<<endl;
}


#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define pb push_back
#define mp make_pair
typedef pair<int , int>  pii;
const int mod=998244353;
int main()
{
	int n;
	cin>>n;

	ll a[n] , b[n];
	vector<pii> v;
	for(int i=0;i<n;i++)
	{

	cin>>a[i];
	a[i]=a[i]*(i+1)*(n-i);
	v.pb(mp(a[i], i));
	}
	for(int i=0;i<n;i++)
	cin>>b[i];

	sort(v.begin() , v.end());
	sort(b,b+n ,greater<int>());
/*	ll temp[n];
	ll ans[n];

   for(int i=0;i<n;i++)
	{
		temp[v[i].second]=b[i];
	}
	for(int i=0;i<n;i++)
	{
	ans[i]=a[i]*temp[i];
	ans[i]%=mod;
	}
	*/
	ll sum=0;
	for(int i =0 ;i<n;i++)
	{

	  sum+=(v[i].first*b[i])%mod;
	  sum%=mod;
	}
	cout<<sum<<endl;
	return 0;
}


#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define pb push_back
#define mp make_pair
typedef pair<int , int>  pii;
const int mod=998244353;
int main()
{
	int n;
	cin>>n;

	ll a[n] , b[n];
	vector<pii> v;
	for(int i=0;i<n;i++)
	{

	cin>>a[i];
	v.pb(mp(a[i], i));
	}
	for(int i=0;i<n;i++)
	cin>>b[i];

	sort(v.begin() , v.end());
	sort(b,b+n ,greater<int>());
	ll temp[n];
	ll ans[n];

	for(int i=0;i<n;i++)
	{
		temp[v[i].second]=b[i];
	}
	for(int i=0;i<n;i++)
	{
	ans[i]=a[i]*temp[i];
	ans[i]%=mod;
	}
	ll sum=0;
	for(int i =0 ;i<n;i++)
	{
	  sum+=(i+1)*(n-i)*ans[i];
	  sum%=mod;
	}
	cout<<sum<<endl;
}


#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define pb push_back
#define mp make_pair
typedef pair<int , int>  pii;
const long long mod=998244353;
int main()
{
	int n;
	cin>>n;

	ll a[n] , b[n];
	vector<pii> v;
	for(int i=0;i<n;i++)
	{

	cin>>a[i];
	a[i]=a[i]*(i+1)*1ll*(n-i);
	a[i]%=mod;
	v.pb(mp(a[i], i));
	}
	for(int i=0;i<n;i++)
	cin>>b[i];

	sort(v.begin() , v.end());
	sort(b,b+n ,greater<int>());

	ll sum=0;
	for(int i =0 ;i<n;i++)
	{
	  sum = (sum + (v[i].first * 1ll * b[i]) % mod) % mod;

	}
	cout<<sum<<endl;
	return 0;
}


#include <bits/stdc++.h>

#define pb push_back
#define Mp make_pair
#define F first
#define S second
#define all(x) x.begin(), x.end()
#define Sort(x) sort(all(x))
#define sz(x) x.size()
#define debug(x)  cerr << #x << " = " << x << endl
#define endl '\n'
#define sync ios::sync_with_stdio(0), cin.tie(0)
#define esp ' '
#define end(x) return cout << x , 0

using namespace std;

typedef long long ll;
typedef long double ld;
typedef pair<int, int> pii;
typedef vector<int> vi;
typedef pair<ll , ll> pll ;
typedef vector<ll> vll ;
typedef string str ;

const ll MOD = 1e9 + 7 ;
const ll MAXN = 2e5 + 30 ;
const ll MINN = 1e3 + 20 ;
const ll MOD2 = 998244353ll ;
const ll INF = 74592896151251 ;
const ld EPS = 1e-9 ;

ll gcd(ll a, ll b) { return (b ? gcd(b, a % b) : a); }
ll mod(ll n) { while(n < 0) n += MOD; return n % MOD; }
ll pow(ll a, ll b) { return (!b ? 1 : pow(a, b / 2) * pow(a, b / 2) * (b % 2 ? a : 1)) ;}

void print (pll p) {
    cout << p.F << ' ' << p.S  << endl ;
}

ll d (ll x1 ,ll y1 , ll x2 , ll y2) {
    return abs(x1 - x2) + abs(y1 - y2) ;
}
inline void add (ll x1 , ll y1 , ll x2 , ll y2) {

    while (x1 < x2) print({++x1 , y1}) ;
    while (x1 > x2) print({--x1 , y1}) ;
    while (y1 > y2) print({x1 , --y1}) ;
    while (y1 < y2) print({x1 , ++y1}) ;

}

int Main() {
   ll xa , ya , xb , yb , xc , yc , ans = INF , id_i = 0 , id_j = 0 ;
   cin >> xa >> ya >> xb >> yb >> xc >> yc ;
   for (int i = 0 ; i <= 1000 ; i ++){
       for (int j = 0 ; j <= 1000 ; j ++) {
           ll f = d(i , j , xa , ya) + d(i , j , xb , yb) +d (i , j , xc , yc) ;
           if (f < ans) {
               ans = f ;
               id_i = i ;
               id_j = j ;
           }
       }
   }
    cout << ++ans << endl ;
    cout << id_i << ' ' << id_j << endl ;
    add (id_i , id_j , xa , ya) ;
    add (id_i , id_j , xb , yb) ;
    add (id_i , id_j , xc , yc) ;

}

int main () {
    sync ;
    int q ;
    q = 1 ;
    while (q --)
        Main() ;
	return 0;
}


#include <bits/stdc++.h>
using namespace std;
typedef long long ll;

vector <pair<int, int> > vec;

int main(){
    ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);

    for (int i = 1; i <= 3; i++){
        int x, y;
        cin >> x >> y;
        vec.push_back({x, y});
    }
    sort(vec.begin(), vec.end());
    vector <pair<int, int> > vecc;
    for (int i = vec[0].first; i < vec[1].first; i++)
        vecc.push_back({i, vec[0].second});
    int dy = (vec[0].second <= vec[1].second ? 1 : -1);
    for (int i = vec[0].second; i != vec[1].second; i += dy){
        vecc.push_back({vec[1].first, i});
    }
    vecc.push_back(vec[1]);
    if (vec[2].second > max(vec[0].second, vec[1].second)){
        for (int i = max(vec[0].second, vec[1].second)+1; i <= vec[2].second; i++)
            vecc.push_back({vec[1].first, i});
    } else
    if (vec[2].second < min(vec[0].second, vec[1].second)){
        for (int i = min(vec[0].second, vec[1].second)-1; i >= vec[2].second; i--){
            vecc.push_back({vec[1].first, i});
        }
    }
    for (int i = vec[1].first+1; i <= vec[2].first; i++)
        vecc.push_back({i, vec[2].second});
    cout << vecc.size() << "\n";
    for (int i = 0; i < vecc.size(); i++)
        cout << vecc[i].first << ' ' << vecc[i].second << "\n";

}


#include <bits/stdc++.h>
using namespace std;
typedef long long ll;

vector <pair<int, int> > vec;

int main(){
    ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);

    for (int i = 1; i <= 3; i++){
        int x, y;
        cin >> x >> y;
        vec.push_back({x, y});
    }
    sort(vec.begin(), vec.end());
    vector <pair<int, int> > vecc;
    for (int i = vec[0].first; i < vec[1].first; i++)
        vecc.push_back({i, vec[0].second});
    int dy = (vec[0].second < vec[1].second ? 1 : -1);
    for (int i = vec[0].second; i <= vec[1].second; i += dy){
        vecc.push_back({vec[1].first, i});
    }
    if (vec[2].second > max(vec[0].second, vec[1].second)){
        for (int i = max(vec[0].second, vec[1].second)+1; i <= vec[2].second; i++)
            vecc.push_back({vec[1].first, i});
    } else
    if (vec[2].second < min(vec[0].second, vec[1].second)){
        for (int i = min(vec[0].second, vec[1].second)-1; i >= vec[2].second; i--){
            vecc.push_back({vec[1].first, i});
        }
    }
    for (int i = vec[1].first+1; i <= vec[2].first; i++)
        vecc.push_back({i, vec[2].second});
    cout << vecc.size() << "\n";
    for (int i = 0; i < vecc.size(); i++)
        cout << vecc[i].first << ' ' << vecc[i].second << "\n";

}


#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
// typedef __int128 ll;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
#define FR first
#define SE second
#define MP make_pair
#define PB push_back
#define vc vector
#define db double
#define all(x) (x).begin(),(x).end()
#define sz(x) ((int)(x).size())
#define bin(x) (1ll<<(x))
#define fo(i,l,r) for(int i=(l),I=(r);i<=I;i++)
#define fd(i,r,l) for(int i=(r),I=(l);i>=I;i--)
#define mem(x,val) memset(x,val,sizeof x)
#define Swap(a,b,n) for(int I=0;I<=n;I++) swap(a[I],b[I])
#define PC __builtin_popcountll
#ifdef DEBUG
	#define debug(A,args...) fprintf(stderr,A,##args)
#else
	#define debug(A,args...) printf("")
#endif
#define deb debug("line %d\n",__LINE__)
namespace mine
{
	ll qread()
	{
		ll ans=0,f=1;char c=getchar();
		while(c<'0' or c>'9') {if(c=='-')f=-1;c=getchar();}
		while('0'<=c and c<='9') ans=ans*10+c-'0',c=getchar();
		return ans*f;
	}
	void write(ll num){if(num<0) putchar('-'),num=-num;if(num>=10) write(num/10);putchar('0'+num%10);}
	void write1(ll num){write(num);putchar(' ');}
	void write2(ll num){write(num);putchar('\n');}
	template<typename T>inline bool chmax(T&a,const T&b){return a<b?a=b,1:0;}
	template<typename T>inline bool chmin(T&a,const T&b){return a>b?a=b,1:0;}
	ll gcd(ll x,ll y){return y?gcd(y,x%y):x;}
	bool IN(ll x,ll l,ll r){return l<=x and x<=r;}
	void GG(){puts("-1");exit(0);}

	const db eps=1e-8;
	const int INF=0x3f3f3f3f;
	const int MOD=1e9+7;
	int mm(const int x){return x>=MOD?x-MOD:x;}
	template<typename T> void add(T &x,const int &y){x=(x+y>=MOD?x+y-MOD:x+y);}
	ll qpower(ll x,ll e,int mod=MOD){ll ans=1;while(e){if(e&1)ans=ans*x%mod;x=x*x%mod;e>>=1;}return ans;}
	ll invm(ll x){return qpower(x,MOD-2);}
	const int MM=1e6+10;
	ll fac[MM],facinv[MM],Inv[MM];ll Comb(int n,int m){return n<0 or n<m?0:fac[n]*facinv[m]%MOD*facinv[n-m]%MOD;}
	void PRE()
	{
		fac[0]=1;fo(i,1,MM-1) fac[i]=fac[i-1]*i%MOD;
		facinv[MM-1]=invm(fac[MM-1]);fd(i,MM-1,1) facinv[i-1]=facinv[i]*i%MOD;
		Inv[1]=1;fo(i,2,MM-1) Inv[i]=(MOD-MOD/i)*Inv[MOD%i]%MOD;
	}
	const int N=1e6+10;
	//------------------FIXED------------------
	set<pii> ans;
	void main()
	{
		pii a[3];fo(i,0,2) a[i].FR=qread(),a[i].SE=qread();sort(a,a+3);
		while(a[0].FR<a[1].FR) ans.insert(a[0]),a[0].FR++;
		while(a[2].FR>a[1].FR) ans.insert(a[2]),a[2].FR--;
		fo(id,0,1)
		{
			while(a[id].SE<a[2].SE) ans.insert(a[id]),a[id].SE++;
			while(a[id].SE>a[2].SE) ans.insert(a[id]),a[id].SE--;
		}
		ans.insert(a[2]);
		write2(sz(ans));for(auto in:ans) write1(in.FR),write2(in.SE);
	}
};//变量重名！
signed main()
{
	#ifdef DEBUG
	//freopen("a.in","r",stdin);
	//freopen("z.txt","r",stdin);
	//freopen("a.out","w",stdout);
	#endif
	srand(time(0));
	mine::PRE();
	mine::main();
	debug("\n------------------------------------------\nTime: %.2lf s\n",1.0*clock()/CLOCKS_PER_SEC);
}


#include <bits/stdc++.h>
#define mp make_pair
#define X first
#define Y second
#define pii pair<ll,ll>
#define x1 dlfjl
#define x2 dkfj
#define x3 dflgkg
#define y1 dskgj
#define y2 dskfj
#define y3 dfhgdh
#define SQ 320
#define PI 3.14159265359
#define MOD 1000000007
typedef long long ll;
using namespace std;
ll n,m,k,x,  y, z, l, r, i, j, p[335], q;
ll a[1005][1005], b[300500];
vector<pii> ans, f;
void go(ll x1, ll y1, ll x2, ll y2, ll val) {
    if (val == 0) {
        for (int i = min(x1, x2); i <= max(x1, x2); i++)
            a[i][y1] = 1;
        for (int i = min(y1, y2); i <= max(y1, y2); i++)
            a[x2][i] = 1;
        } else if (val == 1) {
            for (int i = min(x1, x2); i <= max(x1, x2); i++)
            a[i][y2] = 1;
        for (int i = min(y1, y2); i <= max(y1, y2); i++)
            a[x1][i] = 1;
        }
}
int main() {
    cerr << "mesyura hui" << endl;
    //freopen("input.txt","r",stdin);
    ll xa, xb, xc, ya, yb, yc;
    cin >> xa >> ya >> xb >> yb >> xc >> yc;
    for (int i = 0; i < 3; i++)
        for (int j = 0; j < 3; j++)
    for (int k = 0; k < 3; k++) {
        ll val = (i==2) + (j==2) + (k==2);
        if (val > 1)
            continue;
        for (int l = 0; l <= 1000; l++)
            for (int r = 0; r <= 1000; r++)
                a[l][r] = 0;
        go(xa, ya, xb, yb, i);
        go(xa, ya, xc, yc, j);
        go(xc, yc, xb, yb, k);
        f.clear();
        for (int l = 0; l <= 1000; l++)
            for (int r = 0; r <= 1000; r++)
        if (a[l][r]) {
            f.push_back(mp(l,r));
        }
        if (ans.empty() || ans.size() > f.size()) {
            ans.clear();
            for (int j = 0; j < f.size(); j++)
                ans.push_back(f[j]);
        }
    }
    cout << ans.size() << endl;
    for (int i = 0; i < ans.size(); i++)
        cout << ans[i].X << " " << ans[i].Y << endl;
    return 0;
}


#include <bits/stdc++.h>
#define mp make_pair
#define X first
#define Y second
#define pii pair<ll,ll>
#define x1 dlfjl
#define x2 dkfj
#define x3 dflgkg
#define y1 dskgj
#define y2 dskfj
#define y3 dfhgdh
#define SQ 320
#define PI 3.14159265359
#define MOD 1000000007
typedef long long ll;
using namespace std;
ll n,m,k,x,  y, z, l, r, i, j, p[335], q;
ll a[1005][1005], b[300500];
vector<pii> ans, f;
void go(ll x1, ll y1, ll x2, ll y2, ll val) {
    if (val == 0) {
        for (int i = min(x1, x2); i <= max(x1, x2); i++)
            a[i][y1] = 1;
        for (int i = min(y1, y2); i <= max(y1, y2); i++)
            a[x2][i] = 1;
        } else if (val == 1) {
            for (int i = min(x1, x2); i <= max(x1, x2); i++)
            a[i][y2] = 1;
        for (int i = min(y1, y2); i <= max(y1, y2); i++)
            a[x1][i] = 1;
        }
}
int main() {
    //freopen("input.txt","r",stdin);
    ll xa, xb, xc, ya, yb, yc;
    cin >> xa >> ya >> xb >> yb >> xc >> yc;
    for (int i = 0; i < 3; i++)
        for (int j = 0; j < 3; j++)
    for (int k = 0; k < 3; k++) {
        ll val = (i==2) + (j==2) + (k==2);
        if (val > 1)
            continue;
        for (int l = 0; l <= 1000; l++)
            for (int r = 0; r <= 1000; r++)
                a[l][r] = 0;
        go(xa, ya, xb, yb, i);
        go(xa, ya, xc, yc, j);
        go(xc, yc, xb, yb, k);
        f.clear();
        for (int l = 0; l <= 1000; l++)
            for (int r = 0; r <= 1000; r++)
        if (a[l][r]) {
            f.push_back(mp(l,r));
        }
        if (ans.empty() || ans.size() > f.size()) {
            ans.clear();
            for (int j = 0; j < f.size(); j++)
                ans.push_back(f[j]);
        }
    }
    cout << ans.size() << endl;
    for (int i = 0; i < ans.size(); i++)
        cout << ans[i].X << " " << ans[i].Y << endl;
    return 0;
}


#include <bits/stdc++.h>
#define mp make_pair
#define X first
#define Y second
#define pii pair<ll,ll>
#define x1 dlfjl
#define x2 dkfj
#define x3 dflgkg
#define y1 dskgj
#define y2 dskfj
#define y3 dfhgdh
#define SQ 320
#define PI 3.14159265359
#define MOD 1000000007
typedef long long ll;
using namespace std;
ll n,m,k,x,  y, z, l, r, i, j, p[335], q;
ll a[1005][1005], b[300500];
vector<pii> ans, f;
void go(ll x1, ll y1, ll x2, ll y2, ll val) {
    if (val == 0) {
        for (int i = min(x1, x2); i <= max(x1, x2); i++)
            a[i][y1] = 1;
        for (int i = min(y1, y2); i <= max(y1, y2); i++)
            a[x2][i] = 1;
        } else if (val == 1) {
            for (int i = min(x1, x2); i <= max(x1, x2); i++)
            a[i][y2] = 1;
        for (int i = min(y1, y2); i <= max(y1, y2); i++)
            a[x1][i] = 1;
        }
}
int main() {
    //freopen("input.txt","r",stdin);
    for (int i = 0; i < 1000000; i++)
        cerr << "mesyura hui" << endl;
    ll xa, xb, xc, ya, yb, yc;
    cin >> xa >> ya >> xb >> yb >> xc >> yc;
    for (int i = 0; i < 3; i++)
        for (int j = 0; j < 3; j++)
    for (int k = 0; k < 3; k++) {
        ll val = (i==2) + (j==2) + (k==2);
        if (val > 1)
            continue;
        for (int l = 0; l <= 1000; l++)
            for (int r = 0; r <= 1000; r++)
                a[l][r] = 0;
        go(xa, ya, xb, yb, i);
        go(xa, ya, xc, yc, j);
        go(xc, yc, xb, yb, k);
        f.clear();
        for (int l = 0; l <= 1000; l++)
            for (int r = 0; r <= 1000; r++)
        if (a[l][r]) {
            f.push_back(mp(l,r));
        }
        if (ans.empty() || ans.size() > f.size()) {
            ans.clear();
            for (int j = 0; j < f.size(); j++)
                ans.push_back(f[j]);
        }
    }
    cout << ans.size() << endl;
    for (int i = 0; i < ans.size(); i++)
        cout << ans[i].X << " " << ans[i].Y << endl;
    return 0;
}


#pragma GCC optimize("O3")
//#include<bits/stdc++.h>
#include <iostream>
#include <set>
#include <vector>
#include <cmath>
#include <algorithm>
#include <map>
#include <ctime>
#include <cassert>

using namespace std;

void doRoutine() {
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
    srand(322179);
#ifdef LOCAL
    freopen("C:\\Users\\Dima\\Documents\\Projects\\clion_main\\input.txt", "rt", stdin);
    freopen("C:\\Users\\Dima\\Documents\\Projects\\clion_main\\output.txt", "wt", stdout);
#endif
}

#define DBG(VAR) cerr << #VAR << ": " << VAR << endl

#define all(x) x.begin(), x.end()
#define vb vector<bool>
#define vi vector<int>
#define vvi vector<vi>
#define pii pair<int, int>
#define fi first
#define se second
#define pb push_back
#define vc vector
#define $ make_pair
#define mp make_pair

#ifndef LOCAL
#define cerr if(0) cerr
#define DBG(...) (true)
#endif

#define D double
#define int int64_t

template <typename T1, typename T2>
ostream & operator << (ostream & out, pair <T1, T2> p) {
    //out << "{" << p.fi << ", " << p.se << "}";
    out << p.fi << " " << p.se;
    return out;
}

template <typename T1, typename T2>
istream & operator >> (istream & in, pair <T1, T2> & p) {
    in >> p.fi >> p.se;
    return in;
}

template <typename T>
ostream & operator << (ostream & out, vector <T> arr) {
    for (int i = 0; i < arr.size(); ++i)
        out << arr[i] << " ";
    out << endl;
    return out;
}

template <typename T>
istream & operator >> (istream & in, vector <T> & arr) {
    for (int i = 0; i < arr.size(); ++i)
        in >> arr[i];
    return in;
}

template <typename T>
ostream & operator << (ostream & out, multiset <T> a) {
    out << "{";
    for (auto x : a) {
        out << x << " ";
    }
    out << "}";
    return out;
}

//const int MAX_MEM = 2e8;
//char mem[MAX_MEM];
//int mpos = 0;
//
//inline void* operator new(size_t n) {
//    char *res = mem + mpos;
//    mpos += n;
//    return (void*) res;
//}
//
//inline void operator delete(void*) {}

// ----------------------------- CODE NOW ------------------------

signed main() {
    doRoutine();

    vector <pii> arr(3);
    cin >> arr;
    sort(arr.begin(), arr.end());
    set <pii> ans;
    for (int i = arr[0].fi; i <= arr[1].fi; ++i) {
        ans.insert(mp(i, arr[0].se));
    }
    for (int i = min(arr[0].se, arr[1].se); i <= max(arr[0].se, arr[1].se); ++i) {
        ans.insert(mp(arr[i].fi, i));
    }
    for (int i = min(arr[1].se, arr[2].se); i <= max(arr[1].se, arr[2].se); ++i) {
        ans.insert(mp(arr[1].fi, i));
    }
    for (int i = arr[1].fi; i <= arr[2].fi; ++i) {
        ans.insert(mp(i, arr[2].se));
    }
    cout << ans.size() << endl;
    for (auto x : ans) {
        cout << x << endl;
    }
    return 0;
}


#pragma GCC optimize("O3")
//#include<bits/stdc++.h>
#include <iostream>
#include <set>
#include <vector>
#include <cmath>
#include <algorithm>
#include <map>
#include <ctime>
#include <cassert>

using namespace std;

void doRoutine() {
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
    srand(322179);
#ifdef LOCAL
    freopen("C:\\Users\\Dima\\Documents\\Projects\\clion_main\\input.txt", "rt", stdin);
    freopen("C:\\Users\\Dima\\Documents\\Projects\\clion_main\\output.txt", "wt", stdout);
#endif
}

#define DBG(VAR) cerr << #VAR << ": " << VAR << endl

#define all(x) x.begin(), x.end()
#define vb vector<bool>
#define vi vector<int>
#define vvi vector<vi>
#define pii pair<int, int>
#define fi first
#define se second
#define pb push_back
#define vc vector
#define $ make_pair
#define mp make_pair

#ifndef LOCAL
#define cerr if(0) cerr
#define DBG(...) (true)
#endif

#define D double
#define int int64_t

template <typename T1, typename T2>
ostream & operator << (ostream & out, pair <T1, T2> p) {
    //out << "{" << p.fi << ", " << p.se << "}";
    out << p.fi << " " << p.se;
    return out;
}

template <typename T1, typename T2>
istream & operator >> (istream & in, pair <T1, T2> & p) {
    in >> p.fi >> p.se;
    return in;
}

template <typename T>
ostream & operator << (ostream & out, vector <T> arr) {
    for (int i = 0; i < arr.size(); ++i)
        out << arr[i] << " ";
    out << endl;
    return out;
}

template <typename T>
istream & operator >> (istream & in, vector <T> & arr) {
    for (int i = 0; i < arr.size(); ++i)
        in >> arr[i];
    return in;
}

template <typename T>
ostream & operator << (ostream & out, multiset <T> a) {
    out << "{";
    for (auto x : a) {
        out << x << " ";
    }
    out << "}";
    return out;
}

//const int MAX_MEM = 2e8;
//char mem[MAX_MEM];
//int mpos = 0;
//
//inline void* operator new(size_t n) {
//    char *res = mem + mpos;
//    mpos += n;
//    return (void*) res;
//}
//
//inline void operator delete(void*) {}

// ----------------------------- CODE NOW ------------------------

signed main() {
    doRoutine();

    vector <pii> arr(3);
    cin >> arr;
    sort(arr.begin(), arr.end());
    set <pii> ans;
    for (int i = arr[0].fi; i <= arr[1].fi; ++i) {
        ans.insert(mp(i, arr[0].se));
    }
    for (int i = min(arr[0].se, arr[1].se); i <= max(arr[0].se, arr[1].se); ++i) {
        ans.insert(mp(arr[1].fi, i));
    }
    for (int i = min(arr[1].se, arr[2].se); i <= max(arr[1].se, arr[2].se); ++i) {
        ans.insert(mp(arr[1].fi, i));
    }
    for (int i = arr[1].fi; i <= arr[2].fi; ++i) {
        ans.insert(mp(i, arr[2].se));
    }
    cout << ans.size() << endl;
    for (auto x : ans) {
        cout << x << endl;
    }
    return 0;
}


//tavakol bar khoda
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
const int MAXN = (int)1e6 + 1;
const int MOD = (int)1e9 + 7;
const int infint = (int)1e8 + 3;
const ll inf = (ll)1e18;
ll x[3], y[3];
set< pair<int, int> > S;
void add(int A, int B, int C, int D)
{
	S.insert({A, B});
	while(A < C)
	{
		A++;
		S.insert({A, B});
	}
	while(A > C)
	{
		A--;
		S.insert({A, B});
	}
	while(B < D)
	{
		B++;
		S.insert({A, B});
	}
	while(B > D)
	{
		B--;
		S.insert({A, B});
	}
}
int main()
{
	ios::sync_with_stdio(false);
	cin.tie(0); cout.tie(0);
	for (int i = 0; i < 3; i++)
		cin >> x[i] >> y[i];

	ll ans = infint, X = infint, Y = infint;
	for (int i = 0; i <= 1000; i++)
		for (int j = 0; j <= 1000; j++)
		{
			ll cur = 0;
			for (int t = 0; t < 3; t++)
				cur += abs(i - x[t]) + abs(j - y[t]);
			cur++;
			if(cur < ans)
				ans = cur, X = i, Y = j;
		}
	cout << ans << "\n";
	for (int i = 0; i < 3; i++)
		add(X, Y, x[i], y[i]);
	for (auto u : S)
		cout << u.first << " " << u.second << "\n";
}


//tavakol bar khoda
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
const int MAXN = (int)1e6 + 1;
const int MOD = (int)1e9 + 7;
const int infint = (int)1e8 + 3;
const ll inf = (ll)1e18;
ll x[3], y[3];
set< pair<int, int> > S;
void add(int A, int B, int C, int D)
{
	S.insert({A, B});
	while(A < C)
	{
		A++;
		S.insert({A, B});
	}
	while(A > C)
	{
		A--;
		S.insert({A, B});
	}
	while(B < D)
	{
		B++;
		S.insert({A, B});
	}
	while(B > D)
	{
		B--;
		S.insert({B, D});
	}
}
int main()
{
	ios::sync_with_stdio(false);
	cin.tie(0); cout.tie(0);
	for (int i = 0; i < 3; i++)
		cin >> x[i] >> y[i];

	ll ans = infint, X = infint, Y = infint;
	for (int i = 0; i <= 1000; i++)
		for (int j = 0; j <= 1000; j++)
		{
			ll cur = 0;
			for (int t = 0; t < 3; t++)
				cur += abs(i - x[t]) + abs(j - y[t]);
			cur++;
			if(cur < ans)
				ans = cur, X = i, Y = j;
		}
	cout << ans << "\n";
	for (int i = 0; i < 3; i++)
		add(X, Y, x[i], y[i]);

	for (auto u : S)
		cout << u.first << " " << u.second << "\n";
}


#include <iostream>
#include <algorithm>
#include <string>
#include <sstream>
#include <vector>
#include <set>
#include <cmath>
#include <unordered_map>
#include <queue>
#include <map>
#include <functional>
#include <stack>
#include <cmath>
#include <cstring>
#include <random>
#include <chrono>
#include <memory>
#include <cassert>
#include <numeric>
#include <iomanip>
#include <array>
#define int long long
#define pic pair<int, char>
#define x first
#define y second
#define ll long long
#define pii pair<long long, long long>
#define endl "\n"
#define all(a) (a).begin(), (a).end()
#pragma GCC optimize ("O3")
#define PI 3.14159265
#define pdd pair<double, double>
#define rect pair<pii, pii>

using namespace std;

const int N = 5e5 + 14;
const int inf = (int)1e18 + 10;
const int mod = 1e9 + 7;
const double eps = 1e-6;

mt19937 rnd(chrono::high_resolution_clock::now().time_since_epoch().count());

using namespace std;

int dist(pii p1, pii p2)
{
	return abs(p1.x - p2.x) + abs(p1.y - p2.y);
}

pii a[3];
set<pii> st;

void move(pii from, pii to)
{
	st.insert(from);

	while (from.x < to.x)
	{
		++from.x;
		st.insert(from);
	}

	while (from.x > to.x)
	{
		--from.x;
		st.insert(from);
	}

	while (from.y < to.y)
	{
		++from.y;
		st.insert(from);
	}

	while (from.y > to.y)
	{
		--from.y;
		st.insert(from);
	}
}

int32_t main()
{
	ios_base::sync_with_stdio(false);
	cin.tie(0); cout.tie(0);
	cout.precision(20);

	for (int i = 0; i < 3; ++i)
		cin >> a[i].x >> a[i].y;

	int ans = inf;
	pii mnp;

	for(int i = 0; i <= 1000; ++i)
		for (int j = 0; j <= 1000; ++j)
		{
			int val = 0;

			for (int k = 0; k < 3; ++k)
				val += dist({ i, j }, a[k]);

			++val;

			if (ans > val)
			{
				ans = val;
				mnp = { i, j };
			}
		}

	for (int i = 0; i < 3; ++i)
		move(mnp, a[i]);

	cout << ans << endl;

	for (auto p : st)
		cout << p.x << " " << p.y << endl;
}


#include <bits/stdc++.h>

#define LL long long
#define PLL pair<LL,LL>

using namespace std;

int main(){
	ios_base::sync_with_stdio(false);
	vector<PLL> p(3);
	vector<LL> y(3);
	for (LL i = 0; i < 3; i++){
		cin >> p[i].first >> p[i].second;
		y[i] = p[i].second;
	}
	sort(p.begin(),p.end());
	sort(y.begin(),y.end());
	set<PLL> res;
	for (LL i = y[0]; i <= y[2]; i++)
		res.insert({p[1].first,i});
	for (LL i = 0; i < 3; i++){
		for (LL j = min(p[i].first,p[1].first); j <= max(p[i].first,p[1].first); j++)
			res.insert({j,p[i].second});
	}
	cout << res.size() << "\n";
	for (auto &[r,c] : res)
		cout << r << " " << c << "\n";
}


#include <bits/stdc++.h>
using namespace std;

typedef long long ll;
typedef long double ld;
typedef double db;
typedef string str;

typedef pair<int,int> pi;
typedef pair<ll,ll> pl;
typedef pair<db,db> pd;

typedef vector<int> vi;
typedef vector<bool> vb;
typedef vector<ll> vl;
typedef vector<db> vd;
typedef vector<str> vs;
typedef vector<pi> vpi;
typedef vector<pl> vpl;
typedef vector<pd> vpd;
template<class T> using V = vector<T>;
template<class T, size_t SZ> using AR = array<T,SZ>;

#define mp make_pair
#define f first
#define s second
#define sz(x) (int)(x).size()
#define all(x) begin(x), end(x)
#define rall(x) (x).rbegin(), (x).rend()
#define sor(x) sort(all(x))
#define rsz resize
#define ins insert
#define ft front()
#define bk back()
#define pf push_front
#define pb push_back
#define eb emplace_back
#define lb lower_bound
#define ub upper_bound

#define FOR(i,a,b) for (int i = (a); i < (b); ++i)
#define F0R(i,a) FOR(i,0,a)
#define For(i,a) FOR(i,0,a)
#define ROF(i,a,b) for (int i = (b)-1; i >= (a); --i)
#define R0F(i,a) ROF(i,0,a)
#define Rof(i,a) ROF(i,0,a);
#define trav(a,x) for (auto& a: x)

template<class T> bool ckmin(T& a, const T& b) {
    return b < a ? a = b, 1 : 0; }
template<class T> bool ckmax(T& a, const T& b) {
    return a < b ? a = b, 1 : 0; }
constexpr int pct(int x) { return __builtin_popcount(x); }
constexpr int bits(int x) { return 31-__builtin_clz(x); } // floor(log2(x))
ll cdiv(ll a, ll b) { return a/b+((a^b)>0&&a%b); } // divide a by b rounded up
ll fdiv(ll a, ll b) { return a/b-((a^b)<0&&a%b); } // divide a by b rounded down
ll half(ll x) { return fdiv(x,2); }

template<class T, class U> T fstTrue(T lo, T hi, U f) {
    // note: if (lo+hi)/2 is used instead of half(lo+hi) then this will loop infinitely when lo=hi
    hi ++; assert(lo <= hi); // assuming f is increasing
    while (lo < hi) { // find first index such that f is true
        T mid = half(lo+hi);
        f(mid) ? hi = mid : lo = mid+1;
    }
    return lo;
}
template<class T, class U> T lstTrue(T lo, T hi, U f) {
    lo --; assert(lo <= hi); // assuming f is decreasing
    while (lo < hi) { // find first index such that f is true
        T mid = half(lo+hi+1);
        f(mid) ? lo = mid : hi = mid-1;
    }
    return lo;
}
template<class T> void remDup(vector<T>& v) {
    sort(all(v)); v.erase(unique(all(v)),end(v)); }

// INPUT
template<class A> void re(complex<A>& c);
template<class A, class B> void re(pair<A,B>& p);
template<class A> void re(vector<A>& v);
template<class A, size_t SZ> void re(array<A,SZ>& a);

template<class T> void re(T& x) { cin >> x; }
void re(db& d) { str t; re(t); d = stod(t); }
void re(ld& d) { str t; re(t); d = stold(t); }
template<class H, class... T> void re(H& h, T&... t) { re(h); re(t...); }

template<class A> void re(complex<A>& c) { A a,b; re(a,b); c = {a,b}; }
template<class A, class B> void re(pair<A,B>& p) { re(p.f,p.s); }
template<class A> void re(vector<A>& x) { trav(a,x) re(a); }
template<class A, size_t SZ> void re(array<A,SZ>& x) { trav(a,x) re(a); }

// TO_STRING
#define ts to_string
str ts(char c) { return str(1,c); }
str ts(const char* s) { return (str)s; }
str ts(str s) { return s; }
str ts(bool b) {
#ifdef LOCAL
    return b ? "true" : "false";
#else
    return ts((int)b);
#endif
}
template<class A> str ts(complex<A> c) {
    stringstream ss; ss << c; return ss.str(); }
str ts(vector<bool> v) {
    str res = "{"; F0R(i,sz(v)) res += char('0'+v[i]);
    res += "}"; return res; }
template<size_t SZ> str ts(bitset<SZ> b) {
    str res = ""; F0R(i,SZ) res += char('0'+b[i]);
    return res; }
template<class A, class B> str ts(pair<A,B> p);
template<class T> str ts(T v) { // containers with begin(), end()
#ifdef LOCAL
    bool fst = 1; str res = "{";
		for (const auto& x: v) {
			if (!fst) res += ", ";
			fst = 0; res += ts(x);
		}
		res += "}"; return res;
#else
    bool fst = 1; str res = "";
    for (const auto& x: v) {
        if (!fst) res += " ";
        fst = 0; res += ts(x);
    }
    return res;

#endif
}
template<class A, class B> str ts(pair<A,B> p) {
#ifdef LOCAL
    return "("+ts(p.f)+", "+ts(p.s)+")";
#else
    return ts(p.f)+" "+ts(p.s);
#endif
}

// OUTPUT
template<class A> void pr(A x) { cout << ts(x); }
template<class H, class... T> void pr(const H& h, const T&... t) {
    pr(h); pr(t...); }
void ps() { pr("\n"); } // print w/ spaces
template<class H, class... T> void ps(const H& h, const T&... t) {
    pr(h); if (sizeof...(t)) pr(" "); ps(t...); }

// DEBUG
void DBG() { cerr << "]" << endl; }
template<class H, class... T> void DBG(H h, T... t) {
    cerr << ts(h); if (sizeof...(t)) cerr << ", ";
    DBG(t...); }
#ifdef LOCAL // compile with -DLOCAL, chk -> fake assert
#define dbg(...) cerr << "Line(" << __LINE__ << ") -> [" << #__VA_ARGS__ << "]: [", DBG(__VA_ARGS__)
	#define chk(...) if (!(__VA_ARGS__)) cerr << "Line(" << __LINE__ << ") -> function(" \
		 << __FUNCTION__  << ") -> CHK FAILED: (" << #__VA_ARGS__ << ")" << "\n", exit(0);
#else
#define dbg(...) 0
#define chk(...) 0
#endif

int gcd(int a, int b) {if (b == 0)return a;return gcd(b, a % b);}

// FILE I/O
void setIn(str s) { freopen(s.c_str(),"r",stdin); }
void setOut(str s) { freopen(s.c_str(),"w",stdout); }
void unsyncIO() { cin.tie(0)->sync_with_stdio(0); }
void setIO(str s = "") {
    unsyncIO();
    // cin.exceptions(cin.failbit);
    // throws exception when do smth illegal
    // ex. try to read letter into int
    if (sz(s)) { setIn(s+".in"), setOut(s+".out"); } // for USACO
}

const int M = 1e9+7; // 998244353;
const int MX = 2e5+5;
const ll INF = 1e18;
const ld PI = acos((ld)-1);
const int xd[4] = {1,0,-1,0}, yd[4] = {0,1,0,-1};
mt19937 rng((uint32_t)chrono::steady_clock::now().time_since_epoch().count());

pi pt[3];
set<pi> tmp;
int main() {
//	setIO();
    For(i,3){
        int x,y;re(x,y);
        pt[i]=mp(x,y);
    }
    sort(pt,pt+3);
    int a=pt[0].f,b=pt[0].s,c=pt[1].f,d=pt[1].s,e=pt[2].f,f=pt[2].s;
    int j1x=c;
    int j1y=b;
    int j2x=e;
    int j2y=f;
    if(f>max(b,d))j2y=max(b,d);
    if(f<min(b,d))j2y=min(b,d);
    for(int i=j1x;i>=a;i--){
        tmp.insert(mp(i,j1y));
    }
    if(b>d){
        for(int i=b;i>=d;i--){
            tmp.insert(mp(j1x,i));
        }
    }
    else{
        for(int i=b;i<=d;i++){
            tmp.insert(mp(j1x,i));
        }
    }
    for(int i=c;i<=e;i++){
        tmp.insert(mp(i,j2y));
    }
    if(f>j2y){
        for(int i=j2y;i<=f;i++){
            tmp.insert(mp(j2x,i));
        }
    }
    else if(f<j2y){
        for(int i=j2y;i>=f;i--){
            tmp.insert(mp(j2x,i));
        }
    }
    ps(tmp.size());
    trav(x,tmp)ps(x);

    // you should actually read the stuff at the bottom
}

/* stuff you should look for
	* int overflow, array bounds
	* special cases (n=1?)
	* do smth instead of nothing and stay organized
	* WRITE STUFF DOWN
	* DON'T GET STUCK ON ONE APPROACH
*/


#pragma comment(linker, "/STACK:60777216")

#include <cassert>
#include<iostream>
#include<algorithm>
#include<cstdio>
#include<complex>
#include<vector>
#include<set>
#include<map>
#include<cmath>
#include<queue>
#include<string>
#include<cstdlib>
#include<memory.h>
#include<ctime>
#include<bitset>
#include<fstream>
#include<queue>
#include<stack>
#include<unordered_map>
#include<unordered_set>

using namespace std;

typedef long double ld;

typedef long long ll;
typedef pair<int,int>	pii;
typedef pair<ld,ld>	pdd;
typedef vector<int> vi;
typedef vector<ld> vd;
typedef pair<ll,ll> pl;

#define FOR(i,a,b)		for(int i=(a);i<(b);i++)
#define REP(i,n)		FOR(i,0,n)
#define SORT(v)			sort((v).begin(),(v).end())
#define UN(v)			SORT(v),(v).erase(unique((v).begin(),(v).end()),(v).end())
#define CL(a,b)			memset(a,b,sizeof a)
#define pb				push_back

int main(){
#ifdef LocalHost
	freopen("input.txt","r",stdin);
	//freopen("output.txt","w",stdout);
#endif

	int x[3],y[3];
	REP(i,3)cin>>x[i]>>y[i];
	vector<pii> w;
	REP(i,3)REP(j,i)REP(tp,2){
		vector<pii> t;
		int x1 = x[i], y1 = y[i];
		t.pb(pii(x1,y1));

		while(x1!=x[j] || y1!=y[j]){
			if(tp==0){
				if(x1!=x[j])x1+=(x[j]>x1?1:-1);
				else y1 += (y[j]>y1?1:-1);
			}else{
				if(y1!=y[j])y1+=(y[j]>y1?1:-1);
				else x1 += (x[j]>x1?1:-1);
			}
			t.pb(pii(x1,y1));
		}
		int bt = 0;
		REP(q,t.size()){
			if(abs(t[bt].first-x[3-i-j])+abs(t[bt].first-y[3-i-j])>abs(t[q].first-x[3-i-j])+abs(t[q].second-y[3-i-j]))bt=q;
		}
		x1 = t[bt].first;
		y1 = t[bt].second;
		while(x1!=x[3-i-j] || y1!=y[3-i-j]){
			if(x1!=x[3-i-j])x1 += (x[3-i-j]>x1?1:-1);
			else y1 += (y[3-i-j]>y1?1:-1);
			t.pb(pii(x1,y1));
		}
		if(w.size() == 0 || w.size()>t.size()) w=t;
	}

	cout<<w.size()<<endl;
	REP(i,w.size()) cout<<w[i].first<<' '<<w[i].second<<endl;

#ifdef LocalHost
	printf("TIME: %.3lf\n",ld(clock())/CLOCKS_PER_SEC);
#endif
	return 0;
}


#pragma comment(linker, "/STACK:60777216")

#include <cassert>
#include<iostream>
#include<algorithm>
#include<cstdio>
#include<complex>
#include<vector>
#include<set>
#include<map>
#include<cmath>
#include<queue>
#include<string>
#include<cstdlib>
#include<memory.h>
#include<ctime>
#include<bitset>
#include<fstream>
#include<queue>
#include<stack>
#include<unordered_map>
#include<unordered_set>

using namespace std;

typedef long double ld;

typedef long long ll;
typedef pair<int,int>	pii;
typedef pair<ld,ld>	pdd;
typedef vector<int> vi;
typedef vector<ld> vd;
typedef pair<ll,ll> pl;

#define FOR(i,a,b)		for(int i=(a);i<(b);i++)
#define REP(i,n)		FOR(i,0,n)
#define SORT(v)			sort((v).begin(),(v).end())
#define UN(v)			SORT(v),(v).erase(unique((v).begin(),(v).end()),(v).end())
#define CL(a,b)			memset(a,b,sizeof a)
#define pb				push_back

int main(){
#ifdef LocalHost
	freopen("input.txt","r",stdin);
	//freopen("output.txt","w",stdout);
#endif

	int x[3],y[3];
	REP(i,3)cin>>x[i]>>y[i];
	vector<pii> w;
	REP(i,3)REP(j,3)REP(tp,2)if(i!=j){
		vector<pii> t;
		int x1 = x[i], y1 = y[i];
		t.pb(pii(x1,y1));

		while(x1!=x[j] || y1!=y[j]){
			if(tp==0){
				if(x1!=x[j])x1+=(x[j]>x1?1:-1);
				else y1 += (y[j]>y1?1:-1);
			}else{
				if(y1!=y[j])y1+=(y[j]>y1?1:-1);
				else x1 += (x[j]>x1?1:-1);
			}
			t.pb(pii(x1,y1));
		}
		int bt = 0;
		REP(q,t.size()){
			if(abs(t[bt].first-x[3-i-j])+abs(t[bt].second-y[3-i-j])>abs(t[q].first-x[3-i-j])+abs(t[q].second-y[3-i-j]))bt=q;
		}
		x1 = t[bt].first;
		y1 = t[bt].second;
		while(x1!=x[3-i-j] || y1!=y[3-i-j]){
			if(x1!=x[3-i-j])x1 += (x[3-i-j]>x1?1:-1);
			else y1 += (y[3-i-j]>y1?1:-1);
			t.pb(pii(x1,y1));
		}
		if(w.size() == 0 || w.size()>t.size()) w=t;
	}

	cout<<w.size()<<endl;
	REP(i,w.size()) cout<<w[i].first<<' '<<w[i].second<<endl;

#ifdef LocalHost
	printf("TIME: %.3lf\n",ld(clock())/CLOCKS_PER_SEC);
#endif
	return 0;
}


#include <bits/stdc++.h>

using namespace std;
typedef long long ll;
typedef pair<int, int> pi;

set<pi> path(pi x, pi y) {
  set<pi> sol;
  if (x.first > y.first)
    swap(x, y);
  for (int a = x.first; a <=y.first ; a++)
    sol.insert({a, x.second});
  x = {y.first, x.second};
  if (x.second > y.second)
    swap(x,y);
  for (int b = x.second; b <= y.second; b++)
    sol.insert({x.first, b});
  return sol;
}

int dist(pi x, pi y) {
  return abs(x.first-y.first)+abs(x.second-y.second);
}

int main() {
  ios_base::sync_with_stdio(false); cin.tie(NULL); cout.precision(20);
  vector<pi> a(3);
  for (int i = 0; i < 3; i++)
    cin >> a[i].first >> a[i].second;
  sort (a.begin(), a.end());
  if ((a[0].second <= a[1].second and a[1].second <= a[2].second) or (a[0].second >= a[1].second and a[1].second >= a[2].second) ) {

    set<pi> sol = path(a[0], a[1]);
    set<pi> p = path(a[2],a[1]);
    for (pi x:p)
      sol.insert(x);
    cout << sol.size() << endl;
    for (pi x: sol)
      cout <<  x.first << " " << x.second << "\n";
  }
  else {
    pi aux;
    aux.first = a[1].first;
    aux.second = a[0].second;
    set<pi> sol = path(a[0], aux);
    set<pi> p = path(a[1], aux);
    for (auto x: p)
      sol.insert(x);
    p = path(aux, a[2]);
    for (auto x: p)
      sol.insert(x);
    cout << sol.size() << endl;
    for (auto x: sol)
      cout << x.first << " " << x.second << "\n";
  }
  return 0;
}


#include <bits/stdc++.h>

using namespace std;
typedef long long ll;
typedef pair<int, int> pi;

set<pi> path(pi x, pi y) {
  set<pi> sol;
  if (x.first > y.first)
    swap(x, y);
  for (int a = x.first; a <=y.first ; a++)
    sol.insert({a, x.second});
  x = {y.first, x.second};
  if (x.second > y.second)
    swap(x,y);
  for (int b = x.second; b <= y.second; b++)
    sol.insert({x.first, b});
  return sol;
}

int dist(pi x, pi y) {
  return abs(x.first-y.first)+abs(x.second-y.second);
}

int main() {
  ios_base::sync_with_stdio(false); cin.tie(NULL); cout.precision(20);
  vector<pi> a(3);
  for (int i = 0; i < 3; i++)
    cin >> a[i].first >> a[i].second;
  sort (a.begin(), a.end());
  if ((a[0].second <= a[1].second and a[1].second <= a[2].second) or (a[0].second >= a[1].second and a[1].second >= a[2].second) ) {

    set<pi> sol = path(a[0], a[1]);
    set<pi> p = path(a[2],a[1]);
    for (pi x:p)
      sol.insert(x);
    cout << sol.size() << endl;
    for (pi x: sol)
      cout <<  x.first << " " << x.second << "\n";
  }
  else {
    pi aux;

    if (abs(a[0].second-a[1].second) < abs(a[2].second-a[1].second)) {
      aux.first = a[1].first;
      aux.second = a[0].second;
    }
    else {
      aux.first = a[1].first;
      aux.second = a[2].second;
    }

    set<pi> sol = path(a[0], aux);
    set<pi> p = path(a[1], aux);
    for (auto x: p)
      sol.insert(x);
    p = path(aux, a[2]);
    for (auto x: p)
      sol.insert(x);
    cout << sol.size() << endl;
    for (auto x: sol)
      cout << x.first << " " << x.second << "\n";
  }
  return 0;
}


#include <bits/stdc++.h>
using namespace std;
void print(vector<pair<int, int>> ans)
{
    cout<<ans.size()<<endl;
    for(auto i : ans)
        cout<<i.second<<" "<<i.first<<endl;
    exit(0);
}
vector<pair<int, int>> solve(pair<int, int> p1, pair<int, int> p2, pair<int, int> p3)
{
    set<pair<int, int>> ans;
    while(p1.first < p2.first && p1.first < p3.first)
    {
        ans.insert(p1);
        p1.first++;
        ans.insert(p1);
    }
    while(p1.first > p2.first && p1.first > p3.first)
    {
        ans.insert(p1);
        p1.first--;
        ans.insert(p1);
    }
    while(p1.second < p2.second && p1.second < p3.second)
    {
        ans.insert(p1);
        p1.second++;
        ans.insert(p1);
    }
    while(p1.second > p2.second && p1.second > p3.second)
    {
        ans.insert(p1);
        p1.second--;
        ans.insert(p1);
    }
    auto c = p1;
    while(c != p2)
    {
        ans.insert(c);
        if(c.first > p2.first)
        {
            c.first--;
            ans.insert(c);
        }
        if(c.first < p2.first)
        {
            c.first++;
            ans.insert(c);
        }
        if(c.second < p2.second)
        {
            c.second++;
            ans.insert(c);
        }
        if(c.second > p2.second)
        {
            c.second--;
            ans.insert(c);
        }
    }
    c = p1;
    p2.swap(p3);
    while(c != p2)
    {
      //  cout<<c.first<<" "<<c.second<<endl;
        ans.insert(c);
        if(c.first > p2.first)
        {
            c.first--;
            ans.insert(c);
        }
        if(c.first < p2.first)
        {
            c.first++;
            ans.insert(c);
        }
        if(c.second > p2.second)
        {
            c.second--;
            ans.insert(c);
        }
        if(c.second < p2.second)
        {
            c.second++;
            ans.insert(c);
        }
    }
    vector<pair<int, int>> a2;
    for(auto i : ans)
        a2.push_back(i);
    return a2;
}
signed main()
{
    int x1, y1, x2, y2, x3, y3;
    cin>>x1>>y1>>x2>>y2>>x3>>y3;
    auto v1 = solve({x1, y1}, {x2, y2}, {x3, y3}), v2 = solve({x2, y2}, {x1, y1}, {x3, y3}), v3 = solve({x3, y3}, {x1, y1}, {x2, y2});
    auto kek = v1;
    kek = min(kek, v2), kek = min(kek, v3);
    cout<<kek.size()<<endl;
    for(auto i : kek)
        cout<<i.first<<" "<<i.second<<endl;
}


#include <bits/stdc++.h>
#define mp make_pair
#define pb push_back
#define X first
#define Y second
#define y0 y12
#define y1 y22
#define INF 987654321
#define PI 3.141592653589793238462643383279502884
#define fup(i,a,b,c) for(int (i)=(a);(i)<=(b);(i)+=(c))
#define fdn(i,a,b,c) for(int (i)=(a);(i)>=(b);(i)-=(c))
#define MEM0(a) memset((a),0,sizeof(a));
#define MEM_1(a) memset((a),-1,sizeof(a));
#define ALL(a) a.begin(),a.end()
#define SYNC ios_base::sync_with_stdio(false);cin.tie(0)
using namespace std;
typedef long long ll;
typedef long double ld;
typedef double db;
typedef unsigned int uint;
typedef unsigned long long ull;
typedef pair<int, int> Pi;
typedef pair<ll, ll> Pll;
typedef pair<ld, ld> Pd;
typedef vector<int> Vi;
typedef vector<ll> Vll;
typedef vector<db> Vd;
typedef vector<Pi> VPi;
typedef vector<Pll> VPll;
typedef vector<Pd> VPd;
typedef tuple<int, int, int> iii;
typedef tuple<int, int, int, int> iiii;
typedef tuple<ll, ll, ll> LLL;
typedef vector<iii> Viii;
typedef vector<LLL> VLLL;
typedef complex<double> base;
const int MOD = 1000000007;
ll POW(ll a, ll b, ll MMM = MOD) { ll ret = 1; for (; b; b >>= 1, a = (a*a) % MMM)if (b & 1)ret = (ret*a) % MMM; return ret; }
ll gcd(ll a, ll b) { return b ? gcd(b, a%b) : a; }
ll lcm(ll a, ll b) { if (a == 0 || b == 0)return a + b; return a*(b / gcd(a, b)); }
int dx[] = { 0,1,0,-1,1,1,-1,-1 }, dy[] = { 1,0,-1,0,1,-1,1,-1 };
int ddx[] = { -1,-2,1,-2,2,-1,2,1 }, ddy[] = { -2,-1,-2,1,-1,2,1,2 };

inline int dist(int x1,int y1,int x2,int y2){
	return abs(x1-x2)+abs(y1-y2);
}
void print(int x1,int y1,int x,int y){
	while(x1<x)printf("%d %d\n",x1++,y1);
	while(x1>x)printf("%d %d\n",x1--,y1);
	while(y1<y)printf("%d %d\n",x1,y1++);
	while(y1>y)printf("%d %d\n",x1,y1--);
}
int main() {
	int x1,y1,x2,y2,x3,y3;
	cin>>x1>>y1>>x2>>y2>>x3>>y3;
	int t=INF,x=-1,y=-1;
	fup(i,0,1000,1){
		fup(j,0,1000,1){
			int tmp=dist(x1,y1,i,j)+dist(x2,y2,i,j)+dist(x3,y3,i,j);
			if(tmp<t){
				t=tmp;
				x=i,y=j;
			}
		}
	}
	printf("%d\n",t+1);
	print(x1,y1,x,y);
	print(x2,y2,x,y);
	print(x3,y3,x,y);
	printf("%d %d\n",x,y);
}


#include <iostream>
#include <cstdio>
#include <vector>
#include <algorithm>

using namespace std;

int main()
{
    vector<pair<int, int>> point;
    int xmax = -1, ymax = -1, xmin = 1005, ymin = 1005;
    for(int i = 0; i < 3; i++)
    {
        int x, y;
        scanf("%d %d", &x, &y);
        point.push_back(make_pair(x, y));

        xmax = max(xmax, x);
        xmin = min(xmin, x);
        ymax = max(ymax, y);
        ymin = min(ymin, y);
    }
    int ans = (xmax - xmin) + (ymax - ymin) + 1;
    sort(point.begin(), point.end());

    printf("%d\n", ans);
    for(int i = ymin; i <= ymax; i++)
    {
        printf("%d %d\n", point[1].first, i);
    }

    for(int i = point[0].first; i < point[1].first; i++)
    {
        printf("%d %d\n", i, point[0].second);
    }

    for(int i = point[1].first + 1; i <= point[2].first; i++)
    {
        printf("%d %d\n", i, point[2].second);
    }

    return 0;
}


#include <iostream>
#include <cstdio>
#include <vector>
#include <algorithm>

using namespace std;

int main()
{
    vector<pair<int, int>> point;
    int xmax = -1, ymax = -1, xmin = 1005, ymin = 1005;
    for(int i = 0; i < 3; i++)
    {
        int x, y;
        scanf("%d %d", &x, &y);
        point.push_back(make_pair(x, y));

        xmax = max(xmax, x);
        xmin = min(xmin, x);
        ymax = max(ymax, y);
        ymin = min(ymin, y);
    }
    int ans = (xmax - xmin) + (ymax - ymin) + 1;
    sort(point.begin(), point.end());

    printf("%d\n", ans);
    for(int i = 0; i <= ymax - ymin; i++)
    {
        printf("%d %d\n", point[1].first, i);
    }

    for(int i = point[0].first; i < point[1].first; i++)
    {
        printf("%d %d\n", i, point[0].second);
    }

    for(int i = point[1].first + 1; i <= point[2].first; i++)
    {
        printf("%d %d\n", i, point[2].second);
    }

    return 0;
}


#include<bits/stdc++.h>
using namespace std;

bool sorter(pair<int,int> a,pair<int,int> b) {
	return a.second <= b.second;
}

int main() {
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);

	vector<pair<int,int>>location(3);
	vector<int>tracker(1001);

	for(int i=0;i<3;i++) {
		cin>>location[i].first>>location[i].second;
		tracker[location[i].first] = location[i].second;
	}

	sort(location.begin(),location.end());

	int start = min({location[0].second,location[1].second,location[2].second});
	int end = max({location[0].second,location[1].second,location[2].second});

	int xdis = location[2].first - location[0].first;
	int ydis = end - start;

	cout<< (xdis+ydis+1)<<endl;

	for(int i=location[0].first;i<location[1].second;i++) {
		cout<<i<<" "<<location[0].second<<endl;
	}

	for(int j= start;j<= end;j++) {
		cout<<location[1].first<<" "<<j<<endl;
	}

	for(int i=location[1].first+1;i<=location[2].first;i++) {
		cout<<i<<" "<<location[2].second<<endl;
	}

	return 0;
}


#include<bits/stdc++.h>
using namespace std;

bool sorter(pair<int,int> a,pair<int,int> b) {
	return a.second <= b.second;
}

int main() {
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);

	vector<pair<int,int>>location(3);
	vector<int>tracker(1001);

	for(int i=0;i<3;i++) {
		cin>>location[i].first>>location[i].second;
		tracker[location[i].first] = location[i].second;
	}

	sort(location.begin(),location.end());

	int start = min({location[0].second,location[1].second,location[2].second});
	int end = max({location[0].second,location[1].second,location[2].second});

	int xdis = location[2].first - location[0].first;
	int ydis = end - start;

	cout<< (xdis+ydis+1)<<endl;

	for(int i=location[0].first;i<location[1].first;i++) {
		cout<<i<<" "<<location[0].second<<endl;
	}

	for(int j= start;j<= end;j++) {
		cout<<location[1].first<<" "<<j<<endl;
	}

	for(int i=location[1].first+1;i<=location[2].first;i++) {
		cout<<i<<" "<<location[2].second<<endl;
	}

	return 0;
}


#include<cstdio>
#include<algorithm>
#include<cmath>
using namespace std;
int v[1010][1010];
struct point {
	int x, y;
	point operator -(const point &p)const {
		return { x - p.x,y - p.y };
	}
	int SZ() {
		return abs(x) + abs(y);
	}
}A, B, C;
void Paint(point a, point b) {
	int i, j;
	int bx = min(a.x, b.x), ex = max(a.x, b.x);
	int by = min(a.y, b.y), ey = max(a.y, b.y);
	for (i = bx; i <= ex; i++) {
		for (j = by; j <= ey; j++) {
			if (i == bx || j == ey)v[i][j] = 1;
		}
	}
}
int main() {
	scanf("%d%d", &A.x, &A.y);
	scanf("%d%d", &B.x, &B.y);
	scanf("%d%d", &C.x, &C.y);
	int i, j, Mn = 1e9, px, py;
	for (i = 0; i <= 1000; i++) {
		for (j = 0; j <= 1000; j++) {
			point t = { i,j };
			int s = (t - A).SZ() + (t - B).SZ() + (t - C).SZ();
			if (Mn > s)Mn = s, px = i, py = j;
		}
	}
	printf("%d\n", Mn + 1);
	point t = { px,py };
	Paint(t, A);
	Paint(t, B);
	Paint(t, C);
	for (i = 0; i <= 1000; i++)for (j = 0; j <= 1000; j++)if (v[i][j])printf("%d %d\n", i, j);
}


#include<cstdio>
#include<algorithm>
#include<cmath>
using namespace std;
int v[1010][1010];
struct point {
	int x, y;
	point operator -(const point &p)const {
		return { x - p.x,y - p.y };
	}
	int SZ() {
		return abs(x) + abs(y);
	}
}A, B, C;
void Paint(point a, point b) {
	int i, j;
	int bx = min(a.x, b.x), ex = max(a.x, b.x);
	int by = min(a.y, b.y), ey = max(a.y, b.y);
	for (i = bx; i <= ex; i++) {
		for (j = by; j <= ey; j++) {
			if (i == a.x || j == b.y)v[i][j] = 1;
		}
	}
}
int main() {
	scanf("%d%d", &A.x, &A.y);
	scanf("%d%d", &B.x, &B.y);
	scanf("%d%d", &C.x, &C.y);
	int i, j, Mn = 1e9, px, py;
	for (i = 0; i <= 1000; i++) {
		for (j = 0; j <= 1000; j++) {
			point t = { i,j };
			int s = (t - A).SZ() + (t - B).SZ() + (t - C).SZ();
			if (Mn > s)Mn = s, px = i, py = j;
		}
	}
	printf("%d\n", Mn + 1);
	point t = { px,py };
	Paint(t, A);
	Paint(t, B);
	Paint(t, C);
	for (i = 0; i <= 1000; i++)for (j = 0; j <= 1000; j++)if (v[i][j])printf("%d %d\n", i, j);
}


#pragma GCC optimize("O3")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx")

#include <bits/stdc++.h>

#define pb push_back
#define fi first
#define se second
#define all(v) v.begin(), v.end()

using namespace std;
using ll = int64_t;

const int MAX_N = 3;
const int MAX_X = 1000;

pair<int,int> points[MAX_N];
int dx[] = {1, -1, 0, 0};
int dy[] = {0, 0, 1, -1};

int d(int x0, int y0, int x1, int y1) {
  return abs(x0 - x1) + abs(y0 - y1);
}

void print_path(int x0, int y0, int x1, int y1, bool print_first) {
  if (print_first)
    cout << x0 << " " << y0 << "\n";
  while (x0 != x1 || y0 != y1) {
    for (int k = 0; k < 4; k++) {
      int nx = x0 + dx[k];
      int ny = y0 + dy[k];
      if (d(nx, ny, x1, y1) < d(x0, y0, x1, y1)) {
        x0 = nx;
        y0 = ny;
        break;
      }
    }
    cout << x0 << " " << y0 << "\n";
  }
}

int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(nullptr);

  for (int i = 0; i < MAX_N; i++) {
    int x, y;
    cin >> x >> y;
    points[i] = {x, y};
  }

  int result = std::numeric_limits<int>::max();
  int start_x = -1, start_y = -1;
  for (int x = 0; x <= MAX_X; x++) {
    for (int y = 0; y <= MAX_X; y++) {
      int current_result = 0;
      for (int i = 0; i < 3; i++) {
        auto p = points[i];
        current_result += d(x, y, p.fi, p.se) + 1;
      }
      current_result -= (MAX_N - 1);
      if (current_result < result) {
        result = current_result;
        start_x = x;
        start_y = y;
      }
    }
  }
  cout << result << endl;
  for (int i = 0; i < MAX_N; i++) {
    print_path(start_x, start_y, points[i].fi, points[i].se, i == 0);
  }

  return 0;
}


#pragma GCC optimize("O3")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx")

#include <bits/stdc++.h>

#define pb push_back
#define fi first
#define se second
#define all(v) v.begin(), v.end()

using namespace std;
using ll = int64_t;

const int MAX_N = 3;
const int MAX_X = 1000;

pair<int,int> points[MAX_N];
int dx[] = {1, -1, 0, 0};
int dy[] = {0, 0, 1, -1};

int d(int x0, int y0, int x1, int y1) {
  return abs(x0 - x1) + abs(y0 - y1);
}

void print_path(int x0, int y0, int x1, int y1, bool print_first) {
  if (print_first)
    cout << x0 << " " << y0 << "\n";
  while (x0 != x1 || y0 != y1) {
    for (int k = 0; k < 4; k++) {
      int nx = x0 + dx[k];
      int ny = y0 + dy[k];
      if (d(nx, ny, x1, y1) < d(x0, y0, x1, y1)) {
        x0 = nx;
        y0 = ny;
        break;
      }
    }
    cout << x0 << " " << y0 << "\n";
  }
}

int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(nullptr);

  for (int i = 0; i < MAX_N; i++) {
    int x, y;
    cin >> x >> y;
    points[i] = {x, y};
  }

  int result = std::numeric_limits<int>::max();
  int start_x = -1, start_y = -1;
  for (int x = 0; x < MAX_X; x++) {
    for (int y = 0; y < MAX_X; y++) {
      int current_result = 0;
      for (int i = 0; i < 3; i++) {
        auto p = points[i];
        current_result += d(x, y, p.fi, p.se) + 1;
      }
      current_result -= (MAX_N - 1);
      if (current_result < result) {
        result = current_result;
        start_x = x;
        start_y = y;
      }
    }
  }
  cout << result << endl;
  for (int i = 0; i < MAX_N; i++) {
    print_path(start_x, start_y, points[i].fi, points[i].se, i == 0);
  }

  return 0;
}