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 C# (Mono 4.6.2.0) (judge verdict: Wrong Answer)

using System;
using System.Collections.Generic;
using System.Linq;
using System.IO;
using System.Globalization;
using System.Diagnostics;
using static System.Console;
using Pair = System.Collections.Generic.KeyValuePair<int, int>;

class Program
{
    static void Main()
    {
        //SetOut(new StreamWriter(OpenStandardOutput()) { AutoFlush = false });
        new Program().Solve();
        Out.Flush();
    }
    Scanner cin = new Scanner();
    Random rnd = new Random();
    Stopwatch sw = new Stopwatch();
    readonly int[] dd = { 0, 1, 0, -1, 0 };
    readonly int mod = 1000000007;
    readonly string alfa = "abcdefghijklmnopqrstuvwxyz";

    int N;

    void Solve()
    {
        N = cin.Nextint;
        var X = new int[N];
        var Y = new int[N];


        var R = new int[N];
        var B = new int[N];

        var W = new Pair[N];
        var J = new SortedSet<int>();
        for (int i = 0; i < N; i++)
        {
            X[i] = cin.Nextint;
            Y[i] = cin.Nextint;
            R[i] = Math.Min(X[i], Y[i]);
            B[i] = Math.Max(X[i], Y[i]);
            W[i] = new Pair(R[i], B[i]);
            J.Add(R[i]);
        }

        Array.Sort(R);Array.Sort(B);

        long ans = (long)(R[N - 1] - R[0]) * (B[N - 1] - B[0]);
       // WriteLine(ans);

     
        W = W.OrderBy(i => i.Key).ThenBy(i => i.Value).ToArray();
        int min = W[0].Key;
        int max = W[N - 1].Key;
        int diff = max - min;
        // WriteLine(diff);

        for (int i = 0; i < N; i++)
        {
            if (J.First() < W[i].Key) break;
            J.Remove(W[i].Key);
            J.Add(W[i].Value);
            diff = Math.Min(J.Last() - J.First(), diff);
        
        }

        long d = Math.Max(R[N - 1], B[N - 1]) - Math.Min(R[0], B[0]);

        ans = Math.Min(ans, d * diff);
        WriteLine(ans);

    }

}

class Scanner
{
    string[] s; int i;
    char[] cs = new char[] { ' ' };
    public Scanner() { s = new string[0]; i = 0; }
    public string[] Scan { get { return ReadLine().Split(); } }
    public int[] Scanint { get { return Array.ConvertAll(Scan, int.Parse); } }
    public long[] Scanlong { get { return Array.ConvertAll(Scan, long.Parse); } }
    public double[] Scandouble { get { return Array.ConvertAll(Scan, double.Parse); } }
    public string Next
    {
        get
        {
            if (i < s.Length) return s[i++];
            string st = ReadLine();
            while (st == "") st = ReadLine();
            s = st.Split(cs, StringSplitOptions.RemoveEmptyEntries);
            i = 0;
            return Next;
        }
    }
    public int Nextint { get { return int.Parse(Next); } }
    public long Nextlong { get { return long.Parse(Next); } }
    public double Nextdouble { get { return double.Parse(Next); } }
}