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



Sample input:
3
1 2
3 4
5 6


Sample output:
15

Submission status: Wrong Answer

Solution code:
n = int(input())
lis = []
li = []
MAX = []
MIN = []
ans = []
for i in range(n):
  a,b = map(int,input().split())
  MAX.append(max(a,b))
  MIN.append(min(a,b))

ans.append((max(MAX)-min(MAX)) * (max(MIN)-min(MIN)))

  # print(MAX,MIN)

lis.append(MAX[MAX.index(max(MAX))])
li.append(MIN[MAX.index(max(MAX))])
lis.append(MIN[MIN.index(min(MIN))])
li.append(MAX[MIN.index(min(MIN))])

del MIN[MAX.index(max(MAX))]
del MAX[MAX.index(max(MAX))]
del MAX[MIN.index(min(MIN))]
del MIN[MIN.index(min(MIN))]

  # print(MAX,MIN)

  # print("lis li",lis,li,MAX,MIN)

for i in range(len(MAX)):
  if min(li) <= MAX[i] and MAX[i] <= max(li):
    continue
  elif min(li) <= MIN[i] and MIN[i] <= max(li):
    continue
  elif max(li) < MIN[i]:
    li[li.index(max(li))] = MIN[i]
  elif MAX[i] < min(li):
    li[li.index(min(li))] = MAX[i]
  elif MAX[i]-max(li) < min(li) -MIN[i]:
    li[li.index(max(li))] = MAX[i]
  elif MAX[i]-max(li) > min(li)-MIN[i]:
    li[li.index(min(li))] = MIN[i]
  else:
    continue

  # print(lis,li)
ans.append((max(lis)-min(lis)) * (max(li)-min(li)))

print(min(ans))

Submission status: Wrong Answer

Solution code:
n = int(input())
lis = []
li = []
MAX = []
MIN = []
ans = []
for i in range(n):
  a,b = map(int,input().split())
  MAX.append(max(a,b))
  MIN.append(min(a,b))

ans.append((max(MAX)-min(MAX)) * (max(MIN)-min(MIN)))

  # print(MAX,MIN)

lis.append(MAX[MAX.index(max(MAX))])
li.append(MIN[MAX.index(max(MAX))])
lis.append(MIN[MIN.index(min(MIN))])
li.append(MAX[MIN.index(min(MIN))])

del MIN[MAX.index(max(MAX))]
del MAX[MAX.index(max(MAX))]
del MAX[MIN.index(min(MIN))]
del MIN[MIN.index(min(MIN))]

  # print(MAX,MIN)

  # print("lis li",lis,li,MAX,MIN)

for i in range(len(MAX)):
  if min(li) <= MAX[i] and MAX[i] <= max(li):
    continue
  elif min(li) <= MIN[i] and MIN[i] <= max(li):
    continue
  elif max(li) < MIN[i]:
    li[li.index(max(li))] = MIN[i]
  elif MAX[i] < min(li):
    li[li.index(min(li))] = MAX[i]
  elif MAX[i]-max(li) <= min(li) -MIN[i]:
    li[li.index(max(li))] = MAX[i]
  else:
    li[li.index(min(li))] = MIN[i]

  # print(lis,li)
ans.append((max(lis)-min(lis)) * (max(li)-min(li)))

print(min(ans))

Submission status: Wrong Answer

Solution code:
n = int(input())
lis = []
li = []
MAX = []
MIN = []
ans = []
for i in range(n):
  a,b = map(int,input().split())
  MAX.append(max(a,b))
  MIN.append(min(a,b))

ans.append((max(MAX)-min(MAX)) * (max(MIN)-min(MIN)))

  # print(MAX,MIN)

lis.append(MAX[MAX.index(max(MAX))])
li.append(MIN[MAX.index(max(MAX))])
lis.append(MIN[MIN.index(min(MIN))])
li.append(MAX[MIN.index(min(MIN))])

del MIN[MAX.index(max(MAX))]
del MAX[MAX.index(max(MAX))]
del MAX[MIN.index(min(MIN))]
del MIN[MIN.index(min(MIN))]

  # print(MAX,MIN)

  # print("lis li",lis,li,MAX,MIN)

for i in range(len(MAX)):
  if min(li) <= MAX[i] and MAX[i] <= max(li):
    continue
  elif min(li) <= MIN[i] and MIN[i] <= max(li):
    continue
  elif max(li) < MIN[i]:
    li[li.index(max(li))] = MIN[i]
  elif MAX[i] < min(li):
    li[li.index(min(li))] = MAX[i]
  elif MAX[i]-max(li) < min(li) -MIN[i]:
    li[li.index(max(li))] = MAX[i]
  else:
    li[li.index(min(li))] = MIN[i]

  # print(lis,li)
ans.append((max(lis)-min(lis)) * (max(li)-min(li)))

print(min(ans))

Submission status: Wrong Answer

Solution code:
n = int(input())
lis = []
li = []
MAX = []
MIN = []
ans = []
for i in range(n):
  a,b = map(int,input().split())
  MAX.append(max(a,b))
  MIN.append(min(a,b))

ans.append((max(MAX)-min(MAX)) * (max(MIN)-min(MIN)))

  # print(MAX,MIN)

lis.append(MAX[MAX.index(max(MAX))])
li.append(MIN[MAX.index(max(MAX))])
lis.append(MIN[MIN.index(min(MIN))])
li.append(MAX[MIN.index(min(MIN))])

del MIN[MAX.index(max(MAX))]
del MAX[MAX.index(max(MAX))]
del MAX[MIN.index(min(MIN))]
del MIN[MIN.index(min(MIN))]

  # print(MAX,MIN)

  # print("lis li",lis,li,MAX,MIN)

for i in range(len(MAX)):
  if min(li) <= MAX[i] and MAX[i] <= max(li):
    continue
  elif min(li) <= MIN[i] and MIN[i] <= max(li):
    continue
  elif MAX[i]-max(li) <= min(li)-MIN[i]:
    li[li.index(max(li))] = MIN[i]
  else:
    li[li.index(min(li))] = MAX[i]

  # print(lis,li)
ans.append((max(lis)-min(lis)) * (max(li)-min(li)))

print(min(ans))
  #360

Submission status: Wrong Answer

Solution code:
n = int(input())
lis = []
li = []
MAX = []
MIN = []
ans = []
for i in range(n):
  a,b = map(int,input().split())
  MAX.append(max(a,b))
  MIN.append(min(a,b))

ans.append((max(MAX)-min(MAX)) * (max(MIN)-min(MIN)))

  # print(MAX,MIN)

lis.append(MAX[MAX.index(max(MAX))])
li.append(MIN[MAX.index(max(MAX))])
lis.append(MIN[MIN.index(min(MIN))])
li.append(MAX[MIN.index(min(MIN))])

del MIN[MAX.index(max(MAX))]
del MAX[MAX.index(max(MAX))]
del MAX[MIN.index(min(MIN))]
del MIN[MIN.index(min(MIN))]

  # print(MAX,MIN)

  # print("lis li",lis,li,MAX,MIN)

for i in range(len(MAX)):
  if min(li) <= MAX[i] and MAX[i] <= max(li):
    continue
  elif min(li) <= MIN[i] and MIN[i] <= max(li):
    continue
  elif MAX[i]-max(li) < min(li)-MIN[i]:
    li[li.index(max(li))] = MIN[i]
  else:
    li[li.index(min(li))] = MAX[i]

  # print(lis,li)
ans.append((max(lis)-min(lis)) * (max(li)-min(li)))

print(min(ans))
  #360

Submission status: Wrong Answer

Solution code:
n = int(input())
lis = []
li = []
MAX = []
MIN = []
ans = []
for i in range(n):
  a,b = map(int,input().split())
  MAX.append(max(a,b))
  MIN.append(min(a,b))

ans.append((max(MAX)-min(MAX)) * (max(MIN)-min(MIN)))

  # print(MAX,MIN)

lis.append(MAX[MAX.index(max(MAX))])
li.append(MIN[MAX.index(max(MAX))])
lis.append(MIN[MIN.index(min(MIN))])
li.append(MAX[MIN.index(min(MIN))])

del MIN[MAX.index(max(MAX))]
del MAX[MAX.index(max(MAX))]
del MAX[MIN.index(min(MIN))]
del MIN[MIN.index(min(MIN))]

  # print(MAX,MIN)

  # print("lis li",lis,li,MAX,MIN)

for i in range(len(MAX)):
  if min(li) <= MAX[i] and MAX[i] <= max(li):
    continue
  elif min(li) <= MIN[i] and MIN[i] <= max(li):
    continue
  elif MAX[i]-max(li) < min(li)-MIN[i]:
    li[li.index(max(li))] = MIN[i]
  else:
    li[li.index(min(li))] = MAX[i]

  # print(lis,li)
ans.append((max(lis)-min(lis)) * (max(li)-min(li)))

print(min(ans),ans)
  #360

Submission status: Wrong Answer

Solution code:
n = int(input())
lis = []
li = []
MAX = []
MIN = []
ans = []
for i in range(n):
  a,b = map(int,input().split())
  MAX.append(max(a,b))
  MIN.append(min(a,b))

ans.append((max(MAX)-min(MAX)) * (max(MIN)-min(MIN)))

  # print(MAX,MIN)

lis.append(MAX[MAX.index(max(MAX))])
li.append(MIN[MAX.index(max(MAX))])
lis.append(MIN[MIN.index(min(MIN))])
li.append(MAX[MIN.index(min(MIN))])

del MIN[MAX.index(max(MAX))]
del MAX[MAX.index(max(MAX))]
del MAX[MIN.index(min(MIN))]
del MIN[MIN.index(min(MIN))]

  # print(MAX,MIN)

  # print("lis li",lis,li)

for i in range(len(MAX)):
  if min(li) <= MAX[i] and MAX[i] <= max(li):
    continue
  elif min(li) <= MIN[i] and MIN[i] <= max(li):
    continue
  elif min(li)-MAX[i] <= MIN[i]-max(li):
    li[li.index(max(li))] = MIN[i]
  else:
    li[li.index(min(li))] = MAX[i]
  #  print(lis,li)

ans.append((max(lis)-min(lis)) * (max(li)-min(li)))

print(min(ans))

Submission status: Wrong Answer

Solution code:
n = int(input())
lis = []
li = []
MAX = []
MIN = []
ans = []
for i in range(n):
  a,b = map(int,input().split())
  MAX.append(max(a,b))
  MIN.append(min(a,b))

ans.append((max(MAX)-min(MAX)) * (max(MIN)-min(MIN)))
  
lis.append(MAX[MAX.index(max(MAX))])
li.append(MIN[MAX.index(max(MAX))])
lis.append(MIN[MIN.index(min(MIN))])
li.append(MAX[MIN.index(min(MIN))])

del MIN[MAX.index(max(MAX))]
del MAX[MAX.index(max(MAX))]
del MAX[MIN.index(min(MIN))]
del MIN[MIN.index(min(MIN))]

for i in range(len(MAX)):
  if min(li) <= MAX[i] and MAX[i] <= max(li):
    continue
  elif min(li) <= MIN[i] and MIN[i] <= max(li):
    continue
  elif min(li)-MAX[i] <= MIN[i]-max(li):
    li[li.index(min(li))] = MAX[i]
  else:
    li[li.index(max(li))] = MIN[i]
    
ans.append((max(lis)-min(lis)) * (max(li)-min(li)))

print(min(ans))

Submission status: Wrong Answer

Solution code:
n = int(input())
lis = []
li = []
for i in range(n):
  a,b = map(int,input().split())
  lis.append(max(a,b))
  li.append(min(a,b))
 # RR || BB
ans1 = (max(lis)-min(lis)) * (max(li)-min(li))

ans2_1 = max(max(lis),max(li))-min(min(lis),min(li))

  # print(lis,li)
for i in range(n):
  if lis[i] == max(lis):
    tmp = lis[i]
    lis[i] = li[i]
    li[i] = tmp
  # print(lis,li)
print((max(lis)-min(lis)) * (max(li)-min(li)))

Submission status: Wrong Answer

Solution code:
n = int(input())
lis = []
li = []
for i in range(n):
  a,b = map(int,input().split())
  lis.append(max(a,b))
  li.append(min(a,b))
 # RR || BB
 #　分からんティウス
print((max(lis)-min(lis)) * (max(li)-min(li)))

Submission status: Wrong Answer

Solution code:
N = int(input())
Ball = []
for i in range(N):
    x, y = map(int, input().split())
    x, y = min(x, y), max(x, y)
    Ball.append((x, y))

Ball.sort()  # ソートしておく
X = [x for x, y in Ball]
Y = [y for x, y in Ball]

# 全体のMIN, MAX
MIN = X[0]
MAX = max(Y)

# 確定2玉を別グループに
ans = (max(X) - MIN) * (MAX - min(Y))

# 確定2玉を同じグループに
B = [x for x in X]  # とりあえず小さいほうを集めたことにしておく
B_max = B[-1]
temp = 0
for i in range(N):
    x, y = X[i], Y[i]
    if abs(B_max - x) > abs(B_max - y):
        B[i] = y
        B_max = max(B_max, y)
    else:
        break

ans = min(ans, (MAX - MIN) * (max(B) - min(B)))
print(ans)

Submission status: Wrong Answer

Solution code:
N = int(input())
Ball = []
for i in range(N):
    x, y = map(int, input().split())
    x, y = min(x, y), max(x, y)
    Ball.append((x, y))

Ball.sort()  # ソートしておく
X = [x for x, y in Ball]
Y = [y for x, y in Ball]

# 全体のMIN, MAX
MIN = X[0]
MAX = max(Y)

# 確定2玉を別グループに
ans = (max(X) - MIN) * (MAX - min(Y))

# 確定2玉を同じグループに
B = [x for x in X]  # とりあえず小さいほうを集めたことにしておく
B_max = B[-1]
temp = 0
for i in range(N):
    x, y = X[i], Y[i]
    if B_max - x > B_max - y >= 0:
        B[i] = y
    else:
        break

ans = min(ans, (MAX - MIN) * (max(B) - min(B)))

# 大きいほうを集めておくパターン
Ball.sort(key=lambda x: x[1])
X = [x for x, y in Ball]
Y = [y for x, y in Ball]
B = [y for y in Y]  # とりあえず大きいほうを集めたことにしておく
B_max = B[-1]
for i in range(N):
    x, y = X[i], Y[i]
    if B_max - y > B_max - x >= 0:
        B[i] = x
    else:
        break

ans = min(ans, (MAX - MIN) * (max(B) - min(B)))
print(ans)

Submission status: Wrong Answer

Solution code:
N = int(input())
Ball = []
for i in range(N):
    x, y = map(int, input().split())
    x, y = min(x, y), max(x, y)
    Ball.append((x, y))

Ball.sort()  # ソートしておく
X = [x for x, y in Ball]
Y = [y for x, y in Ball]

# 全体のMIN, MAX
MIN = X[0]
MAX = max(Y)

# 確定2玉を別グループに
ans = (max(X) - MIN) * (MAX - min(Y))

# 確定2玉を同じグループに
B = [x for x in X]  # とりあえず小さいほうを集めたことにしておく
B_max = B[-1]
temp = 0
for i in range(N):
    x, y = X[i], Y[i]
    if B_max - x >= B_max - y >= 0:
        B[i] = y
    else:
        break

print(min(ans, (MAX - MIN) * (max(B) - min(B))))

Submission status: Wrong Answer

Solution code:
N = int(input())
Ball = []
for i in range(N):
    x, y = map(int, input().split())
    x, y = min(x, y), max(x, y)
    Ball.append((x, y))

Ball.sort()  # ソートしておく
X = [x for x, y in Ball]
Y = [y for x, y in Ball]

# 全体のMIN, MAX
MIN = X[0]
MAX = max(Y)

# 確定2玉を別グループに
ans = (max(X) - MIN) * (MAX - min(Y))

# 確定2玉を同じグループに
B = [x for x in X]  # とりあえず小さいほうを集めたことにしておく
B_max = B[-1]
for i in range(N):
    x, y = X[i], Y[i]
    if B_max - x >= B_max - y > 0:
        B[i] = y

print(min(ans, (MAX - MIN) * (max(B) - min(B))))

Submission status: Wrong Answer

Solution code:
N = int(input())
Ball = []
for i in range(N):
    x, y = map(int, input().split())
    x, y = min(x, y), max(x, y)
    Ball.append((x, y))

Ball.sort()  # ソートしておく
X = [x for x, y in Ball]
Y = [y for x, y in Ball]

# 全体のMIN, MAX
MIN = X[0]
MAX = max(Y)

# 確定2玉を別グループに
ans = (max(X) - MIN) * (MAX - min(Y))

# 確定2玉を同じグループに
B = [x for x in X]  # とりあえず小さいほうを集めたことにしておく
B_max = B[-1]
for i in range(N):
    x, y = X[i], Y[i]
    if B_max - x > B_max - y >= 0:
        B[i] = y

print(min(ans, (MAX - MIN) * (max(B) - min(B))))

Submission status: Wrong Answer

Solution code:
N = int(input())
Ball = []
for i in range(N):
    x, y = map(int, input().split())
    x, y = min(x, y), max(x, y)
    Ball.append((x, y))

Ball.sort()  # ソートしておく
X = [x for x, y in Ball]
Y = [y for x, y in Ball]

# 全体のMIN, MAX
MIN = X[0]
MAX = max(Y)

# 確定2玉を別グループに
ans1 = (max(X) - MIN) * (MAX - min(Y))

# 確定2玉を同じグループに
B_max = X[-1]
B_min = float('inf')

for x, y in Ball:
    if B_max - x > B_max - y and (B_max - y >= 0):  # xを使うよりyのがいいのなら
        B_min = min(B_min, y)
    else:
        break

ans2 = (MAX - MIN) * (B_max - B_min)
print(min(ans1, ans2) if ans2 >= 0 else ans1)

Submission status: Wrong Answer

Solution code:
N = int(input())
Ball = [tuple(map(int, input().split())) for i in range(N)]

# 確定2玉を別グループに（R: 小さいほう, B: 大きいほう）
R, B = [], []
for x, y in Ball:
    x, y = min(x, y), max(x, y)
    R.append(x)
    B.append(y)
ans = (max(R) - min(R)) * (max(B) - min(B))

# 確定2玉を同グループに
M_index, m_index = -1, -1
M, m = 0, float('inf')
# 全体のmax, minと場所を取得
for i in range(N):
    for n in Ball[i]:
        if n > M:
            M = n
            M_index = i
        if n < m:
            m = n
            m_index = i

# 選ばれなかったほう
Mo, mo = min(Ball[M_index]), max(Ball[m_index])

# 組み合わせを取り除いておく
Ball = sorted([Ball[i] for i in range(N) if i not in (M_index, m_index)])

# どこまで入れ替えるを全探索
Ball_lo = [Ball[i][0] for i in range(len(Ball))]
Ball_hi = [Ball[i][1] for i in range(len(Ball))]
for i in range(len(Ball)):
    B = [Mo, mo]
    B += Ball_lo[:i]
    B += Ball_hi[i:]
    ans = min(ans, (M - m) * (max(B) - min(B)))

print(ans)

Submission status: Wrong Answer

Solution code:
N = int(input())
Ball = [tuple(map(int, input().split())) for i in range(N)]

# 確定2玉を別グループに（R: 小さいほう, B: 大きいほう）
R, B = [], []
for x, y in Ball:
    if x < y:
        R.append(x)
        B.append(y)
    else:
        R.append(y)
        B.append(x)
ans = (max(R) - min(R)) * (max(B) - min(B))

# 確定2玉を同グループに
M_index, m_index = -1, -1
M, m = 0, float('inf')
R, B = [], []
# 全体のmax, minと場所を取得
for i in range(N):
    for n in Ball[i]:
        if n > M:
            M = n
            M_index = i
        if n < m:
            m = n
            m_index = i

# 選ばれなかったほう
Mo, mo = min(Ball[M_index]), max(Ball[m_index])

# 組み合わせを取り除いておく
Ball = [Ball[i] for i in range(N) if i not in (M_index, m_index)]

# Rには大きいほうを
R, B = [M, m], [Mo, mo]
for x, y in Ball:
    x, y = min(x, y), max(x, y)
    if x > mo:
        B.append(x)
        R.append(y)
    else:
        R.append(y)
        B.append(x)
ans = min(ans, (max(R) - min(R)) * (max(B) - min(B)))

print(ans)

Submission status: Wrong Answer

Solution code:
N = int(input())
Ball = [tuple(map(int, input().split())) for i in range(N)]

# 確定2玉を別グループに（R: 小さいほう, B: 大きいほう）
R, B = [], []
for x, y in Ball:
    if x < y:
        R.append(x)
        B.append(y)
    else:
        R.append(y)
        B.append(x)
ans = (max(R) - min(R)) * (max(B) - min(B))

# 確定2玉を同グループに
M_index, m_index = -1, -1
M, m = 0, float('inf')
R, B = [], []
# 全体のmax, minと場所を取得
for i in range(N):
    for n in Ball[i]:
        if n > M:
            M = n
            M_index = i
        if n < m:
            m = n
            m_index = i

# 選ばれなかったほう
Mo, mo = min(Ball[M_index]), max(Ball[m_index])

# 組み合わせを取り除いておく
Ball = [Ball[i] for i in range(N) if i not in (M_index, m_index)]

# Rには大きいほうを
R, B = [M, m], [Mo, mo]
for x, y in Ball:
    if x > y:
        R.append(x)
        B.append(y)
    else:
        R.append(y)
        B.append(x)
ans = min(ans, (max(R) - min(R)) * (max(B) - min(B)))

# Rには小さいほうを
R, B = [M, m], [Mo, mo]
for x, y in Ball:
    if x < y:
        R.append(x)
        B.append(y)
    else:
        R.append(y)
        B.append(x)
ans = min(ans, (max(R) - min(R)) * (max(B) - min(B)))

print(ans)

Submission status: Wrong Answer

Solution code:
from collections import defaultdict,deque
import sys,heapq,bisect,math,itertools,string,queue,datetime
sys.setrecursionlimit(10**8)
INF = float('inf')
mod = 10**9+7
eps = 10**-7
def inpl(): return list(map(int, input().split()))
def inpl_s(): return list(input().split())

N = int(input())
xys = []	#x <= y
MIN = INF
MAX = -INF




for i in range(N):
	x,y = inpl()
	if x > y:
		x,y = y,x

	if MIN > x:
		MIN = x
		MIN_pair = y
		MIN_ind = i

	if MAX < y:
		MAX = y
		MAX_pair = x
		MAX_ind = i

	xys.append([x,y])

#MAXとMINがどっちもRed
def solve1():
	R_min, R_max = MIN, MAX
	B_min, B_max = min(MIN_pair,MAX_pair), max(MIN_pair, MAX_pair)

	for x,y in xys:
		if B_min <= x <= B_max:
			continue
		elif B_min <= y <= B_max:
			continue
		elif B_max < x:
			B_max = x
		elif y < B_min:
			B_min = y
		else:
			if B_min-x > y-B_max:
				B_max = y
			else:
				B_min = x

	return (B_max-B_min)*(R_max-R_min)

#MAXがRed,MINがBlue
def solve2():
	R_max,R_min = MAX, MIN_pair
	B_max,B_min = MAX_pair, MIN

	for x,y in xys:
		if y < R_min:
			R_min = y
		elif B_max < x:
			B_max = x

	return (B_max-B_min)*(R_max-R_min)

def solve3():
	miny = INF
	maxx = -INF
	for i,[x,y] in enumerate(xys):
		if i == MIN_ind:
			continue
		else:
			miny = min(miny,y)
			maxx = max(maxx,x)

	return (MAX-miny)*(maxx-MIN)


if N == 1:
	print(xys[0][0]*xys[0][1])
else:
	if MIN_ind != MAX_ind:
		print(min(solve1(),solve2()))
	else:
		print(solve3())

Submission status: Wrong Answer

Solution code:
from collections import defaultdict,deque
import sys,heapq,bisect,math,itertools,string,queue,datetime
sys.setrecursionlimit(10**8)
INF = float('inf')
mod = 10**9+7
eps = 10**-7
def inpl(): return list(map(int, input().split()))
def inpl_s(): return list(input().split())

N = int(input())
xys = []	#x <= y
MIN = INF
MAX = -INF

for i in range(N):
	x,y = inpl()
	if x > y:
		x,y = y,x

	if MIN > x:
		MIN = x
		MIN_pair = y

	if MAX < y:
		MAX = y
		MAX_pair = x

	xys.append([x,y])

#MAXとMINがどっちもRed
R_min, R_max = MIN, MAX
B_min, B_max = min(MIN_pair,MAX_pair), max(MIN_pair, MAX_pair)

for x,y in xys:
	if B_min <= x <= B_max:
		continue
	elif B_min <= y <= B_max:
		continue
	elif B_max < x:
		B_max = x
	elif y < B_min:
		B_min = y
	else:
		if B_min-x > y-B_max:
			B_max = y
		else:
			B_min = x

ans1 = (B_max-B_min)*(R_max-R_min)

#MAXがRed,MINがBlue
R_max,R_min = MAX, MIN_pair
B_max,B_min = MAX_pair, MIN

for x,y in xys:
	if y < R_min:
		R_min = y
	elif B_max < x:
		B_max = x

ans2 = (B_max-B_min)*(R_max-R_min)

print(min(ans1,ans2))

Submission status: Wrong Answer

Solution code:
n = int(input())
x = []
y = []
xy = []
maxlist = []
minlist = []
amax = 0
amin = 10**10
case1 = 0
case2 = 0
for i in range(n):
    store = [int(j) for j in input().split(' ')]
    if store[0] < store[1]:
        store[0], store[1] = store[1], store[0]
    if store[0] == amax:
        maxlist.append(i)
    elif store[0] > amax:
        amax = store[0]
        maxlist = [i]
    if store[1] == amin:
        minlist.append(i)
    elif store[1] < amin:
        amin = store[1]
        minlist = [i]
    x.append(store[0])
    y.append(store[1])
    xy.extend(store)

case1 = (max(x) - min(x)) * (max(y)-min(y))
for k in maxlist:
    if k in minlist:
        print(case1)
        exit()
for index in range(n):
    y[index] = [y[index], index]
y.sort()

bmax = y[n-1][0]
bmin = y[1][0]
check = True
minsum = 10**10
for i in range(0, n-1):
    if x[y[i][1]] > bmax:
        bmax = x[y[i][1]]
    if check and x[y[i][1]] <= y[i+1][0]:
        bmin = x[y[i][1]]
        check = False
    elif check:
        bmin = y[i+1][0]
    if minsum > bmax - bmin:
        minsum = bmax - bmin
    if not check:
        break
case2 = minsum * (amax-amin)
print(min([case1, case2]))

Submission status: Wrong Answer

Solution code:
n = int(input())
x = []
y = []
xy = []
maxlist = []
minlist = []
amax = 0
amin = 10**10
case1 = 0
case2 = 0
for i in range(n):
    store = [int(j) for j in input().split(' ')]
    if store[0] < store[1]:
        store[0], store[1] = store[1], store[0]
    if store[0] == amax:
        maxlist.append(i)
    elif store[0] > amax:
        amax = store[0]
        maxlist = [i]
    if store[1] == amin:
        minlist.append(i)
    elif store[1] < amin:
        amin = store[1]
        minlist = [i]
    x.append(store[0])
    y.append(store[1])
    xy.extend(store)

case1 = (max(x) - min(x))*(max(y)-min(y))
for k in maxlist:
    if k in minlist:
        print(case1)
        exit()
for index in range(n):
    y[index] = [y[index], index]
y.sort()

bmax = y[n-1][0]
bmin = y[1][0]
check = True
minsum = 10**10
for i in range(0, n-1):
    if x[y[i][1]] > bmax:
        bmax = x[y[i][1]]
    if check and x[y[i][1]] <= y[i+1][0]:
        bmin = x[y[i][1]]
        check = False
    elif check:
        bmin = y[i+1][0]
    if minsum > bmax - bmin:
        minsum = bmax - bmin
case2 = minsum * (amax-amin)
print(min([case1, case2]))

Submission status: Wrong Answer

Solution code:
n = int(input())
x = []
y = []
xy = []
maxlist = []
minlist = []
amax = 0
amin = 10**10
case1 = 0
case2 = 0
for i in range(n):
    store = [int(j) for j in input().split(' ')]
    if store[0] < store[1]:
        store[0], store[1] = store[1], store[0]
    if store[0] == amax:
        maxlist.append(i)
    elif store[0] > amax:
        amax = store[0]
        maxlist = [i]
    if store[1] == amin:
        minlist.append(i)
    elif store[1] < amin:
        amin = store[1]
        minlist = [i]
    x.append(store[0])
    y.append(store[1])
    xy.extend(store)

case1 = (max(x) - min(x))*(max(y)-min(y))
for k in maxlist:
    if k in minlist:
        print(case1)
        exit()
for index in range(n):
    y[index] = [y[index], index]
y.sort()

bmax = y[n-1][0]
bmin = y[1][0]
check = True
minsum = 10**10
for i in range(0, n-1):
    if x[y[i][1]] > bmax:
        bmax = x[y[i][1]]
    if check and x[y[i][1]] <= y[i+1][0]:
        bmin = x[y[i][1]]
        check = False
    elif check:
        bmin = y[i+1][0]
    print(bmax, bmin)
    if minsum > bmax - bmin:
        minsum = bmax - bmin
case2 = minsum * (amax-amin)
print(min([case1, case2]))

Submission status: Wrong Answer

Solution code:
n = int(input())
x = []
y = []
xy = []
maxlist = []
minlist = []
amax = 0
amin = 10**10
case1 = 0
case2 = 0
for i in range(n):
    store = [int(j) for j in input().split(' ')]
    if store[0] < store[1]:
        store[0], store[1] = store[1], store[0]
    if store[0] == amax:
        maxlist.append(i)
    elif store[0] > amax:
        amax = store[0]
        maxlist = [i]
    if store[1] == amin:
        minlist.append(i)
    elif store[1] < amin:
        amin = store[1]
        minlist = [i]
    x.append(store[0])
    y.append(store[1])
    xy.extend(store)

case1 = (max(x) - min(x))*(max(y)-min(y))
for k in maxlist:
    if k in minlist:
        print(case1)
        exit()
for index in range(n):
    y[index] = [y[index], index]
y.sort()

bmax = y[n-1][0]
bmin = y[1][0]

minsum = 10**10
for i in range(0, n-1):
    if x[y[i][1]] > bmax:
        bmax = x[y[i][1]]
    if x[y[i][1]] < bmin:
        bmin = x[y[i][1]]
    if minsum > bmax - bmin:
        minsum = bmax - bmin
case2 = minsum * (amax-amin)
print(min([case1, case2]))

Submission status: Wrong Answer

Solution code:
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 = minmax
for b in balls:
  best = min(best, cur_max-b[0])
  cur_max = max(cur_max, b[1])

v2 = (maxmax-minmin)*best

print(min(v1,v2))

Submission status: Wrong Answer

Solution code:
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 = minmax
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))

Submission status: Wrong Answer

Solution code:
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))

Submission status: Wrong Answer

Solution code:
n=int(input())
x,y=zip(*(sorted(map(int,input().split())) for _ in range(n)))
p=min(range(n),key=lambda i:x[i])
q=max(range(n),key=lambda i:y[i])
a,b=sorted([x[q],y[p]])
for i in range(n):
    if i!=p and i!=q:
        if a-x[i]>y[i]-b:
            a=min(a,x[i])
        else:
            b=max(b,y[i])
print(min((max(x)-x[p])*(y[q]-min(y)),(y[q]-x[p])*(b-a)))

Submission status: Wrong Answer

Solution code:
n = int(input())
r_max, b_max = map(int, input().split())
if r_max > b_max:
    r_max, b_max = b_max, r_max
r_min, b_min = r_max, b_max
x_max, x_min = r_max, r_min
y_max, y_min = b_max, b_min


def compaere(xy, _max, _min):
    if xy > _max:
        _x = xy - _min
        f = 1
    elif xy < _min:
        _x = _max - xy
        f = 2
    elif xy >= _min and xy <= _max:
        _x = _max - _min
        f = 0
    return _x, f


for _ in range(n - 1):
    x, y = map(int, input().split())
    if x > y:
        x, y = y, x
    x_max = max(x, x_max)
    x_min = min(x, x_min)
    y_max = max(y, y_max)
    y_min = min(y, y_min)

    r_x, r_x_f = compaere(x, r_max, r_min)
    r_y, r_y_f = compaere(y, r_max, r_min)
    b_x, b_x_f = compaere(x, b_max, b_min)
    b_y, b_y_f = compaere(y, b_max, b_min)

    if r_x * b_y < b_x * r_y:
        if r_x_f:
            if r_x_f == 1:
                r_max = x
            else:
                r_min = x
        if b_y_f:
            if b_y_f == 1:
                b_max = y
            else:
                b_min = y

    else:
        if b_x_f:
            if b_x_f == 1:
                b_max = x
            else:
                b_min = x
        if r_y_f:
            if r_y_f == 1:
                r_max = y
            else:
                r_min = y

print(min((r_max - r_min) * (b_max - b_min),
          (x_max - x_min) * (y_max - y_min)))

Submission status: Wrong Answer

Solution code:
n = int(input())
r_max, b_max = map(int, input().split())
if r_max > b_max:
    r_max, b_max = b_max, r_max
r_min, b_min = r_max, b_max
x_max, x_min = r_max, r_min
y_max, y_min = b_max, b_min


def compaere(xy, _max, _min):
    if xy > _max:
        _x = xy - _min
        f = 1
    elif xy < _min:
        _x = _max - xy
        f = 2
    elif xy >= _min and xy <= _max:
        _x = _max - _min
        f = 0
    return _x, f


for _ in range(n - 1):
    x, y = map(int, input().split())
    if x > y:
        x, y = y, x
    x_max = max(x, x_max)
    x_min = min(x, x_min)
    y_max = max(y, y_max)
    y_min = min(y, y_min)

    r_x, r_x_f = compaere(x, r_max, r_min)
    r_y, r_y_f = compaere(y, r_max, r_min)
    b_x, b_x_f = compaere(x, b_max, b_min)
    b_y, b_y_f = compaere(y, b_max, b_min)
    flag_0 = (x_max - x_min) * (y_max - y_min)
    flag_1 = r_x * b_y
    flag_2 = b_x * r_y

    if flag_0 <= flag_1 and flag_0 <= flag_2:
        r_max = x_max
        r_min = x_min
        b_max = y_max
        b_min = y_min

    elif flag_1 <= flag_2:
        if r_x_f:
            if r_x_f == 1:
                r_max = x
            else:
                r_min = x
        if b_y_f:
            if b_y_f == 1:
                b_max = y
            else:
                b_min = y

    else:
        if b_x_f:
            if b_x_f == 1:
                b_max = x
            else:
                b_min = x
        if r_y_f:
            if r_y_f == 1:
                r_max = y
            else:
                r_min = y

print(min(flag_0, flag_1, flag_2))

Submission status: Wrong Answer

Solution code:
n = int(input())
r_max, b_max = map(int, input().split())
if r_max > b_max:
    r_max, b_max = b_max, r_max
r_min, b_min = r_max, b_max
x_max, x_min = r_max, r_min
y_max, y_min = b_max, b_min


def compaere(xy, _max, _min):
    if xy > _max:
        _x = xy - _min
        f = 1
    elif xy < _min:
        _x = _max - xy
        f = 2
    elif xy >= _min and xy <= _max:
        _x = _max - _min
        f = 0
    return _x, f


for _ in range(n - 1):
    x, y = map(int, input().split())

    if x > y:
        x, y = y, x
    x_max = max(x, x_max)
    x_min = min(x, x_min)
    y_max = max(y, y_max)
    y_min = min(y, y_min)

    r_x, r_x_f = compaere(x, r_max, r_min)
    r_y, r_y_f = compaere(y, r_max, r_min)
    b_x, b_x_f = compaere(x, b_max, b_min)
    b_y, b_y_f = compaere(y, b_max, b_min)

    if r_x * b_y <= b_x * r_y:
        if r_x_f:
            if r_x_f == 1:
                r_max = x
            else:
                r_min = x
        if b_y_f:
            if b_y_f == 1:
                b_max = y
            else:
                b_min = y

    else:
        if b_x_f:
            if b_x_f == 1:
                b_max = x
            else:
                b_min = x
        if r_y_f:
            if r_y_f == 1:
                r_max = y
            else:
                r_min = y

print(min((r_max - r_min) * (b_max - b_min), (x_max - x_min) * (y_max - y_min)))

Submission status: Wrong Answer

Solution code:
n = int(input())
r_max, b_max = map(int, input().split())
r_min, b_min = r_max, b_max


def compaere(xy, _max, _min):
    if xy > _max:
        _x = xy - _min
        f = 1
    elif xy < _min:
        _x = _max - xy
        f = 2
    elif xy >= _min and xy <= _max:
        _x = _max - _min
        f = 0
    return _x, f


for _ in range(n - 1):
    x, y = map(int, input().split())

    r_x, r_x_f = compaere(x, r_max, r_min)
    r_y, r_y_f = compaere(y, r_max, r_min)
    b_x, b_x_f = compaere(x, b_max, b_min)
    b_y, b_y_f = compaere(y, b_max, b_min)

    if r_x * b_y <= b_x * r_y:
        if r_x_f:
            if r_x_f == 1:
                r_max = x
            else:
                r_min = x
        if b_y_f:
            if b_y_f == 1:
                b_max = y
            else:
                b_min = y

    else:
        if b_x_f:
            if b_x_f == 1:
                b_max = x
            else:
                b_min = x
        if r_y_f:
            if r_y_f == 1:
                r_max = y
            else:
                r_min = y

print((r_max - r_min) * (b_max - b_min))