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)

/// Thank you tanakh!!!
/// 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 mut 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")
    };
}

use std::cmp;

const INF: usize = 1e15 as usize;

fn solve1(xy: &Vec<(usize, usize)>) -> usize {
    let max = xy.iter().map(|&(x, y)| cmp::max(x, y)).max().unwrap();
    let min = xy.iter().map(|&(x, y)| cmp::min(x, y)).min().unwrap();
    let max_minimum = xy.iter().map(|&(x, y)| cmp::min(x, y)).max().unwrap();
    let min_maximum = xy.iter().map(|&(x, y)| cmp::max(x, y)).min().unwrap();
    (max - min_maximum) * (max_minimum - min)
}

fn solve2(xy: &Vec<(usize, usize)>) -> usize {
    let n = xy.len();
    let mut pairs = vec![];
    for &(x, y) in xy.iter() {
        pairs.push((cmp::min(x, y), cmp::max(x, y)));
    }
    pairs.sort();

    let (whole_minimum, _) = pairs[0];
    let whole_maximum = pairs.iter().map(|&(_, b)| b).max().unwrap();
    let (mut cur_max, _) = pairs[n - 1];
    let mut right_min = INF;

    let mut ans = (cur_max - pairs[0].0) * (whole_maximum - whole_minimum);
    for i in 0..(n - 1) {
        let (_, cur_right) = pairs[i];
        let (next_left, _) = pairs[i + 1];
        right_min = cmp::min(right_min, cur_right);
        let cur_min = cmp::min(right_min, next_left);
        cur_max = cmp::max(cur_max, cur_right);
        ans = cmp::min(ans, (whole_maximum - whole_minimum) * (cur_max - cur_min));
    }
    ans
}

fn main() {
    input!(n: usize, xy: [(usize, usize); n]);
    println!("{}", cmp::min(solve1(&xy), solve2(&xy)));
}