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 JavaScript (Node.js 12.16.1) (judge verdict: Accepted)

"use strict";
var input=require("fs").readFileSync("/dev/stdin","utf8");
var cin=input.split(/ |\n/),cid=0;
function next(){return +cin[cid++];}
function nextstr(){return cin[cid++];}
function nextbig(){return BigInt(cin[cid++]);}
function nexts(n,a){return a?cin.slice(cid,cid+=n):cin.slice(cid,cid+=n).map(a=>+a);}
function nextm(h,w,a){var r=[],i=0;if(a)for(;i<h;i++)r.push(cin.slice(cid,cid+=w));else for(;i<h;i++)r.push(cin.slice(cid,cid+=w).map(a=>+a));return r;}
function xArray(v){var a=arguments,l=a.length,r="Array(a["+--l+"]).fill().map(x=>{return "+v+";})";while(--l)r="Array(a["+l+"]).fill().map(x=>"+r+")";return eval(r);}

var myOut = main();
if(myOut !== undefined)console.log(String(myOut));

function main(){
  var n = next();
  var x = [];
  for(var i = 0; i < n; i++){
    var u = next(), v = next();
    if(v < u){var temp = u; u = v; v = temp;}
    x.push([u,v]);
  }
  x.sort((a,b)=>b[0]>a[0]?1:b[0]<a[0]?-1:a[1]-b[1]);
  var rx = 0, rn = x[n-1][0], bx = 0, bn = 1e9;
  for(var i = 0; i < n; i++){
    if(rx < x[i][0])rx = x[i][0];
    if(bx < x[i][1])bx = x[i][1];
    if(bn > x[i][1])bn = x[i][1];
  }
  var ans = solve(rx,rn,bx,bn);
  var r = x[0][0];
  var [aa,b] = x.pop();
  x.sort((a,b)=>a[1]-b[1]);
  while(x.length){
    var [u,v] = x.pop();
    if(b >= v)break;
    rx = Math.max(rx,v);
    bn = Math.min(bn,u);
    if(x.length)bx = Math.max(b,x[x.length-1][1],r);
    var t = solve(rx,rn,bx,bn);
    if(ans > t)ans = t;
  }
  return ans;
}
function solve(a,b,c,d){
  return BigInt(a-b) * BigInt(c-d);
}