stablegradients/pie-gem5-bysrc huggingface dataset:
// Original C++ solution (slower):
#include <bits/stdc++.h>

using namespace std;

int n;

typedef long long ll;

const int maxn = 2e5+5;

ll a[maxn],b[maxn];

int get_num(){

	int num = 0;

	char c;

	bool flag = false;

	while((c = getchar()) == ' ' || c == '\r' || c == '\n');

	if(c == '-')

		flag = true;

	else num = c - '0';

	while(isdigit(c = getchar()))

		num = (num<<3) + (num<<1) + c - '0';

	return (flag ? -1 : 1) * num;

}

ll ret = 0;

ll mxa,mna,mxb,mnb;

ll dmx,dmi;

ll id[maxn];

bool cmp(int x,int y){

	return a[x] < a[y];

}

int main(){

	n = get_num();

	mna = mnb = 1e9;

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

		id[i] = i;

		a[i] = get_num();

		b[i] = get_num();

		if(a[i] > b[i])swap(a[i],b[i]);

		mxa = max(mxa,a[i]);

		mna = min(mna,a[i]);

		mxb = max(mxb,b[i]);

		mnb = min(mnb,b[i]);

	}

	ret = (mxb - mnb) * (mxa - mna);

	dmx = 0;

	dmi = 1e9;

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

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

		dmx = max(dmx,b[id[i]]);

		dmi = min(dmi,b[id[i]]);

		ret = min(ret,(ll)(max(dmx,a[id[n]])-min(dmi,a[id[i+1]])) * (mxb - mna));

	}

	cout << ret << endl;

	return 0;

}

// Optimized solution to the same problem (faster):
#include <cstdio>

#include <algorithm>

#include <vector>

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



inline int read()

{

	int data = 0, w = 1; char ch = getchar();

	while (ch != '-' && (ch < '0' || ch > '9')) ch = getchar();

	if (ch == '-') w = -1, ch = getchar();

	while (ch >= '0' && ch <= '9') data = data * 10 + (ch ^ 48), ch = getchar();

	return data * w;

}



const int maxn(2e5 + 10);

std::pair<int, int> t[maxn]; long long ans;

int n, lx[maxn], ly[maxn], rx[maxn], ry[maxn];



int main()

{

	scanf("%d", &n), ly[0] = ry[n + 1] = 1e9;

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

	{

	    scanf("%d%d", &t[i].first, &t[i].second);

	    if (t[i].first > t[i].second) std::swap(t[i].first, t[i].second);

	}

	std::sort(t + 1, t + n + 1);

	for (int i = 1; i <= n; i++) lx[i] = std::max(lx[i - 1], t[i].second);

	for (int i = 1; i <= n; i++) ly[i] = std::min(ly[i - 1], t[i].second);

	for (int i = n; i; i--) rx[i] = std::max(rx[i + 1], t[i].second);

	for (int i = n; i; i--) ry[i] = std::min(ry[i + 1], t[i].second);

	ans = 1ll * (t[n].first - t[1].first) * (lx[n] - ly[n]);

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

	{

		int ax = std::max(t[n].first, lx[i]), ay = std::min(t[i + 1].first, ly[i]);

		int bx = std::max(rx[i + 1], t[i].first), by = std::min(ry[i + 1], t[1].first);

		ans = std::min(ans, 1ll * (ax - ay) * (bx - by));

	}

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

	return 0;

}


// Fastest known solution for this problem:
// Original C++ solution (slower):
#include <iostream>

#include <cstdio>

#include <cstdlib>

#include <cstring> 

#include <cmath> 

#include <algorithm>

#include <set> 

using namespace std; 

inline int gi() {

    register int data = 0, w = 1;

    register char ch = 0;

    while (!isdigit(ch) && ch != '-') ch = getchar(); 

    if (ch == '-') w = -1, ch = getchar(); 

    while (isdigit(ch)) data = 10 * data + ch - '0', ch = getchar(); 

    return w * data; 

}



const int MAX_N = 2e5 + 5; 

struct Node { int x, y; } a[MAX_N]; 

bool operator < (const Node &l, const Node &r) { 

	if (l.x == r.x) return l.y < r.y; 

	else return l.x < r.x; 

} 

int N; 

long long ans = 0; 

multiset<int> s1, s2; 



int main () { 

	N = gi(); 

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

		int x = gi(), y = gi(); 

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

		a[i] = (Node){x, y}; 

	} 

	sort(&a[1], &a[N + 1]); 

	for (int i = 1; i <= N; i++) s2.insert(a[i].y); 

	ans = 1ll * (a[N].x - a[1].x) * (*s2.rbegin() - *s2.begin()); 

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

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

		int mx1 = *s1.rbegin(), mn1 = *s1.begin(); 

		int mx2 = *s2.rbegin(); 

		int Lmax = max(mx1, a[N].x), Lmin = min(mn1, a[i + 1].x); 

		int Rmax = mx2, Rmin = a[1].x; 

		ans = min(ans, 1ll * (Lmax - Lmin) * (Rmax - Rmin)); 

	} 

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

    return 0; 

} 

// Optimized solution to the same problem (faster):
#include <cstdio>

#include <algorithm>

#include <vector>

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



inline int read()

{

	int data = 0, w = 1; char ch = getchar();

	while (ch != '-' && (ch < '0' || ch > '9')) ch = getchar();

	if (ch == '-') w = -1, ch = getchar();

	while (ch >= '0' && ch <= '9') data = data * 10 + (ch ^ 48), ch = getchar();

	return data * w;

}



const int maxn(2e5 + 10);

std::pair<int, int> t[maxn]; long long ans;

int n, lx[maxn], ly[maxn], rx[maxn], ry[maxn];



int main()

{

	scanf("%d", &n), ly[0] = ry[n + 1] = 1e9;

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

	{

	    scanf("%d%d", &t[i].first, &t[i].second);

	    if (t[i].first > t[i].second) std::swap(t[i].first, t[i].second);

	}

	std::sort(t + 1, t + n + 1);

	for (int i = 1; i <= n; i++) lx[i] = std::max(lx[i - 1], t[i].second);

	for (int i = 1; i <= n; i++) ly[i] = std::min(ly[i - 1], t[i].second);

	for (int i = n; i; i--) rx[i] = std::max(rx[i + 1], t[i].second);

	for (int i = n; i; i--) ry[i] = std::min(ry[i + 1], t[i].second);

	ans = 1ll * (t[n].first - t[1].first) * (lx[n] - ly[n]);

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

	{

		int ax = std::max(t[n].first, lx[i]), ay = std::min(t[i + 1].first, ly[i]);

		int bx = std::max(rx[i + 1], t[i].first), by = std::min(ry[i + 1], t[1].first);

		ans = std::min(ans, 1ll * (ax - ay) * (bx - by));

	}

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

	return 0;

}


// Fastest known solution for this problem:
// Original C++ solution (slower):
#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;

}


// Optimized solution to the same problem (faster):
#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;

}

// Fastest known solution for this problem:
// Original C++ solution (slower):
#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;

}

// Optimized solution to the same problem (faster):
#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;

} 


// Fastest known solution for this problem:
// Original C++ solution (slower):
#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;

}

// Optimized solution to the same problem (faster):
#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();

}

// Fastest known solution for this problem:
// Original C++ solution (slower):
#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);

}

// Optimized solution to the same problem (faster):
#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();

}

// Fastest known solution for this problem:
// Original C++ solution (slower):
#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;

}

	

	

	

// Optimized solution to the same problem (faster):
#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();

}

// Fastest known solution for this problem:
// Original C++ solution (slower):
    #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);

    }

// Optimized solution to the same problem (faster):
#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();

}

// Fastest known solution for this problem: