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

#define LL long long

#define Accel ios::sync_with_stdio(0), cin.tie(0), cout.tie(0);

#define Re(a,b) memset(a,b,sizeof a)

#define F first

#define S second

#define MP make_pair

#define PB push_back

#define ALL(X) (X).begin(), (X).end()

#define FOR(I, A, B) for (int I = (A); I <= (B); I++)

#define REP(I, N) for (int I = 0; I < (N); I++)

#define PII pair<int,int>

#define PLL pair<LL,LL>

#define SZ(a) ((int)a.size())

using namespace std;

const int N=1e5+10;

int p[N];

int find(int x){

	if(x==p[x])return p[x];

	return p[x]=find(p[x]);

}

int n,k;

int a[N];

vector<int>g[N];

set<int>s[N];

int main(){

	cin>>n>>k;

	FOR(i,1,n)cin>>a[i],p[i]=i;

	REP(i,k){

		int u,v;cin>>u>>v;u=find(u),v=find(v);

		p[u]=v;

	}

	int t=0;

	FOR(i,1,n){

		find(i);

		if(s[p[i]].find(i)!=s[p[i]].end()){

			t++;

		}

		else s[p[i]].insert(i);

		

		if(s[p[i]].find(a[i])!=s[p[i]].end()){

			t++;

		}

		else s[p[i]].insert(a[i]);

		

	}

	cout<<t<<endl;



}

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

#define LL long long

#define Accel ios::sync_with_stdio(0), cin.tie(0), cout.tie(0);

#define Re(a,b) memset(a,b,sizeof a)

#define F first

#define S second

#define MP make_pair

#define PB push_back

#define ALL(X) (X).begin(), (X).end()

#define FOR(I, A, B) for (int I = (A); I <= (B); I++)

#define REP(I, N) for (int I = 0; I < (N); I++)

#define PII pair<int,int>

#define PLL pair<LL,LL>

#define SZ(a) ((int)a.size())

using namespace std;

const int N=1e5+10;

int p[N];

int find(int x){

	if(x==p[x])return p[x];

	return p[x]=find(p[x]);

}

int n,k;

int a[N];

int main(){

	cin>>n>>k;

	FOR(i,1,n)cin>>a[i],p[i]=i;

	REP(i,k){

		int u,v;cin>>u>>v;u=find(u),v=find(v);

		p[u]=v;

	}

	int t=0;

	FOR(i,1,n){

		if(find(i)==find(a[i]))t++;

		

	}

	cout<<t<<endl;



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

using namespace std;

typedef pair<int,int> P;

typedef long long ll;

typedef long double ld;

const int inf=1e9+7;

const ll longinf=1LL<<60;

#define REP(i,m,n) for(int i=(int)(m) ; i < (int) (n) ; ++i )

#define rep(i,n) REP(i,0,n)

#define F first

#define S second



const int mx=100010;

const ll mod=1e9+7;



vector<int> par(mx);



int find(int x){

  if(par[x]==x){ return x; } else { return par[x]=find(par[x]); }

}



void unite(int x, int y){

  x=find(x);

  y=find(y);

  par[y]=x;

}



int main(){

  int n,m,ans=0; 

  cin >> n >> m;

  vector<int> a(n);

  rep(i,n){ cin >> a[i]; a[i]--; }

  rep(i,n){ par[i] = i; }

  rep(i,m){ 

  	int x, y;

  	cin >> x >> y;

  	unite(x-1,y-1);

  }

  rep(i,n){if(find(i)==find(a[i])){ ans++; }}

  

  cout << ans << endl;

  return 0;

}

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

using namespace std;

typedef pair<int,int> P;

typedef long long ll;

typedef long double ld;

const int inf=1e9+7;

const ll longinf=1LL<<60;

#define REP(i,m,n) for(int i=(int)(m) ; i < (int) (n) ; ++i )

#define rep(i,n) REP(i,0,n)

#define F first

#define S second



const int mx=100010;

const ll mod=1e9+7;



struct UnionFind {  

  vector<int> par; // par[i]:iの親の番号　(例) par[3] = 2 : 3の親が2

  UnionFind(int n) : par(n) { //最初は全てが根であるとして初期化

    for(int i=0; i<n; i++){ par[i]=i; }  

  }

  int root(int x) { // データxが属する木の根を再帰で得る：root(x) = {xの木の根}

    if(par[x]==x){ return x; }

    return par[x] = root(par[x]);

  }

  void unite(int x, int y) { // xとyの木を併合

    int rx = root(x); //xの根をrx

    int ry = root(y); //yの根をry

    if(rx == ry){ return; }//xとyの根が同じ(=同じ木にある)時はそのまま

    par[rx] = ry; //xとyの根が同じでない(=同じ木にない)時：xの根rxをyの根ryにつける

  }



  bool check(int x, int y) { // 2つのデータx, yが属する木が同じならtrueを返す

    return root(x) == root(y);

  }

};



int main() {

  int n,m; cin >> n >> m;

  UnionFind tree(n);

  vector<int> a(n);

  rep(i,n){ cin>>a[i]; a[i]--; }

  rep(i,m){

    int x,y; cin >> x >> y;

    tree.unite(x-1,y-1);

  }

  int ans=0;

  rep(i,n){ if(tree.check(i,a[i])){ ans++; } }

  

  cout << ans << endl;

  return 0;

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

using namespace std;

typedef pair<int,int> P;

typedef long long ll;

typedef long double ld;

const int inf=1e9+7;

const ll longinf=1LL<<60;

#define REP(i,m,n) for(int i=(int)(m) ; i < (int) (n) ; ++i )

#define rep(i,n) REP(i,0,n)

#define F first

#define S second



const int mx=100010;

const ll mod=1e9+7;



vector<int> par(mx);



int find(int x){

  if(par[x]==x){ return x; } else { return par[x]=find(par[x]); }

}



void unite(int x, int y){

  x=find(x);

  y=find(y);

  par[y]=x;

}



int main(){

  int n,m,ans=0; 

  cin >> n >> m;

  vector<int> a(n);

  rep(i,n){ cin >> a[i]; a[i]--; }

  rep(i,n){ par[i] = i; }

  rep(i,m){ 

  	int x, y;

  	cin >> x >> y;

  	unite(x-1,y-1);

  }

  rep(i,n){if(find(i)==find(a[i])){ ans++; }}

  

  cout << ans << endl;

  return 0;

}

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

using namespace std;

typedef pair<int,int> P;

typedef long long ll;

typedef long double ld;

const int inf=1e9+7;

const ll longinf=1LL<<60;

#define REP(i,m,n) for(int i=(int)(m) ; i < (int) (n) ; ++i )

#define rep(i,n) REP(i,0,n)

#define F first

#define S second

 

const int mx=100010;

const ll mod=1e9+7;



struct UnionFind {  

  vector<int> par,sizes;                     // par[i]:iの親の番号(ex)par[3]=2 : 3の親が2

  UnionFind(int n) : par(n),sizes(n,1)  {    //最初は全てが根であるとして初期化

    for(int i=0; i<n; i++){ par[i]=i; }  

  }

  int root(int x) {                       //xが属する木の根を再帰で得る:root(x)={xの木の根}

    if(par[x]==x){ return x; }

    return par[x] = root(par[x]);

  }

  void unite(int x, int y) {                 // xとyの木を併合

    int rx = root(x);                        //xの根をrx

    int ry = root(y);                        //yの根をry

    if(rx == ry){ return; }                  //xとyの根が同じ(=同じ木にある)時はそのまま

    if(sizes[rx]<sizes[ry]){ swap(rx, ry); } //xの木をおおきくする

    par[ry] = rx; 

    sizes[rx] += sizes[ry];                  //sizes[ry]はもう使わない

  }

  bool check(int x, int y) {                 // x,yが属する木が同じならtrueを返す

    return root(x) == root(y);

  }

  int size(int x){                           //xが含まれる木の大きさを返す

    return sizes[root(x)];

  }

};



int main(){

  int n,m;

  cin >> n >> m;

  vector<int> p(n);

  rep(i,n){ cin>>p[i]; p[i]--; }

  UnionFind uf(n);

  rep(i,m){

    int x,y; cin>>x>>y; x--; y--;

    uf.unite(x,y);

  }

  int ans=0;

  rep(i,n){

    if(uf.check(i,p[i])) ans++;

  }

  cout << ans << endl;

  return 0;

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



# define pb push_back

# define fr first

# define sc second

# define mk make_pair



using namespace std;



const int inf = 1000000000 + 7;

const int N = 2e5 + 5;



typedef long long ll;



int n, mn1 = inf, mn2 = inf, mx1, mx2;

ll ans = 2e18;

pair <int, int> a[N];



int main()

{

    cin >> n;



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

    {

        cin >> a[i].fr >> a[i].sc;

        if(a[i].fr > a[i].sc) swap(a[i].fr, a[i].sc);

        mn1 = min(a[i].fr, mn1);

        mn2 = min(a[i].sc, mn2);

        mx1 = max(a[i].fr, mx1);

        mx2 = max(a[i].sc, mx2);

    }



    ans = mx1 - mn1;

    ans *= (mx2 - mn2);



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



    mx1 = mx2, mn2 = a[2].fr;



    ll l = 1e9, r = a[n].fr;

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

    {

        l = min(l, a[i].sc * 1ll);

        r = max(r, a[i].sc * 1ll);

        ans = min(ans, (mx1 - mn1) * 1ll * (r - min(l, a[i + 1].fr * 1ll)));

    }

    cout << ans << endl;

}


// Faster C++ solution for the same problem (measured speedup: 5.197263750076447x):
#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;

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



#define pb push_back

#define mk make_pair

#define sc second

#define fr first



using namespace std;



typedef long long ll;



const long long N = (long long) 1e6 + 5;

const long long mod = (long long) 1e9 + 7;



pair<long long,long long> a[N];



long long n;

long long mn,mn1 = mod,mx,mx1,mnn,res,mxx;



int main () {

        ios_base::sync_with_stdio(false);



        cin >> n;



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

                cin >> a[i].fr >> a[i].sc;

                if(a[i].fr > a[i].sc)

                        swap (a[i].fr,a[i].sc);

                mn1 = min (mn1,a[i].sc);

                mx1 = max (mx1,a[i].sc);

        }



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



        mn = a[1].fr; mx = a[n].fr;



        res = (mx - mn) * 1ll * (mx1 - mn1);



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

                if(i > 1) mnn = min (mnn,a[i].sc);

                else mnn = a[i].sc;

                mxx = max (mxx,a[i].sc);



                res = min (res,(mx1 - mn) * 1ll * (max(mxx,a[n].fr) - min(a[i + 1].fr,mnn)));

        }

        cout << res << endl;

        return 0;

}


// Faster C++ solution for the same problem (measured speedup: 5.260654411327332x):
#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;

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

using namespace std;

typedef long long ll;

const int MAX = (1e5)+1;

 int n;

vector<pair<ll, ll> > a;

multiset<ll> r, b;

long long ans = LLONG_MAX;

int main() {	

ios::sync_with_stdio(false);

cin.tie(0);	

cin >> n;

a.resize(n);	

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

	cin >> a[i].first >> a[i].second;		if(a[i].first > a[i].second) 

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

	}	

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

	for(auto p: a) {	

	r.insert(p.first);	

	b.insert(p.second);	}	

ans = min((*r.rbegin() - *r.begin()) * (*b.rbegin() - *b.begin()), ans);	

for(auto p: a) {	

	r.erase(r.find(p.first));		b.erase(b.find(p.second));		r.insert(p.second);	

	b.insert(p.first);	

	ans = min((*r.rbegin() - *r.begin()) * (*b.rbegin() - *b.begin()), ans);	}

	cout << ans;}

// Faster C++ solution for the same problem (measured speedup: 5.297084145756956x):
#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;

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

# define f first

# define s second



using namespace std;



const int N = 1e6;



long long n, x, y, ans;

pair <long long, long long> a[N], b[N];



int main(){

      scanf("%lld", &n);

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

             scanf("%lld %lld", &a[i].f, &a[i].s);

             if(a[i].f > a[i].s)

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

             b[i].f = a[i].s, b[i].s = a[i].f;

      }



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

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



      ans = (a[n].f - a[1].f) * (b[n].f - b[1].f);

      long long r = a[n].f, l = 1e9;

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

             l = min(a[i].s, l);

             r = max(r, a[i].s);

             ans = min(ans, (b[n].f - a[1].f) * (r - min(l, a[i + 1].f)));

      }

      cout << ans;

}


// Faster C++ solution for the same problem (measured speedup: 5.144632320978577x):
#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;

}
// Slower C++ solution:
#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;

}

// Faster C++ solution for the same problem (measured speedup: 5.176581116887984x):
#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;

}
// Slower C++ solution:
#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; 

} 

// Faster C++ solution for the same problem (measured speedup: 5.139743222542631x):
#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;

}
// 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.1161245228543113x):
#include <bits/stdc++.h>

#define ls (o << 1)

#define rs (o << 1 | 1)

#define mid ((L + R) >> 1)

using namespace std;

typedef long long LL;

const int N = 200500;

const int mod = 998244353;

bool is[N];

int x[N], y[N], h[N], n;

bool cmp(const int &o, const int &p) { return x[o] < x[p]; }

bool cmp1(const int &o, const int &p) { return y[o] < y[p]; }

int main() {

#ifdef TEST

	freopen("input.txt", "r", stdin);

#endif

	scanf("%d", &n);

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

		scanf("%d%d", &x[i], &y[i]);

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

		h[i] = i;

	}

	sort(h, h + n, cmp1);

	int mx = h[n - 1];

	LL ans = y[h[n - 1]] - y[h[0]];

	sort(h, h + n, cmp);

	int mn = h[0];

	ans *= x[h[n - 1]] - x[h[0]];

	if (mn == mx) {

		cout << ans << endl;

		return 0;

	}

	multiset<int> s;

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

		if (i == mn) {

			s.insert(y[i]);

		} else {

			s.insert(x[i]);

		}

	}

	LL con = y[mx] - x[mn];

	int ans2 = *s.rbegin() - *s.begin();

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

		if (h[i] == mx) continue;

		s.erase(s.find(x[h[i]]));

		s.insert(y[h[i]]);

		ans2 = min(ans2, *s.rbegin() - *s.begin());

	}

	cout << min(ans, con * ans2) << endl;

	return 0;

}