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: Accepted)

//https://qiita.com/tanakh/items/0ba42c7ca36cd29d0ac8
macro_rules! input {
    (source = $s:expr, $($r:tt)*) => {
        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)*}
    };
}

macro_rules! input_inner {
    ($iter:expr) => {};
    ($iter:expr, ) => {};
    ($iter:expr, $var:ident : $t:tt $($r:tt)*) => {
        let $var = read_value!($iter, $t);
        input_inner!{$iter $($r)*}
    };
}

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) => {
        read_value!($iter, String).chars().collect::<Vec<char>>()
    };
    ($iter:expr, usize1) => {
        read_value!($iter, usize) - 1
    };
    ($iter:expr, $t:ty) => {
        $iter.next().unwrap().parse::<$t>().expect("Parse error")
    };
}

//

fn run() {
    input! {
        n: usize,
        p: [(i64, i64); n],
    }
    let mut p = p;
    for p in &mut p {
        if p.0 > p.1 {
            std::mem::swap(&mut p.0, &mut p.1);
        }
    }
    p.sort();
    let mut max = 0;
    for i in 1..n {
        if p[i].1 >= p[max].1 {
            max = i;
        }
    }
    let mut r = [p[0].0, p[max].0];
    let mut b = [p[0].1, p[max].1];
    for i in 1..n {
        r[1] = std::cmp::max(r[1], p[i].0);
        b[0] = std::cmp::min(b[0], p[i].1);
    }
    let mut ans = (r[1] - r[0]) * (b[1] - b[0]);
    if max != 0 {
        let mut bmax = std::cmp::max(p[max].0, p[0].1);
        let bmin = std::cmp::min(p[max].0, p[0].1);
        let mut local = bmin;
        let mut h = std::collections::BinaryHeap::new();
        for i in 1..n {
            if i == max {
                continue;
            }
            h.push((-p[i].0, i));
            bmax = std::cmp::max(bmax, p[i].0);
            local = std::cmp::min(local, p[i].0);
        }
        ans = std::cmp::min(ans, (p[max].1 - p[0].0) * (bmax - local));
        while let Some((v, k)) = h.pop() {
            if k == n {
                ans = std::cmp::min(ans, (p[max].1 - p[0].0) * (bmax - std::cmp::min(bmin, -v)));
                break;
            }
            bmax = std::cmp::max(bmax, p[k].1);
            h.push((-p[k].1, n));
            if let Some(&(u, _)) = h.peek() {
                ans = std::cmp::min(ans, (p[max].1 - p[0].0) * (bmax - std::cmp::min(bmin, -u)));
            }
        }
    }
    println!("{}", ans);
}

fn main() {
    run();
}