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 Java8 (OpenJDK 1.8.0) (judge verdict: Time Limit Exceeded)

import java.util.*;

public class Main {
	
	/*
	 * default function
	 * */	
	int n_int() {
		return cin.nextInt();
	}
	
	long n_long() {
		return cin.nextLong();
	}
	
	String n_line() {
		return cin.nextLine();
	}
	
	void println(String str) {	
		System.out.println(str);
	}
	
	void print(String str) {
		System.out.print(str);
	}
	
	/*
	 * default variable
	 */
	
	static final int MOD = 1000000007;
	
	Scanner cin = new Scanner(System.in);	
	String  output;
	
	public static void main(String[] args) {			
		new Main().run();						
	}
	/* default above */
		
	public void run() {
			
		input();
		/* 
		 * start
		 */	
		
		dfs(0);
		
		/*
		 * finish
		 */
		
		output = res+"";
		println(output);
			
	}
	/* 
	 * define variable
	 */
	
	int N;
	long[] x;
	long[] y;
	long res;
	
	long[] red;
	long[] blue;
	
	void input() {
		
		res = Long.MAX_VALUE;
		
		N = n_int();
		x = new long[N];
		y = new long[N];
		
		
		red  = new long[N];
		blue = new long[N];
		
		for (int i = 0; i < N; i ++) {
			x[i] = n_long();
			y[i] = n_long();
		}
	}
	
	void dfs(int index) {
		
		if (index == N) {
			long R_MAX = Long.MIN_VALUE;
			long R_MIN = Long.MAX_VALUE;
			
			long B_MAX = Long.MIN_VALUE;
			long B_MIN = Long.MAX_VALUE;
			
			for (int i = 0; i < N; i ++) {
				R_MAX = Math.max(R_MAX, red[i]);
				R_MIN = Math.min(R_MIN, red[i]);	
				
				B_MAX = Math.max(B_MAX, blue[i]);
				B_MIN = Math.min(B_MIN, blue[i]);	
			}
			
			res = Math.min(res, (R_MAX - R_MIN)*(B_MAX - B_MIN));	
			return ;
		}
		
		
		red[index] = x[index];
		blue[index]= y[index];
		dfs(index + 1);
		
		red[index] = y[index];
		blue[index]= x[index];
		dfs(index + 1);										
	}
	
}