stablegradients/pie-gem5-pairs huggingface dataset:
// Slower C++ solution:
#include<bits/stdc++.h>

#define MAXN 200000+5

using namespace std;

typedef long long LL;

struct node

{

	LL x,y;

}P[MAXN];

LL n,minans=LLONG_MAX;

LL Rmax,Rmin,Lmax,Lmin;

int main()

{

	scanf("%lld",&n);

	for(int i=1;i<=n;i++)

	{

		scanf("%lld%lld",&P[i].x,&P[i].y);

	}

	for(int k=1;k<=100;k++)

	{

		srand(time(0));

		random_shuffle(P+1,P+n+1);

		Rmax=Rmin=P[1].x,Lmax=Lmin=P[1].y;

		for(int i=2;i<=n;i++)

		{

			LL rmax=Rmax,rmin=Rmin,lmax=Lmax,lmin=Lmin,ans=0;

			rmax=max(rmax,P[i].x),rmin=min(rmin,P[i].x);

			lmax=max(lmax,P[i].y),lmin=min(lmin,P[i].y);

			ans=(rmax-rmin)*(lmax-lmin);

			rmax=Rmax,rmin=Rmin,lmax=Lmax,lmin=Lmin;

			swap(P[i].x,P[i].y);

			rmax=max(rmax,P[i].x),rmin=min(rmin,P[i].x);

			lmax=max(lmax,P[i].y),lmin=min(lmin,P[i].y);

			if(ans>(rmax-rmin)*(lmax-lmin))

			{

				Rmax=max(Rmax,P[i].x),Rmin=min(Rmin,P[i].x);

				Lmax=max(Lmax,P[i].y),Lmin=min(Lmin,P[i].y);

			}

			else

			{

				Rmax=max(Rmax,P[i].y),Rmin=min(Rmin,P[i].y);

				Lmax=max(Lmax,P[i].x),Lmin=min(Lmin,P[i].x);

			}

		}

		minans=min(minans,(Rmax-Rmin)*(Lmax-Lmin));

	}

	printf("%lld ",minans);

	return 0;

}


// Faster C++ solution for the same problem (measured speedup: 1.1320428662899806x):
#include <iostream>

#include <cstdio>

#include <algorithm>

#include <cstring>

#include <cmath>

#include <cstdlib>

#define ll long long

#define rep(i, a, b) for(int i = (a); i <= (b); i++)

#define per(i, b, a) for(int i = (b); i >= (a); i--)

using namespace std;

const int N = 2e5 + 9, inf = 0x3f3f3f3f;

int n, l, r, cnt, sum, minn1 = inf, minn2 = inf, maxx1, maxx2, vis[N];

struct node{

    int num, pl;

}s[N << 1];

bool cmp(node x, node y){

    return x.num == y.num ? x.pl < y.pl : x.num < y.num;

}

int main(){

    scanf("%d", &n);

    rep(i, 1, n) {

        int x, y; scanf("%d%d", &x, &y);

        if(x > y) swap(x, y);

        minn1 = min(minn1, x), minn2 = min(minn2, y), maxx1 = max(maxx1, x), maxx2 = max(maxx2, y);

        s[++cnt].pl = i, s[cnt].num = x, s[++cnt].pl = i, s[cnt].num = y;

    }

    sort(s + 1, s + 2 * n + 1, cmp);

    l = 1;

    rep(i, 1, 2 * n) {

        if(!vis[s[i].pl]) sum++;

        vis[s[i].pl]++;

        if(sum == n) { r = i; break; }

    }

    int ans = s[r].num - s[l].num;

    while(r < n * 2){

        if(vis[s[l].pl] == 1) sum--;

        vis[s[l].pl]--, l++;

        if(sum != n) rep(i, r + 1, 2 * n) {

            vis[s[i].pl]++;

            if(vis[s[i].pl] == 1) {

                sum++, r = i;

                break;

            }

        }

        if(sum != n) break;

        ans = min(ans, s[r].num - s[l].num);

        //cout << l << " " << ans << endl;

    }

    //cout << ans << endl;

    printf("%lld", min(1ll * ans * (maxx2 - minn1), 1ll * (maxx1 - minn1) * (maxx2 - minn2)));

    return 0;

}
// Slower C++ solution:
#include <algorithm>

#include <cstdio>

using std::max;

using std::min;

using std::sort;

using std::swap;

struct rec

{

    int a, b;

    rec()

    {

        a = b = 0;

    }

    rec(int x, int y)

    {

        a = x;

        b = y;

    }

    friend bool operator<(const rec a, const rec b)

    {

        if (a.a == b.a)

        {

            return a.b < b.b;

        }

        return a.a < b.a;

    }

} a[200010];

int main()

{

    int n;

    rec mx(0, 0), mn(1e9, 1e9);

    scanf("%d", &n);

    for (int i = 1; i <= n; i++)

    {

        scanf("%d%d", &a[i].a, &a[i].b);

        if (a[i].a > a[i].b)

        {

            swap(a[i].a, a[i].b);

        }

        mx.a = max(mx.a, a[i].a);

        mx.b = max(mx.b, a[i].b);

        mn.a = min(mn.a, a[i].a);

        mn.b = min(mn.b, a[i].b);

    }

    long long ans = 1LL * (mx.a - mn.a) * (mx.b - mn.b);

    sort(a + 1, a + n + 1);

    mx = {a[n].a, mx.b};

    mn = {1000000000, a[1].a};

    for (int i = 1; i < n; i++)

    {

        mx.a = max(mx.a, a[i].b);

        mn.a = min(mn.a, a[i].b);

        ans = min(ans, 1LL * (mx.a - min(mn.a, a[i + 1].a)) * (mx.b - mn.b));

    }

    printf("%lld\n", ans);

    return 0;

}

// Faster C++ solution for the same problem (measured speedup: 1.804281550718174x):
#include<bits/stdc++.h>

typedef long long LL;

using namespace std;

const int N=2*1e5+5,inf=1e9+5;;

int n;

LL A,B=inf,_A,_B=inf,ans;

int in[N],ou[N],cnt;

struct card {LL val,bag;} b[N<<1];

bool cmp(card u,card v)

{

	return u.val<v.val;

}

int main()

{

	scanf("%d",&n);

	for(int i=1;i<=n;++i)

	{

		scanf("%lld%lld",&b[i*2-1].val,&b[i*2].val);

		b[i*2-1].bag=b[2*i].bag=i;

		if(b[i*2-1].val>b[i*2].val) swap(b[i*2-1],b[i*2]);

		A=max(b[i*2].val,A),B=min(b[i*2].val,B);

		_A=max(b[i*2-1].val,_A),_B=min(b[i*2-1].val,_B);

	}

	ans=(A-B)*(_A-_B);

	//cout<<ans<<" "<<A-_B<<endl;

	sort(b+1,b+n*2+1,cmp);

	//for(int i=1;i<=n<<1;++i) cout<<b[i].val<<" "<<b[i].bag<<endl;

	int l=2,r=2;

	while(r<=n*2)

	{

		while(cnt<n && r<=n*2) cnt+=(in[b[r].bag]==0),++in[b[r++].bag];

		if(r>2*n) break;

		while(in[b[l].bag]==2) --in[b[l].bag],++ou[b[l++].bag];

		ans=min(ans,(b[r-1].val-b[l].val)*(A-_B));

		//cout<<l<<" "<<r<<" "<<b[l].val<<" "<<b[r].val<<endl;

		if(ou[b[l].bag]==1) break;

		++ou[b[l].bag],--in[b[l].bag],++l,--cnt;

	}

	printf("%lld",ans);

	return 0;

}
// Slower C++ solution:
#include <algorithm>

#include <cstdio>

using std::max;

using std::min;

using std::sort;

using std::swap;

struct rec

{

    int a, b;

    rec()

    {

        a = b = 0;

    }

    rec(int x, int y)

    {

        a = x;

        b = y;

    }

    friend bool operator<(const rec a, const rec b)

    {

        if (a.a == b.a)

        {

            return a.b < b.b;

        }

        return a.a < b.a;

    }

} a[200010];

int main()

{

    int n;

    rec mx(0, 0), mn(1e9, 1e9);

    scanf("%d", &n);

    for (int i = 1; i <= n; i++)

    {

        scanf("%d%d", &a[i].a, &a[i].b);

        if (a[i].a > a[i].b)

        {

            swap(a[i].a, a[i].b);

        }

        mx.a = max(mx.a, a[i].a);

        mx.b = max(mx.b, a[i].b);

        mn.a = min(mn.a, a[i].a);

        mn.b = min(mn.b, a[i].b);

    }

    long long ans = 1LL * (mx.a - mn.a) * (mx.b - mn.b);

    sort(a + 1, a + n + 1);

    mx = {a[n].a, mx.b};

    mn = {1000000000, a[1].a};

    for (int i = 1; i < n; i++)

    {

        mx.a = max(mx.a, a[i].b);

        mn.a = min(mn.a, a[i].b);

        ans = min(ans, 1LL * (mx.a - min(mn.a, a[i + 1].a)) * (mx.b - mn.b));

    }

    printf("%lld\n", ans);

    return 0;

}

// Faster C++ solution for the same problem (measured speedup: 1.9392694392877028x):
#include <set>

#include <cmath>

#include <cstdio>

#include <cstring>

#include <algorithm>

using std::min; using std::max;

using std::swap; using std::sort;

typedef long long ll;



template<typename T>

void read(T &x) {

	int flag = 1; x = 0; char ch = getchar();

	while(ch < '0' || ch > '9') { if(ch == '-') flag = -flag; ch = getchar(); }

	while(ch >= '0' && ch <= '9') x = x * 10 + ch - '0', ch = getchar();

	x *= flag;

}

#if __cplusplus >= 201103l

template<typename T, typename... V>

void read(T &x, V&... v) { read(x), read(v...); }

#endif



const int _ = 2e5 + 10, Inf = 2e9 + 10;

int n, rmx, rmn = Inf, bmx, bmn = Inf; ll ret;

std::multiset<int> r, b;



struct node {

	int v1, v2;

	node() {}

	node(int _v1, int _v2) { v1 = _v1, v2 = _v2; }

	bool operator < (const node &a) const { return v1 < a.v1; }

} p[_];



ll calc() { return 1ll * (*r.rbegin() - *r.begin()) * (*b.rbegin() - *b.begin()); }



int main () {

	read(n);

	for(int i = 1, x, y; i <= n; ++i) {

		read(x, y); if(x > y) swap(x, y);

		p[i] = node(x, y), r.insert(x), b.insert(y);

	}

	ret = calc(), sort(p + 1, p + n + 1);

	for(int i = 1; i <= n; ++i) {

		int x = p[i].v1, y = p[i].v2;

		r.erase(r.find(x)), b.erase(b.find(y));

		r.insert(y), b.insert(x);

		ret = min(ret, calc());

	}

	printf("%lld\n", ret);

	return 0;

}
// Slower C++ solution:
#include <algorithm>

#include <cstdio>

using std::max;

using std::min;

using std::sort;

using std::swap;

struct rec

{

    int a, b;

    rec()

    {

        a = b = 0;

    }

    rec(int x, int y)

    {

        a = x;

        b = y;

    }

    friend bool operator<(const rec a, const rec b)

    {

        if (a.a == b.a)

        {

            return a.b < b.b;

        }

        return a.a < b.a;

    }

} a[200010];

int main()

{

    int n;

    rec mx(0, 0), mn(1e9, 1e9);

    scanf("%d", &n);

    for (int i = 1; i <= n; i++)

    {

        scanf("%d%d", &a[i].a, &a[i].b);

        if (a[i].a > a[i].b)

        {

            swap(a[i].a, a[i].b);

        }

        mx.a = max(mx.a, a[i].a);

        mx.b = max(mx.b, a[i].b);

        mn.a = min(mn.a, a[i].a);

        mn.b = min(mn.b, a[i].b);

    }

    long long ans = 1LL * (mx.a - mn.a) * (mx.b - mn.b);

    sort(a + 1, a + n + 1);

    mx = {a[n].a, mx.b};

    mn = {1000000000, a[1].a};

    for (int i = 1; i < n; i++)

    {

        mx.a = max(mx.a, a[i].b);

        mn.a = min(mn.a, a[i].b);

        ans = min(ans, 1LL * (mx.a - min(mn.a, a[i + 1].a)) * (mx.b - mn.b));

    }

    printf("%lld\n", ans);

    return 0;

}

// Faster C++ solution for the same problem (measured speedup: 1.8187305173493706x):
#include<iostream>

#include<cmath>

#include<cstdio>

#include<algorithm>

#include <string.h>

#define file(x) freopen(x".in","r",stdin);freopen(x".out","w",stdout);

using namespace std;

const int maxn=200005;

long long ans1,ans2=1e18,n,da,xiao,maxx,maxy,minx=1e9+10,miny=1e9+10,weizhiy,weizhix;

struct pai

{

	long long x,y;

	bool operator < (const pai &a)const

	{

		long long gx1,gx2;

		if(xiao<=x&&x<=da)

			gx1=0;

		else if(xiao<=y&&y<=da)

			gx1=0;

		else if(y<xiao)

			gx1=xiao-y;

		else if(x>da)

			gx1=x-da;

		else 

			gx1=min(xiao-x,y-da);

		if(xiao<=a.x&&a.x<=da)

			gx2=0;

		else if(xiao<=a.y&&a.y<=da)

			gx2=0;

		else if(a.y<xiao)

			gx2=xiao-a.y;

		else if(a.x>da)

			gx2=a.x-da;

		else 

			gx2=min(xiao-a.x,a.y-da);

		return gx1>gx2;

	}

} p[maxn];

int main()

{

//	file("1"); 

	scanf("%lld",&n);

	if(n==1)

	{

		printf("0");

		return 0;

	}

	for(int i=1; i<=n; i++)

	{

		scanf("%lld%lld",&p[i].x,&p[i].y);

		if(p[i].x>p[i].y)

			swap(p[i].x,p[i].y);

		maxx=max(maxx,p[i].x);

		if(p[i].y>maxy)

		{

			weizhiy=i;

			maxy=p[i].y;

		}

		if(p[i].x<minx)

		{

			weizhix=i;

			minx=p[i].x;

		}

		miny=min(miny,p[i].y);

	}

	ans1=(maxy-miny)*(maxx-minx);

//	cout<<ans1<<endl;

	da=p[weizhix].y,xiao=p[weizhiy].x;

	sort(p+1,p+n+1);

	if(da<xiao)

		swap(da,xiao);

	if(weizhix!=weizhiy)

	{

		for(int i=1; i<=n; i++)

		{

			int t=i;

			if((xiao<=p[i].x&&p[i].x<=da)||(xiao<=p[i].y&&p[i].y<=da))

				continue;

			else if(p[i].x>da)

				da=p[i].x;

			else if(p[i].y<xiao)

				xiao=p[i].y;

			else if(xiao-p[i].x<p[i].y-da)

				xiao=p[i].x;

			else

				da=p[i].y;

		}

		ans2=(maxy-minx)*(da-xiao);

	}

//	cout<<ans2<<endl;

	printf("%lld",min(ans1,ans2));

	return 0;

}
// Slower C++ solution:
#include<cstdio>

#include<cctype>

#include<cstring>

#include<set>

#include<algorithm>

#define reg register

typedef long long ll;

template<typename T>inline T read(){

    reg T x=0;reg short f=1;reg char c=getchar();

    for(;!isdigit(c);f=c=='-'?-1:1,c=getchar());

    for(;isdigit(c);x=x*10+(c^48),c=getchar());

    return x*f;

}

using std::multiset;

const int MN=2e5+5;

int n,x[MN],y[MN],id[MN];

inline void swap(int& a,int& b){a^=b;b^=a;a^=b;}

inline bool cmp(int a,int b){return x[a]<x[b];}

inline ll min(ll a,ll b){return a<b?a:b;}

multiset<int>s1,s2;

int main(){

	n=read<int>();reg int cnt,i;reg ll ans;

	for(i=1;i<=n;++i){

		x[i]=read<int>(),y[i]=read<int>();id[i]=i;

		if(x[i]>y[i])swap(x[i],y[i]);s1.insert(x[i]);s2.insert(y[i]);

	}

	std::sort(id+1,id+1+n,cmp);

	ans=1ll*(*s1.rbegin()-*s1.begin())*(*s2.rbegin()-*s2.begin());

	for(i=1;i<=n;++i){

		s1.erase(s1.find(x[id[i]]));s2.insert(x[id[i]]);

		s2.erase(s2.find(y[id[i]]));s1.insert(y[id[i]]);

		ans=min(ans,1ll*(*s1.rbegin()-*s1.begin())*(*s2.rbegin()-*s2.begin()));

	}

	printf("%lld\n",ans);

	return 0;

}

// Faster C++ solution for the same problem (measured speedup: 4.998407932197286x):
#include <cstdio>

#include <algorithm>

#include <cstring>

#include <cctype>

using namespace std;



namespace zyt

{

	template<typename T>

	inline bool read(T &x)

	{

		char c;

		bool f = false;

		x = 0;

		do

			c = getchar();

		while (c != EOF && c != '-' && !isdigit(c));

		if (c == EOF)

			return false;

		if (c == '-')

			f = true, c = getchar();

		do

			x = x * 10 + c - '0', c = getchar();

		while (isdigit(c));

		if (f)

			x = -x;

		return true;

	}

	template<typename T>

	inline void write(T x)

	{

		static char buf[20];

		char *pos = buf;

		if (x < 0)

			putchar('-'), x = -x;

		do

			*pos++ = x % 10 + '0';

		while (x /= 10);

		while (pos > buf)

			putchar(*--pos);

	}

	typedef long long ll;

	typedef pair<int, int> pii;

	const int N = 2e5 + 10;

	int n, sufmx[N], sufmn[N];

	pii arr[N];

	int work()

	{

		read(n);

		int mx = 0, mn = 1e9;

		for (int i = 1; i <= n; i++)

		{

			read(arr[i].first), read(arr[i].second);

			if (arr[i].first > arr[i].second)

				swap(arr[i].first, arr[i].second);

			mx = max(mx, arr[i].second), mn = min(mn, arr[i].second);

		}

		sort(arr + 1, arr + n + 1);

		ll ans = ll(arr[n].first - arr[1].first) * (mx - mn), k = mx - arr[1].first;

		mn = 1e9, mx = 0;

		sufmx[n + 1] = 0, sufmn[n + 1] = 1e9;

		for (int i = n; i > 0; i--)

			sufmx[i] = max(sufmx[i + 1], arr[i].first), sufmn[i] = min(sufmn[i + 1], arr[i].first);

		for (int i = 1; i <= n; i++)

		{

			mn = min(mn, arr[i].second), mx = max(mx, arr[i].second);

			ans = min(ans, k * (max(sufmx[i + 1], mx) - min(sufmn[i + 1], mn)));

		}

		write(ans);

		return 0;

	}

}

int main()

{

	return zyt::work();

}
// Slower C++ solution:
#include<bits/stdc++.h>

#define INF 0x7fffffff

#define P pair<int,int>

#define ll long long

#define f first

#define s second

using namespace std;

int n,nn,nx,mx=-INF,mn=INF;

P a[200005];

ll ans=1e18;

inline int read(){

    int x=0,f=1;char ch=getchar();

    while(ch<'0'||ch>'9'){if(ch=='-')f=-1;ch=getchar();}

    while(ch>='0'&&ch<='9'){x=(x<<3)+(x<<1)+ch-'0';ch=getchar();}

    return x*f;

}

int main(){

	n=read();

	for(int i=1;i<=n;++i){

		a[i].f=read(),a[i].s=read();

		if(a[i].f>a[i].s) swap(a[i].f,a[i].s);

		mx=max(mx,a[i].s),mn=min(mn,a[i].s);

	}

	sort(a+1,a+n+1);

	ans=1ll*(mx-mn)*(a[n].f-a[1].f),nn=nx=a[1].s;

	for(int i=2;i<=n;++i){

		ans=min(ans,1ll*(mx-a[1].f)*(max(nx,a[n].f)-min(nn,a[i].f)));

		nn=min(nn,a[i].s),nx=max(nx,a[i].s);

	}

	printf("%lld",ans);

}

// Faster C++ solution for the same problem (measured speedup: 5.308386908134603x):
#include <cstdio>

#include <algorithm>

#include <cstring>

#include <cctype>

using namespace std;



namespace zyt

{

	template<typename T>

	inline bool read(T &x)

	{

		char c;

		bool f = false;

		x = 0;

		do

			c = getchar();

		while (c != EOF && c != '-' && !isdigit(c));

		if (c == EOF)

			return false;

		if (c == '-')

			f = true, c = getchar();

		do

			x = x * 10 + c - '0', c = getchar();

		while (isdigit(c));

		if (f)

			x = -x;

		return true;

	}

	template<typename T>

	inline void write(T x)

	{

		static char buf[20];

		char *pos = buf;

		if (x < 0)

			putchar('-'), x = -x;

		do

			*pos++ = x % 10 + '0';

		while (x /= 10);

		while (pos > buf)

			putchar(*--pos);

	}

	typedef long long ll;

	typedef pair<int, int> pii;

	const int N = 2e5 + 10;

	int n, sufmx[N], sufmn[N];

	pii arr[N];

	int work()

	{

		read(n);

		int mx = 0, mn = 1e9;

		for (int i = 1; i <= n; i++)

		{

			read(arr[i].first), read(arr[i].second);

			if (arr[i].first > arr[i].second)

				swap(arr[i].first, arr[i].second);

			mx = max(mx, arr[i].second), mn = min(mn, arr[i].second);

		}

		sort(arr + 1, arr + n + 1);

		ll ans = ll(arr[n].first - arr[1].first) * (mx - mn), k = mx - arr[1].first;

		mn = 1e9, mx = 0;

		sufmx[n + 1] = 0, sufmn[n + 1] = 1e9;

		for (int i = n; i > 0; i--)

			sufmx[i] = max(sufmx[i + 1], arr[i].first), sufmn[i] = min(sufmn[i + 1], arr[i].first);

		for (int i = 1; i <= n; i++)

		{

			mn = min(mn, arr[i].second), mx = max(mx, arr[i].second);

			ans = min(ans, k * (max(sufmx[i + 1], mx) - min(sufmn[i + 1], mn)));

		}

		write(ans);

		return 0;

	}

}

int main()

{

	return zyt::work();

}
// Slower C++ solution:
#include<bits/stdc++.h>

using namespace std;



typedef long long LL;



const int N=2e5+10;



pair<LL,LL>A[N];

LL f[N][3];



int cmp(pair<LL,LL>a,pair<LL,LL>b)

{

	if(a.first==b.first) return a.second<b.second;

	return a.first<b.first;

}

	



int n;

LL Ans;





int main()

{

	cin>>n;

	for(int i=1;i<=n;i++)

	{

		LL x,y;

		scanf("%lld%lld",&x,&y);

		if(x>y) swap(x,y);

		A[i]=make_pair(x,y);

	}

	sort(A+1,A+n+1,cmp);

	Ans=1e18;

	for(int i=1;i<=n;i++) f[i][0]=max(f[i-1][0],A[i].second);

	for(int i=n;i;i--) f[i][1]=max(f[i+1][1],A[i].second);

	f[0][2]=1e18;

	for(int i=1;i<=n;i++) f[i][2]=min(f[i-1][2],A[i].second);

	LL R1,R2,B1,B2;

	R1=A[n].first,R2=A[1].first,B1=0,B2=1e9;

	for(int i=1;i<=n;i++) B1=max(B1,A[i].second),B2=min(B2,A[i].second);

	Ans=(R1-R2)*(B1-B2);

	for(int i=1;i<n;i++)

	{

		R1=max(R1,A[i].second);

		R2=min(A[i+1].first,f[i][2]);

		B1=f[i+1][1];

		B2=A[1].first;

		if(R2<=f[i][0]) Ans=min(Ans,(R1-R2)*(B1-B2));

	}			

	cout<<Ans<<endl;

}

	

	

	

// Faster C++ solution for the same problem (measured speedup: 5.408498955297348x):
#include <cstdio>

#include <algorithm>

#include <cstring>

#include <cctype>

using namespace std;



namespace zyt

{

	template<typename T>

	inline bool read(T &x)

	{

		char c;

		bool f = false;

		x = 0;

		do

			c = getchar();

		while (c != EOF && c != '-' && !isdigit(c));

		if (c == EOF)

			return false;

		if (c == '-')

			f = true, c = getchar();

		do

			x = x * 10 + c - '0', c = getchar();

		while (isdigit(c));

		if (f)

			x = -x;

		return true;

	}

	template<typename T>

	inline void write(T x)

	{

		static char buf[20];

		char *pos = buf;

		if (x < 0)

			putchar('-'), x = -x;

		do

			*pos++ = x % 10 + '0';

		while (x /= 10);

		while (pos > buf)

			putchar(*--pos);

	}

	typedef long long ll;

	typedef pair<int, int> pii;

	const int N = 2e5 + 10;

	int n, sufmx[N], sufmn[N];

	pii arr[N];

	int work()

	{

		read(n);

		int mx = 0, mn = 1e9;

		for (int i = 1; i <= n; i++)

		{

			read(arr[i].first), read(arr[i].second);

			if (arr[i].first > arr[i].second)

				swap(arr[i].first, arr[i].second);

			mx = max(mx, arr[i].second), mn = min(mn, arr[i].second);

		}

		sort(arr + 1, arr + n + 1);

		ll ans = ll(arr[n].first - arr[1].first) * (mx - mn), k = mx - arr[1].first;

		mn = 1e9, mx = 0;

		sufmx[n + 1] = 0, sufmn[n + 1] = 1e9;

		for (int i = n; i > 0; i--)

			sufmx[i] = max(sufmx[i + 1], arr[i].first), sufmn[i] = min(sufmn[i + 1], arr[i].first);

		for (int i = 1; i <= n; i++)

		{

			mn = min(mn, arr[i].second), mx = max(mx, arr[i].second);

			ans = min(ans, k * (max(sufmx[i + 1], mx) - min(sufmn[i + 1], mn)));

		}

		write(ans);

		return 0;

	}

}

int main()

{

	return zyt::work();

}
// Slower C++ solution:
    #include<bits/stdc++.h>

    #define int long long

    using namespace std;

    const int inf=1e9,mod=1e9+7;

    typedef long long ll;

    int read() {

    	int x=0,f=1;

    	char c=getchar();

    	while(c<'0'||c>'9') f=(c=='-')?-1:1,c=getchar();

    	while(c>='0'&&c<='9') x=x*10+c-'0',c=getchar();

    	return x*f;

    }

    struct node {

    	int x,y,id;

    } a[1000001];

    multiset<int> red;

    multiset<int> blue;

    bool cmp(const node & a , const node & b ){

    	return a.x<b.x;	

    }

    int calc(){

    	return (*red.rbegin()-*red.begin())*(*blue.rbegin()-*blue.begin());

    }

    main() {

    	int n=read();

    	for(int i=1; i<=n; i++) {

    		a[i].x=read(),a[i].y=read();

    		if(a[i].x>a[i].y) swap(a[i].x,a[i].y);

    		red.insert(a[i].x);

    		blue.insert(a[i].y);

    	}

    	sort(a+1,a+1+n,cmp);

    	int minx=calc();

    	for(int i=1;i<=n;i++){

    		int x=a[i].x,y=a[i].y;

    		red.erase(red.find(a[i].x));

    		blue.erase(blue.find(a[i].y));

    		red.insert(a[i].y),blue.insert(a[i].x);

    		minx=min(minx,calc());

    	}

    	printf("%lld",minx);

    }

// Faster C++ solution for the same problem (measured speedup: 5.336885178058249x):
#include <cstdio>

#include <algorithm>

#include <cstring>

#include <cctype>

using namespace std;



namespace zyt

{

	template<typename T>

	inline bool read(T &x)

	{

		char c;

		bool f = false;

		x = 0;

		do

			c = getchar();

		while (c != EOF && c != '-' && !isdigit(c));

		if (c == EOF)

			return false;

		if (c == '-')

			f = true, c = getchar();

		do

			x = x * 10 + c - '0', c = getchar();

		while (isdigit(c));

		if (f)

			x = -x;

		return true;

	}

	template<typename T>

	inline void write(T x)

	{

		static char buf[20];

		char *pos = buf;

		if (x < 0)

			putchar('-'), x = -x;

		do

			*pos++ = x % 10 + '0';

		while (x /= 10);

		while (pos > buf)

			putchar(*--pos);

	}

	typedef long long ll;

	typedef pair<int, int> pii;

	const int N = 2e5 + 10;

	int n, sufmx[N], sufmn[N];

	pii arr[N];

	int work()

	{

		read(n);

		int mx = 0, mn = 1e9;

		for (int i = 1; i <= n; i++)

		{

			read(arr[i].first), read(arr[i].second);

			if (arr[i].first > arr[i].second)

				swap(arr[i].first, arr[i].second);

			mx = max(mx, arr[i].second), mn = min(mn, arr[i].second);

		}

		sort(arr + 1, arr + n + 1);

		ll ans = ll(arr[n].first - arr[1].first) * (mx - mn), k = mx - arr[1].first;

		mn = 1e9, mx = 0;

		sufmx[n + 1] = 0, sufmn[n + 1] = 1e9;

		for (int i = n; i > 0; i--)

			sufmx[i] = max(sufmx[i + 1], arr[i].first), sufmn[i] = min(sufmn[i + 1], arr[i].first);

		for (int i = 1; i <= n; i++)

		{

			mn = min(mn, arr[i].second), mx = max(mx, arr[i].second);

			ans = min(ans, k * (max(sufmx[i + 1], mx) - min(sufmn[i + 1], mn)));

		}

		write(ans);

		return 0;

	}

}

int main()

{

	return zyt::work();

}