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++14 (GCC 5.4.1) (judge verdict: Wrong Answer)

// AtCoder Regular Contest 073
// E - Ball Coloring

#include <cstdio>
#include <cstring>
#include <algorithm>
#define MAX_N 200000
#define INF ((ll)1e10)
using namespace std;
typedef long long int ll;
typedef pair<ll, int> PLI;


int N;
PLI xy[MAX_N * 2];
ll ans;

bool can(ll d) {
  int cnt;
  int used[MAX_N];
  int i, j;

  cnt = 0;
  memset(used, 0, sizeof(0));
  i = 0;
  j = 0;
  for (; i < 2 * N; i++) {
    for (; (j < 2 * N) && (xy[j].first - xy[i].first <= d); j++) {
      if (used[xy[j].second] == 0) {
        cnt++;
        if (cnt == N) {
          // printf("can %2lld true\n", d);
          return true;
        }
      }
      used[xy[j].second]++;
    }
    used[xy[i].second]--;
    if (used[xy[i].second] == 0) {
      cnt--;
    }
  }
  // printf("can %2lld false\n", d);
  return false;
}

int main() {

  ll cnt_s_s, cnt_l_l;
  ll s_s, s_l, l_s, l_l, s_p, l_p;
  ll min_x, max_x;
  ll l, m, r;

  scanf("%d", &N);
  cnt_s_s = cnt_l_l = 0;
  s_s = s_l = INF;
  l_s = l_l = 0;
  for (int i = 0; i < N; i++) {
    scanf("%lld%lld", &xy[2 * i].first, &xy[2 * i + 1].first);
    xy[2 * i].second = i;
    xy[2 * i + 1].second = i;
    min_x = min(xy[2 * i].first, xy[2 * i + 1].first);
    max_x = max(xy[2 * i].first, xy[2 * i + 1].first);
    s_l = min(s_l, max_x);
    l_s = max(l_s, min_x);
    if (s_s >= min_x) {
      if (s_s == min_x) {
        cnt_s_s++;
      } else {
        cnt_s_s = 1;
      }
      s_s = min_x;
    }
    if (l_l <= max_x) {
      if (l_l == max_x) {
        cnt_l_l++;
      } else {
        cnt_l_l = 1;
      }
      l_l = max_x;
    }
  }
  sort(xy, xy + 2 * N);
  s_s = xy[0].first;
  l_l = xy[2 * N - 1].first;
  // printf("%lld, %lld, %lld, %lld\n", s_s, s_l, l_s, l_l);

  ans = (l_s - s_s) * (l_l - s_l);

  // printf("%lld\n", ans);

  // if (xy[0].second != xy[2 * N - 1].second || cnt_s_s * cnt_l_l > 1) {
    r = ans / (l_l - s_s);
    l = -1;
    while (r - l > 1) {
      m = (r + l + 1) / 2;
      if (can(m)) {
        r = m;
      } else {
        l = m;
      }
    }
    m = (r + l + 1) / 2;
    ans = min(ans, (l_l - s_s) * m);
  // }

  printf("%lld\n", ans);

  return 0;

}