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 Rust (1.15.1) (judge verdict: Wrong Answer)

macro_rules !read_value {($iter :expr ,($($t :tt ) ,*) ) =>{($(read_value !($iter ,$t ) ) ,*) } ;($iter :expr ,[$t :tt ;$len :expr ] ) =>{(0 ..$len ) .map (|_ |read_value !($iter ,$t ) ) .collect ::<Vec <_ >>() } ;($iter :expr ,{chars :$base :expr } ) =>{read_value !($iter ,String ) .chars () .map (|c |(c as u8 -$base as u8 ) as usize ) .collect ::<Vec <usize >>() } ;($iter :expr ,{char :$base :expr } ) =>{read_value !($iter ,{chars :$base } ) [0 ] } ;($iter :expr ,chars ) =>{read_value !($iter ,String ) .chars () .collect ::<Vec <char >>() } ;($iter :expr ,char ) =>{read_value !($iter ,chars ) [0 ] } ;($iter :expr ,usize1 ) =>{read_value !($iter ,usize ) -1 } ;($iter :expr ,$t :ty ) =>{$iter .next () .unwrap () .parse ::<$t >() .unwrap () } ;}
macro_rules !input_inner {($iter :expr ) =>{} ;($iter :expr ,) =>{} ;($iter :expr ,mut $var :ident :$t :tt $($r :tt ) *) =>{let mut $var =read_value !($iter ,$t ) ;input_inner !{$iter $($r ) *} } ;($iter :expr ,mut $var :ident $($r :tt ) *) =>{input_inner !{$iter ,mut $var :usize $($r ) *} } ;($iter :expr ,$var :ident :$t :tt $($r :tt ) *) =>{let $var =read_value !($iter ,$t ) ;input_inner !{$iter $($r ) *} } ;($iter :expr ,$var :ident $($r :tt ) *) =>{input_inner !{$iter ,$var :usize $($r ) *} } ;}
macro_rules !input {(source =$s :expr ,$($r :tt ) *) =>{let mut iter =$s .split_whitespace () ;input_inner !{iter ,$($r ) *} } ;(iter =$iter :ident ,$($r :tt ) *) =>{let s ={use std ::io ::Read ;let mut s =String ::new () ;std ::io ::stdin () .read_to_string (&mut s ) .unwrap () ;s } ;let mut $iter =s .split_whitespace () ;input_inner !{$iter ,$($r ) *} } ;($($r :tt ) *) =>{let s ={use std ::io ::Read ;let mut s =String ::new () ;std ::io ::stdin () .read_to_string (&mut s ) .unwrap () ;s } ;let mut iter =s .split_whitespace () ;input_inner !{iter ,$($r ) *} } ;}
use std::cmp::{max, min};
fn main() {
    input! { n, xy: [(i64, i64); n] };
    let mut ans = 0i64;
    let ab = xy
        .iter()
        .map(|&(x, y)| (min(x, y), max(x, y)))
        .collect::<Vec<_>>();
    if n > 1 {
        ans = std::i64::MAX;
        let (mut mx, mut mn) = ((0, 0), (1_000_000_001, n));
        for i in 0..n {
            mx = max(mx, (ab[i].1, i));
            mn = min(mn, (ab[i].0, i));
        }
        if mx.1 != mn.1 {
            let seg = (min(ab[mx.1].0, ab[mn.1].1), max(ab[mx.1].0, ab[mn.1].1));
            let mut idx = (0..n)
                .filter(|&i| i != mx.1 && i != mn.1)
                .collect::<Vec<_>>();
            idx.sort_by_key(|&i| ab[i].0);
            ans = min(ans, (seg.1 - seg.0) * (mx.0 - mn.0));
            if idx.len() > 0 {
                let mut ma = idx.iter().map(|&i| ab[i].0).max().unwrap();
                let mut mi = idx.iter().map(|&i| ab[i].0).min().unwrap();
                ma = max(ma, seg.1);
                mi = min(mi, seg.0);
                ans = min(ans, (ma - mi) * (mx.0 - mn.0));
                mi = 1_000_000_001;
                for &i in idx.iter() {
                    ma = max(ma, ab[i].1);
                    mi = min(mi, ab[i].1);
                    ma = max(ma, seg.1);
                    mi = min(mi, seg.0);
                    ans = min(ans, (ma - min(ab[i].0, mi)) * (mx.0 - mn.0));
                }
            }
        }
        let mut seg = (ab[mx.1].0, ab[mn.1].1);
        for i in 0..n {
            seg.0 = max(seg.0, ab[i].0);
            seg.1 = min(seg.1, ab[i].1);
        }
        ans = min(ans, (mx.0 - seg.1) * (seg.0 - mn.0));
    }
    println!("{}", ans);
}