Problem:
Score : 700 points

Problem Statement

There are N bags, each containing two white balls. The i-th box contains two balls with integers x_i and y_i written on them, respectively.

For each of these bags, you will paint one of the balls red, and paint the other blue.

Afterwards, the 2N balls will be classified according to color.

Then, we will define the following:

R_{max}: the maximum integer written on a ball painted in red

R_{min}: the minimum integer written on a ball painted in red

B_{max}: the maximum integer written on a ball painted in blue

B_{min}: the minimum integer written on a ball painted in blue

Find the minimum possible value of (R_{max} - R_{min}) \times (B_{max} - B_{min}).

Constraints

1 ≤ N ≤ 200,000

1 ≤ x_i, y_i ≤ 10^9

Input

Input is given from Standard Input in the following format:

N
x_1 y_1
x_2 y_2
:
x_N y_N

Output

Print the minimum possible value.

Sample Input 1

3
1 2
3 4
5 6

Sample Output 1

15

The optimal solution is to paint the balls with x_1, x_2, y_3 red, and paint the balls with y_1, y_2, x_3 blue.

Sample Input 2

3
1010 10
1000 1
20 1020

Sample Output 2

380

Sample Input 3

2
1 1
1000000000 1000000000

Sample Output 3

999999998000000001

Solution in C++14 (GCC 5.4.1) (judge verdict: Wrong Answer)

#include <cstdio>
#include <cstring>
#include <algorithm>
#include <map>
#include <set>
#include <iostream>
#define maxn 3009
using namespace std;
typedef  long long ll;
#define N 200005
#define fr(i,x,y) for(int i=x;i<=y;i++)
int n,a[N],b[N];
void doit(){
    scanf("%d",&n);
    if (n==1){
        puts("0");
        return;
    }
    int ma=-1,tt,ss,mi;
    fr(i,1,n){
        scanf("%d%d",&a[i],&b[i]);
        ma=max(ma,b[i]);
        ma=max(ma,a[i]);
        if(a[i]==ma) tt=i;
        if(b[i]==ma) tt=i;
    }
    mi=ma+1;
    fr(i,1,n)if (i!=tt){
            mi=min(mi,b[i]);
            mi=min(mi,a[i]);
            if(a[i]==mi) ss=i;
            if(b[i]==mi) ss=i;
        }
    int x,y;
    x=a[ss]+b[ss]-mi;
    y=a[tt]+b[tt]-ma;
    int t1,t2;
    fr(i,1,n)if (i!=ss&&i!=tt){
            t1=max(a[i],b[i]);
            t2=min(a[i],b[i]);
            if (t2>y) y=t2;
            if (t1<x) x=t1;
        }


    ll ans1=1LL*abs((ma-x))*abs((y-mi));
    x=a[ss]+b[ss]-mi;
    y=a[tt]+b[tt]-ma;
    if (x>y) swap(x,y);
    fr(i,1,n)if (i!=ss&&i!=tt){
            if (a[i]<x&&b[i]<x) x=max(a[i],b[i]);
            if (a[i]>y&&b[i]>y) y=min(a[i],b[i]);
        }
    ll ans2=1LL*(ma-mi)*(y-x);

    printf("%lld\n",ans1>ans2?ans2:ans1);
}

int main(){
  //  while (1)
    doit();
    return 0;
}
/*
 2
 100 18
 20 40
 */