You have N bags, each containing two white balls with integers written on them. You need to paint one ball in each bag red and the other blue. After painting, the 2N balls will be classified by color. Find the minimum possible value of (R_max - R_min) * (B_max - B_min), where R_max and R_min are the maximum and minimum integers written on red balls, and B_max and B_min are the maximum and minimum integers written on blue balls. Constraints: 1 ≤ N ≤ 200,000, 1 ≤ xi, yi ≤ 10^9. Input is given as N followed by pairs of xi and yi. Output the minimum possible value.

# Buggy version:
import sys
input = sys.stdin.readline
N=int(input())
A=[]
C=[]
D=[]
for i in range(N):
    a,b=map(int,input().split())
    c,d=min(a,b),max(a,b)
    A.append((c,d))
    C.append(c)
    D.append(d)
#print(A,C,D,si,ti)
if N==1:
    print(0)
    sys.exit()
ans=(max(C)-min(C))*(max(D)-min(D))
cur=min(D)
ma=min(D)
T=10**19
for a,b in A:
    if a>ma:
        T=min(best,cur-ma)
        break
    T=min(T,cur-a)
    cur=max(cur,b)

print(min(ans,(max(D)-min(C))*T))

# Fixed version:
import sys
input = sys.stdin.readline
N=int(input())
A=[]
C=[]
D=[]
for i in range(N):
    a,b=map(int,input().split())
    c,d=min(a,b),max(a,b)
    A.append((c,d))
    C.append(c)
    D.append(d)
A.sort()
#print(A,C,D,si,ti)
if N==1:
    print(0)
    sys.exit()
ans=(max(C)-min(C))*(max(D)-min(D))
cur=max(C)
ma=min(D)
T=10**19
for a,b in A:
    if a>ma:
        T=min(T,cur-ma)
        break
    T=min(T,cur-a)
    cur=max(cur,b)
print(min(ans,(max(D)-min(C))*T))

# Buggy version:
N = int(input())
balls = sorted(tuple(sorted(map(int,input().split()))) for i in range(N))

# Rmin=MIN, Bmax=MAX
maxmin = balls[-1][0]
minmin = balls[0][0]
maxmax = max(b[1] for b in balls)
minmax = min(b[1] for b in balls)

v1 = (maxmin-minmin)*(maxmax-minmax)

# Rmin=MIN, Rmax=MAX
best = float('inf')
cur_max = maxmin
for b in balls:
  if b[0] > minmax:
    break
  best = min(best, cur_max-b[0])
  cur_max = max(cur_max, b[1])

v2 = (maxmax-minmin)*best

print(min(v1,v2))

# Fixed version:
N = int(input())
balls = sorted(tuple(sorted(map(int,input().split()))) for i in range(N))

# Rmin=MIN, Bmax=MAX
maxmin = balls[-1][0]
minmin = balls[0][0]
maxmax = max(b[1] for b in balls)
minmax = min(b[1] for b in balls)

v1 = (maxmin-minmin)*(maxmax-minmax)

# Rmin=MIN, Rmax=MAX
best = float('inf')
cur_max = maxmin
for b in balls:
  if b[0] > minmax:
    best = min(best, cur_max-minmax)
    break
  best = min(best, cur_max-b[0])
  cur_max = max(cur_max, b[1])
 
v2 = (maxmax-minmin)*best

print(min(v1,v2))

# Buggy version:
# coding: utf-8
# 整数の入力
#a = int(raw_input())
# スペース区切りの整数の入力
import heapq
N = int(input())

Rmax = 0
Rmin = 1000000001
Bmax = 0
Bmin = 1000000001

data = sorted([sorted(list(map(int, input().split()))) for i in range(N)],key=lambda x:x[0])

tempBlues = sorted([d[1] for d in data])
tempReds = [d[0] for d in data]
heapq.heapify(tempReds)
print(tempReds)

Rmin = data[0][0]
Rmax = data[N-1][0]
Bmax = max(tempBlues)
Bmin = min(tempBlues)

minValue = (Rmax - Rmin)*(Bmax - Bmin)
Bmin = Rmin

for i in range(N):
    heapMin = heapq.heappop(tempReds)
    if heapMin == data[i][0]:
        heapq.heappush(tempReds, data[i][1])
        if  data[i][1] > Rmax:
            Rmax = data[i][1]
        if (Rmax - tempReds[0])*(Bmax - Bmin) < minValue:
            minValue = (Rmax - tempReds[0])*(Bmax - Bmin)
    else:
        break

print(minValue)

# Fixed version:
# coding: utf-8
# 整数の入力
#a = int(raw_input())
# スペース区切りの整数の入力
import heapq
N = int(input())

Rmax = 0
Rmin = 1000000001
Bmax = 0
Bmin = 1000000001

data = sorted([sorted(list(map(int, input().split()))) for i in range(N)],key=lambda x:x[0])

tempBlues = sorted([d[1] for d in data])
tempReds = [d[0] for d in data]
heapq.heapify(tempReds)

Rmin = data[0][0]
Rmax = data[N-1][0]
Bmax = max(tempBlues)
Bmin = min(tempBlues)

minValue = (Rmax - Rmin)*(Bmax - Bmin)
Bmin = Rmin

for i in range(N):
    heapMin = heapq.heappop(tempReds)
    if heapMin == data[i][0]:
        heapq.heappush(tempReds, data[i][1])
        if  data[i][1] > Rmax:
            Rmax = data[i][1]
        if (Rmax - tempReds[0])*(Bmax - Bmin) < minValue:
            minValue = (Rmax - tempReds[0])*(Bmax - Bmin)
    else:
        break

print(minValue)