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())
xy = [list(map(int, input().split())) for i in range(n)]
amin, amax, bmin, bmax = float("inf"), 0, float("inf"), 0
for i, j in xy:
    amin = min(amin, min(i, j))
    amax = max(amax, min(i, j))
    bmin = min(bmin, max(i, j))
    bmax = max(bmax, max(i, j))
print((amax - amin) * (bmax - bmin))

Submission status: Wrong Answer

Solution code:
import sys
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines

n = int(readline())
xy = list(map(int,read().split()))

if(n==1):
    print(0)
    exit()

max_num = max(xy)
min_num = min(xy)

max_ind = -1
min_ind = -1
same = False
big = []
small = []
for i in range(n):
    x,y = xy[i*2:i*2+2]
    if(x>y):
        x,y = y,x

    if(x==min_num)&(y==max_num):
        same = True

    if(x==min_num):
        min_ind = i
    if(y==max_num):
        max_ind = i

    big.append(y)
    small.append(x)

#最大と最小を違う色に塗る
ans = (max(big)-min(big)) * (max(small) - min(small))
if(same):
    print(ans)
    exit()

#同じ色に塗る
r = max_num - min_num
if(xy[min_ind*2]==min_num):
    min_pair = xy[min_ind*2+1]
else:
    min_pair = xy[min_ind*2]

if(xy[max_ind*2]==max_num):
    max_pair = xy[max_ind*2+1]
else:
    max_pair = xy[max_ind*2]

nums = []
for i in range(n):
    if(i==min_ind)|(i==max_ind):
        continue
    x,y = xy[i*2:i*2+2]
    if(x>y):
        x,y = y,x
    nums.append((x,y))

if(len(nums)==0):
    b = abs(max_pair-min_pair)
    ans = min(ans,r*b)
    print(ans)
    exit()

nums.sort()
b = max(nums[-1][0], max_pair,min_pair) - min(nums[0][0], max_pair,min_pair)
ans = min(ans,r*b)

min_up = nums[0][1]
max_up = nums[0][1]
for i in range(n-3):
    min_up = min(min_up,nums[i][1])
    max_up = min(max_up,nums[i][1])
    b = max(nums[-1][0], max_pair,min_pair,max_up) - min(nums[i+1][0], max_pair,min_pair,min_up)
    ans = min(ans,r*b)

min_up = min(min_up,nums[-1][1])
max_up = min(max_up,nums[-1][1])
b = max(max_pair,min_pair,max_up) - min(max_pair,min_pair,min_up)
ans = min(ans,r*b)

print(ans)

Submission status: Wrong Answer

Solution code:
import sys
input = sys.stdin.readline

n = int(input())
L, R = [], []
LR = []
INF = 10**9+1
m, M = INF, 0
for i in range(n):
  x, y = map(int, input().split())
  if x > y:
    x, y = y, x
  L.append(x)
  R.append(y)
  LR.append((x, y))
  if m > x:
    m = x
    idx_m = i
  if M < y:
    M = y
    idx_M = i
ans1 = (M-min(R))*(max(L)-m)
if idx_m == idx_M:
  print(ans1)
  exit()
a, b = L[idx_M], R[idx_m]
if a > b:
  a, b = b, a
LR = sorted([lr for i, lr in enumerate(LR) if i != idx_m and i != idx_M])
if not LR:
  print(ans1)
  exit()
l_min, l_max = LR[0][0], LR[-1][0]
ans2 = max(b, l_max)-min(a, l_min)
for i, lr in enumerate(LR):
  l, r = lr
  if l >= a:
    break
  l_max = max(l_max, r)
  if i < len(LR)-1:
    l_min = LR[i+1][0]
  ans2 = min(ans2, max(b, l_max)-min(a, l_min))
ans2 *= M-m
ans = min(ans1, ans2)
print(ans)

Submission status: Wrong Answer

Solution code:
#####segfunc#####
def segfunc(x, y):
    return min(x,y)
#################

#####ide_ele#####
ide_ele = float("inf")
#################

class SegTree:
    """
    init(init_val, ide_ele): 配列init_valで初期化 O(N)
    update(k, x): k番目の値をxに更新 O(logN)
    query(l, r): 区間[l, r)をsegfuncしたものを返す O(logN)
    """
    def __init__(self, init_val, segfunc, ide_ele):
        """
        init_val: 配列の初期値
        segfunc: 区間にしたい操作
        ide_ele: 単位元
        n: 要素数
        num: n以上の最小の2のべき乗
        tree: セグメント木(1-index)
        """
        n = len(init_val)
        self.segfunc = segfunc
        self.ide_ele = ide_ele
        self.num = 1 << (n - 1).bit_length()
        self.tree = [ide_ele] * 2 * self.num
        # 配列の値を葉にセット
        for i in range(n):
            self.tree[self.num + i] = init_val[i]
        # 構築していく
        for i in range(self.num - 1, 0, -1):
            self.tree[i] = self.segfunc(self.tree[2 * i], self.tree[2 * i + 1])

    def update(self, k, x):
        """
        k番目の値をxに更新
        k: index(0-index)
        x: update value
        """
        k += self.num
        self.tree[k] = x
        while k > 1:
            self.tree[k >> 1] = self.segfunc(self.tree[k], self.tree[k ^ 1])
            k >>= 1

    def query(self, l, r):
        """
        [l, r)のsegfuncしたものを得る
        l: index(0-index)
        r: index(0-index)
        """
        res = self.ide_ele

        l += self.num
        r += self.num
        while l < r:
            if l & 1:
                res = self.segfunc(res, self.tree[l])
                l += 1
            if r & 1:
                res = self.segfunc(res, self.tree[r - 1])
            l >>= 1
            r >>= 1
        return res

def main():
    import sys,random

    input=sys.stdin.readline

    N=int(input())
    q=[]
    r=[]
    b=[]
    X=0
    q_append=q.append
    for i in range(N):
        x,y=map(int,input().split())
        r.append(max(x,y))
        b.append(min(x,y))


    X=max(b)
    init_val=[b[i] for i in range(N)]
    for i in range(N):
        x,y=r[i],b[i]
        if X>r[i]:
            init_val[i]=r[i]
        elif X>b[i]:
            q_append((r[i],i,i))
            q_append((r[i],-1,i))
        else:
            q_append((b[i],i,i))
            q_append((r[i],i,i))
            q_append((r[i],-1,i))
            

    q.sort()
    test1=float("inf")
    rmq=SegTree(init_val,segfunc,ide_ele)
    print(q)

    for i in range(0,len(q)):
        val,k,index=q[i]
        if k==-1:
            rmq.update(index,val)
        else:
            res=rmq.query(0,N)
            test1=min(val-res,test1)

    test2=(max(r)-min(r))*(max(b)-min(b))
    test1*=(max(max(b),max(r))-min(min(b),min(r)))
    print(min(test1,test2))

if __name__=="__main__":
    main()

Submission status: Wrong Answer

Solution code:
#####segfunc#####
def segfunc(x, y):
    return min(x,y)
#################

#####ide_ele#####
ide_ele = float("inf")
#################

class SegTree:
    """
    init(init_val, ide_ele): 配列init_valで初期化 O(N)
    update(k, x): k番目の値をxに更新 O(logN)
    query(l, r): 区間[l, r)をsegfuncしたものを返す O(logN)
    """
    def __init__(self, init_val, segfunc, ide_ele):
        """
        init_val: 配列の初期値
        segfunc: 区間にしたい操作
        ide_ele: 単位元
        n: 要素数
        num: n以上の最小の2のべき乗
        tree: セグメント木(1-index)
        """
        n = len(init_val)
        self.segfunc = segfunc
        self.ide_ele = ide_ele
        self.num = 1 << (n - 1).bit_length()
        self.tree = [ide_ele] * 2 * self.num
        # 配列の値を葉にセット
        for i in range(n):
            self.tree[self.num + i] = init_val[i]
        # 構築していく
        for i in range(self.num - 1, 0, -1):
            self.tree[i] = self.segfunc(self.tree[2 * i], self.tree[2 * i + 1])

    def update(self, k, x):
        """
        k番目の値をxに更新
        k: index(0-index)
        x: update value
        """
        k += self.num
        self.tree[k] = x
        while k > 1:
            self.tree[k >> 1] = self.segfunc(self.tree[k], self.tree[k ^ 1])
            k >>= 1

    def query(self, l, r):
        """
        [l, r)のsegfuncしたものを得る
        l: index(0-index)
        r: index(0-index)
        """
        res = self.ide_ele

        l += self.num
        r += self.num
        while l < r:
            if l & 1:
                res = self.segfunc(res, self.tree[l])
                l += 1
            if r & 1:
                res = self.segfunc(res, self.tree[r - 1])
            l >>= 1
            r >>= 1
        return res

def main():
    import sys,random

    input=sys.stdin.readline

    N=int(input())
    q=[]
    r=[]
    b=[]
    X=0
    q_append=q.append
    for i in range(N):
        x,y=map(int,input().split())
        r.append(max(x,y))
        b.append(min(x,y))


    X=max(b)
    init_val=[b[i] for i in range(N)]
    for i in range(N):
        x,y=r[i],b[i]
        if X>r[i]:
            init_val[i]=r[i]
        elif X>b[i]:
            q_append((r[i],i,-1))
            init_val[i]=b[i]
        else:
            q_append((b[i],i,1))
            q_append((r[i],i,-1))
            init_val[i]=b[i]

    q.sort()
    test1=float("inf")
    rmq=SegTree(init_val,segfunc,ide_ele)
    print(q)

    for i in range(0,len(q)):
        val,index,k=q[i]
        if k==-1:
            rmq.update(index,val)
        res=rmq.query(0,N)
        test1=min(val-res,test1)


    test2=(max(r)-min(r))*(max(b)-min(b))
    test1*=(max(max(b),max(r))-min(min(b),min(r)))
    print(min(test1,test2))

if __name__=="__main__":
    main()

Submission status: Wrong Answer

Solution code:
#####segfunc#####
def segfunc(x, y):
    return min(x,y)
#################

#####ide_ele#####
ide_ele = float("inf")
#################

class SegTree:
    """
    init(init_val, ide_ele): 配列init_valで初期化 O(N)
    update(k, x): k番目の値をxに更新 O(logN)
    query(l, r): 区間[l, r)をsegfuncしたものを返す O(logN)
    """
    def __init__(self, init_val, segfunc, ide_ele):
        """
        init_val: 配列の初期値
        segfunc: 区間にしたい操作
        ide_ele: 単位元
        n: 要素数
        num: n以上の最小の2のべき乗
        tree: セグメント木(1-index)
        """
        n = len(init_val)
        self.segfunc = segfunc
        self.ide_ele = ide_ele
        self.num = 1 << (n - 1).bit_length()
        self.tree = [ide_ele] * 2 * self.num
        # 配列の値を葉にセット
        for i in range(n):
            self.tree[self.num + i] = init_val[i]
        # 構築していく
        for i in range(self.num - 1, 0, -1):
            self.tree[i] = self.segfunc(self.tree[2 * i], self.tree[2 * i + 1])

    def update(self, k, x):
        """
        k番目の値をxに更新
        k: index(0-index)
        x: update value
        """
        k += self.num
        self.tree[k] = x
        while k > 1:
            self.tree[k >> 1] = self.segfunc(self.tree[k], self.tree[k ^ 1])
            k >>= 1

    def query(self, l, r):
        """
        [l, r)のsegfuncしたものを得る
        l: index(0-index)
        r: index(0-index)
        """
        res = self.ide_ele

        l += self.num
        r += self.num
        while l < r:
            if l & 1:
                res = self.segfunc(res, self.tree[l])
                l += 1
            if r & 1:
                res = self.segfunc(res, self.tree[r - 1])
            l >>= 1
            r >>= 1
        return res

def main():
    import sys,random

    input=sys.stdin.readline

    N=int(input())
    q=[]
    r=[]
    b=[]
    X=0
    q_append=q.append
    for i in range(N):
        x,y=map(int,input().split())
        r.append(max(x,y))
        b.append(min(x,y))


    X=max(b)
    init_val=[b[i] for i in range(N)]
    for i in range(N):
        x,y=r[i],b[i]
        if X>=r[i]:
            init_val[i]=r[i]
        elif X>=b[i]:
            q_append((r[i],i,i))
            init_val[i]=b[i]
            q_append((r[i],-1,i))
        else:
            q_append((b[i],i,i))
            q_append((r[i],i,i))
            q_append((r[i],-1,i))
            init_val[i]=b[i]

    q.sort()
    test1=float("inf")
    rmq=SegTree(init_val,segfunc,ide_ele)

    for i in range(0,len(q)):
        val,k,index=q[i]
        if k==-1:
            rmq.update(index,val)
        else:
            res=rmq.query(0,N)
            test1=min(val-res,test1)

    test2=(max(r)-min(r))*(max(b)-min(b))
    test1*=(max(max(b),max(r))-min(min(b),min(r)))
    print(min(test1,test2))

if __name__=="__main__":
    main()

Submission status: Wrong Answer

Solution code:
import sys
input=sys.stdin.readline
n=int(input())
l=[list(map(int,input().split())) for i in range(n)]

ans=[]
l.sort()
B1=[];R1=[]
for i in range(n):
  B1.append(max(l[i]))
  R1.append(min(l[i]))
ans.append((max(B1)-min(B1))*(max(R1)-min(R1)))

Bleft=[]
Bright=[]
Rleft=[]
Rright=[]

M=B1[0];m=B1[0]
Bleft.append([m,M])
for i in range(1,n):
  M=max(M,B1[i])
  m=min(m,B1[i])
  Bleft.append([m,M])

B1.reverse()
M=B1[0];m=B1[0]
Bright.append([m,M])
for i in range(1,n):
  M=max(M,B1[i])
  m=min(m,B1[i])
  Bright.append([m,M])

M=R1[0];m=R1[0]
Rleft.append([m,M])
for i in range(1,n):
  M=max(M,R1[i])
  m=min(m,R1[i])
  Rleft.append([m,M])

R1.reverse()
M=R1[0];m=R1[0]
Rright.append([m,M])
for i in range(1,n):
  M=max(M,R1[i])
  m=min(m,R1[i])
  Rright.append([m,M])

for i in range(n-1):
  M1=max(Bleft[i][1],Rright[n-2-i][1])
  m1=min(Bleft[i][0],Rright[n-2-i][0])
  M2=max(Rleft[i][1],Bright[n-2-i][1])
  m2=min(Rleft[i][0],Bright[n-2-i][0])
  ans.append((M1-m1)*(M2-m2))

print(min(ans))

Submission status: Wrong Answer

Solution code:
import sys
input = sys.stdin.readline
n = int(input())
xy = [list(map(int,input().split())) for i in range(n)]
if n == 1:
  print(0)
  exit()
rmax = xy[0][0]
rmin = xy[0][0]
bmax = xy[0][1]
bmin = xy[0][1]
ls = [rmax,rmin,bmax,bmin]
for i in range(1,n):
  x,y = xy[i]
  tmp = []
  for s,t in ((x,y),(y,x)):
    rmxt = max(ls[0],s)
    rmnt = min(ls[1],s)
    bmxt = max(ls[2],t)
    bmnt = min(ls[3],t)
    pr = (rmxt-rmnt)*(bmxt-bmnt)
    tmp.append([pr,rmxt,rmnt,bmxt,bmnt])
  if tmp[0][0] > tmp[1][0]:
    ls = tmp[1][1:]
  else:
    ls = tmp[0][1:]
print((ls[0]-ls[1])*(ls[2]-ls[3]))

Submission status: Wrong Answer

Solution code:
import sys

sys.setrecursionlimit(10 ** 6)
int1 = lambda x: int(x) - 1
p2D = lambda x: print(*x, sep="\n")
def II(): return int(sys.stdin.readline())
def MI(): return map(int, sys.stdin.readline().split())
def LI(): return list(map(int, sys.stdin.readline().split()))
def LLI(rows_number): return [LI() for _ in range(rows_number)]

def main():
    n=II()
    xy=[LI() for _ in range(n)]
    xy=[[x,y] if x<y else [y,x] for x,y in xy]
    rr=[]
    bb=[]
    for x,y in xy:
        rr.append(x)
        bb.append(y)
    mx=max(rr)
    mn=min(rr)
    d=max(bb)-mn
    ans=(mx-mn)*(max(bb)-min(bb))
    ymin=xy[0][1]
    for i in range(n-1):
        y=xy[i][1]
        if y<ymin:ymin=y
        mn=min(xy[i+1][0],ymin)
        mx=max(mx,y)
        ans=min(ans,(mx-mn)*d)
    print(ans)

main()

Submission status: Wrong Answer

Solution code:
import sys
def input():
	return sys.stdin.readline()[:-1]

n = int(input())
d = []
M, m = 0, 10**30
M_of_m, m_of_M = 0, 10**30
for _ in range(n):
	x, y = map(int, input().split())
	g, l = max(x, y), min(x, y)
	d.append([l, g])
	M = max(M, g)
	m = min(m, l)
	M_of_m = max(M_of_m, l)
	m_of_M = min(m_of_M, g)
ans1 = (M - m_of_M) * (M_of_m - m)

M_other, m_other = M_of_m, m
gap = M_other - m_other
d.sort(key=min)
for i in range(n-1):
	M_other = max(M_other, d[i][1])
	if m_other == d[i][0]:
		m_other = min(d[i][1], d[i+1][0])
	gap = min(gap, M_other - m_other)
M_other = max(M_other, d[n-1][1])
gap = min(gap, M_other - m_other)
ans2 = (M - m) * gap

#print(ans1, ans2)
print(min(ans1, ans2))

Submission status: Wrong Answer

Solution code:
import sys
input = sys.stdin.readline
n=int(input())
A=[]
append=A.append
for i in range(n):
  x,y=map(int,input().split())
  if x>y:
    x,y=y,x
  append((x,y,i))
A.sort(key=lambda x:x[0])
x1,y1,n1=A[0]
A.sort(key=lambda x:x[1],reverse=True)
x2,y2,n2=A[0]
r1,r2,b1,b2=0,0,0,0
if n1==n2:
  r1,r2,b1,b2=y1,float("inf"),-float("inf"),x1
  for i in range(n):
    if i==n1:
      continue
    else:
      x,y,m=A[i]
      r2=min(r2,y)
      b1=max(b1,x)
  ans=(r1-r2)*(b1-b2)
else:
  r11,r12,b11,b12=y2,y1,x2,x1
  r21,r22,b21,b22=y2,x1,max(x2,y1),min(x2,y1)
  for i in range(n):
    if i==n1 or i==n2:
      continue
    else:
      x,y,m=A[i]
      r12=min(r12,y)
      b11=max(b11,x)
      b21=max(b21,y)
      b22=min(b22,x)
  ans=min((r11-r12)*(b11-b12),(r21-r22)*(b21-b22))
print(0 if n==1 else ans)

Submission status: Wrong Answer

Solution code:
import sys
input = sys.stdin.readline
n=int(input())
A=[]
append=A.append
for i in range(n):
  x,y=map(int,input().split())
  if x>y:
    x,y=y,x
  append((x,y,i))
A.sort(key=lambda x:x[0])
x1,y1,n1=A[0]
A.sort(key=lambda x:x[1],reverse=True)
x2,y2,n2=A[0]
r1,r2,b1,b2=0,0,0,0
if n1==n2:
  r1,r2,b1,b2=y1,float("inf"),-float("inf"),x1
  for i in range(n):
    if i==n1:
      continue
    else:
      x,y,m=A[i]
      r2=min(r2,y)
      b1=max(b1,x)
  ans=(r1-r2)*(b1-b2)
else:
  r1,r2,b1,b2=y2,y1,x2,x1
  for i in range(n):
    if i==n1 or i==n2:
      continue
    else:
      x,y,m=A[i]
      r2=min(r2,y)
      b1=max(b1,x)
  ans=(r1-r2)*(b1-b2)
print(0 if n==1 else ans)

Submission status: Wrong Answer

Solution code:
from operator import itemgetter

# 入力
N = int(input())
x, y = (
    zip(*(map(int, input().split()) for _ in range(N))) if N else
    ((), ())
)

# R_{max} のボールを赤で塗ると仮定
# R_{min} のボールが赤の場合と青の場合で場合分けし、最小値を解とする
s = sorted(map(sorted, zip(x, y)))
t = sorted(map(sorted, zip(x, y)), key=itemgetter(1))
INF = 10**20

ans = min(
    (s[-1][0] - s[0][0]) * (t[-1][1] - t[0][1]),
    (
        INF if N == 1 or (s[0][1] == t[-1][1] and s[1][0] > s[0][0]) else
        min(
            (
                t[-1][1] -
                s[0][0]
            ) * (
                max(s[-1][0], s[0][1]) -
                min(s[1][0], s[0][1])
            ),
            (
                t[-1][1] -
                s[0][0]
            ) * (
                max(t[-2][1], t[-1][0]) -
                min(t[0][1], t[-1][0])
            )
        )
    )
)

# 出力
print(ans)

Submission status: Wrong Answer

Solution code:
from operator import itemgetter

# 入力
N = int(input())
x, y = (
    zip(*(map(int, input().split()) for _ in range(N))) if N else
    ((), ())
)

# R_{max} のボールを赤で塗ると仮定
# R_{min} のボールが赤の場合と青の場合で場合分けし、最小値を解とする
s = sorted(map(sorted, zip(x, y)))
t = sorted(map(sorted, zip(x, y)), key=itemgetter(1))
INF = 10**10

ans = min(
    (s[-1][0] - s[0][0]) * (t[-1][1] - t[0][1]),
    (
        INF if N == 1 or (s[0][1] == t[-1][1] and s[1][0] > s[0][0]) else
        min(
            (
                t[-1][1] -
                s[0][0]
            ) * (
                max(s[-1][0], s[0][1]) -
                min(s[1][0], s[0][1])
            ),
            (
                t[-1][1] -
                s[0][0]
            ) * (
                max(t[-2][1], t[-1][0]) -
                min(t[0][1], t[-1][0])
            )
        )
    )
)

# 出力
print(ans)

Submission status: Wrong Answer

Solution code:
from operator import itemgetter

# 入力
N = int(input())
x, y = (
    zip(*(map(int, input().split()) for _ in range(N))) if N else
    ((), ())
)

# R_{max} のボールを赤で塗ると仮定
# R_{min} のボールが赤の場合と青の場合で場合分けし、最小値を解とする
u, v = zip(*sorted(map(sorted, zip(x, y))))
U, V = zip(*sorted(map(sorted, zip(x, y)), key=itemgetter(1)))
INF = 10**10

ans = min(
    (u[-1] - u[0]) * (V[-1] - V[0]),
    (
        INF if N == 1 or (v[0] == V[-1] and v[1] > u[0]) else
        min(
            (V[-1] - u[0]) * (max(u[-1], v[0]) - min(u[1], v[0])),
            (V[-1] - u[0]) * (max(V[-2], U[-1]) - min(V[0], U[-1]))
        )
    )
)

# 出力
print(ans)

Submission status: Wrong Answer

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

Submission status: Wrong Answer

Solution code:
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(T,cur-ma)
        break
    T=min(T,cur-a)
    cur=max(cur,b)
print(min(ans,(max(D)-min(C))*T))

Submission status: Wrong Answer

Solution code:
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(T,cur-ma)
        break
    T=min(T,cur-a)
    cur=max(cur,b)

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

Submission status: Wrong Answer

Solution code:
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))
A.sort()
X=[x for x,y in A]
Y=[y for x,y in A]
index=Y.index(max(Y))
X=[A[i][0] for i in range(1,N) if i!=index]
Y=[A[i][1] for i in range(1,N) if i!=index]
B=X+[A[0][1],A[index][0]]
Bmax=max(B)
for i in range(len(X)):
    x,y=X[i],Y[i]
    if Bmax-x>y-Bmax>=0:
        B[i]=y
    else:
        break
print(min(ans,(max(D)-min(C))*(max(B)-min(B))))

Submission status: Wrong Answer

Solution code:
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))
Dmax=[0]*N
Dmax[0]=D[0]
Dmin=[0]*N
Dmin[0]=D[0]
a=D[0]
b=D[0]
for i in range(1,N):
    if a>D[i]:
        a=D[i]
    if b<D[i]:
        b=D[i]
    Dmax[i]=b
    Dmin[i]=a
Dmax1=[0]*N
Dmax1[-1]=D[-1]
Dmin1=[0]*N
Dmin1[-1]=D[-1]
a=D[-1]
b=D[-1]
for i in range(N-1,-1,-1):
    if a>D[i]:
        a=D[i]
    if b<D[i]:
        b=D[i]
    Dmax1[i]=b
    Dmin1[i]=a
#print(A,Dmax1,Dmin1)
#T=max(max(C),max(D))-min(min(C),min(D))
for i in range(1,N):
    ans=min(ans,(max(A[i-1][0],Dmax1[i]) - min( A[0][0], Dmin1[i]) ) *(max(A[-1][0],Dmax[i-1] ) - min(A[i][0],Dmin[i-1])))
    #print(max(A[i-1][0],Dmax1[i]) , min( A[i][0], Dmin1[i]),max(A[-1][0],Dmax[i-1] ) , min(A[i][0],Dmin[i-1]))
#print(ans)

print(ans)

Submission status: Wrong Answer

Solution code:
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))
Dmax=[0]*N
Dmax[0]=D[0]
Dmin=[0]*N
Dmin[0]=D[0]
a=D[0]
b=D[0]
for i in range(1,N):
    if a>D[i]:
        a=D[i]
    if b<D[i]:
        b=D[i]
    Dmax[i]=b
    Dmin[i]=a
#print(A,Dmax,Dmin)
T=max(max(C),max(D))-min(min(C),min(D))
for i in range(1,N):
    ans=min(ans,T*(max(A[-1][0],Dmax[i-1] ) - min(A[i][0],Dmin[i-1])))
    #print(max(A[-1][0],Dmax[i-1] ) , min(A[i][0],Dmin[i-1]))
#print(ans)

print(ans)

Submission status: Wrong Answer

Solution code:
import sys
input = sys.stdin.readline
N=int(input())
A=[]
C=[]
D=[]
s=10**14
si=0
t=0
ti=0
for i in range(N):
    a,b=map(int,input().split())
    c,d=min(a,b),max(a,b)
    if s>=c:
        s=c
        si=i
    if t<=d:
        t=d
        ti=i
    A.append((c,d))
    C.append(c)
    D.append(d)
#print(A,C,D,si,ti)
ans=(max(C)-min(C))*(max(D)-min(D))
if si==ti:
    print(ans)
    sys.exit()
E=[]
F=[]
E.append(A[si][0])
E.append(A[ti][1])
F.append(A[si][1])
F.append(A[ti][0])
F.sort()
a=F[0]
b=F[1]
for i in range(N):
    #print(a, b)
    if i==si or i==ti:
        continue
    x,y =A[i]
    if a<=x<=b:
        F.append(x)
        E.append(y)
        continue
    if a<=y<=b:
        F.append(y)
        E.append(x)
        continue
    if y<a:
        F.append(y)
        E.append(x)
        a=y
        continue
    if b<x:
        F.append(x)
        E.append(y)
        b=x
        continue
    if y-b<=a-x:
        F.append(y)
        E.append(x)
        b=y
        continue
    if y-b>a-x:
        F.append(x)
        E.append(y)
        a=x
        continue
ans=min(ans,(max(E)-min(E))*(max(F)-min(F)) )
E=[]
F=[]
E.append(A[si][0])
E.append(A[ti][1])
F.append(A[si][1])
F.append(A[ti][0])
F.sort()
a=F[0]
b=F[1]
for i in range(N):
    #print(a, b)
    if i==si or i==ti:
        continue
    x,y =A[i]
    if a<=x<=b:
        F.append(x)
        E.append(y)
        continue
    if a<=y<=b:
        F.append(y)
        E.append(x)
        continue
    if y<a:
        F.append(y)
        E.append(x)
        a=y
        continue
    if b<x:
        F.append(x)
        E.append(y)
        b=x
        continue
    if y-b>=a-x:
        F.append(x)
        E.append(y)
        a=x
        continue
    if y-b<a-x:
        F.append(y)
        E.append(x)
        b=y
        continue
#print(A,C,D,E,F,si,ti)
ans=min(ans,(max(E)-min(E))*(max(F)-min(F)) )
print(ans)

Submission status: Wrong Answer

Solution code:
import sys
input = sys.stdin.readline
N=int(input())
A=[]
C=[]
D=[]
s=10**14
si=0
t=0
ti=0
for i in range(N):
    a,b=map(int,input().split())
    c,d=min(a,b),max(a,b)
    if s>=c:
        s=c
        si=i
    if t<=d:
        t=d
        ti=i
    A.append((c,d))
    C.append(c)
    D.append(d)
#print(A,C,D,si,ti)
ans=(max(C)-min(C))*(max(D)-min(D))
if si==ti:
    print(ans)
    sys.exit()
E=[]
F=[]
E.append(A[si][0])
E.append(A[ti][1])
F.append(A[si][1])
F.append(A[ti][0])
F.sort()
a=F[0]
b=F[1]
for i in range(N):
    #print(a, b)
    if i==si or i==ti:
        continue
    x,y =A[i]
    if a<=x<=b:
        F.append(x)
        E.append(y)
        continue
    if a<=y<=b:
        F.append(y)
        E.append(x)
        continue
    if y<a:
        F.append(y)
        E.append(x)
        a=y
        continue
    if b<x:
        F.append(x)
        E.append(y)
        b=x
        continue
    if y-b<=a-x:
        F.append(y)
        E.append(x)
        b=y
        continue
    if y-b>a-x:
        F.append(x)
        E.append(y)
        a=x
        continue
#print(A,C,D,E,F,si,ti)
print(min(ans,(max(E)-min(E))*(max(F)-min(F)) ))

Submission status: Wrong Answer

Solution code:
import sys
input = sys.stdin.readline
N=int(input())
A=[]
C=[]
D=[]
s=10**14
si=0
t=0
ti=0
for i in range(N):
    a,b=map(int,input().split())
    c,d=min(a,b),max(a,b)
    if s>=c:
        s=c
        si=i
    if t<=d:
        t=c
        ti=i
    A.append((c,d))
    C.append(c)
    D.append(d)
#print(A,C,D,si,ti)
ans=(max(C)-min(C))*(max(D)-min(D))
if si==ti:
    print(ans)
    sys.exit()
E=[]
F=[]
E.append(A[si][0])
E.append(A[ti][1])
F.append(A[si][1])
F.append(A[ti][0])
F.sort()
a=F[0]
b=F[1]
for i in range(N):
    #print(a, b)
    if i==si or i==ti:
        continue
    x,y =A[i]
    if a<=x<=b:
        F.append(x)
        E.append(y)
        continue
    if a<=y<=b:
        F.append(y)
        E.append(x)
        continue
    if y<a:
        F.append(y)
        E.append(x)
        a=y
        continue
    if b<x:
        F.append(x)
        E.append(y)
        b=x
        continue
    if y-b<=a-x:
        F.append(y)
        E.append(x)
        b=y
        continue
    if y-b>a-x:
        F.append(x)
        E.append(y)
        a=x
        continue
#print(A,C,D,E,F,si,ti)
print(min(ans,(max(E)-min(E))*(max(F)-min(F)) ))

Submission status: Wrong Answer

Solution code:
import sys
input = sys.stdin.readline
N=int(input())
A=[]
C=[]
D=[]
s=10**14
si=0
t=0
ti=0
for i in range(N):
    a,b=map(int,input().split())
    c,d=min(a,b),max(a,b)
    if s>=c:
        s=c
        si=i
    if t<=d:
        t=c
        ti=i
    A.append((c,d))
    C.append(c)
    D.append(d)
#print(A,C,D,si,ti)
ans=(max(C)-min(C))*(max(D)-min(D))
if si==ti:
    print(ans)
    sys.exit()
E=[]
F=[]
E.append(A[si][0])
E.append(A[ti][1])
F.append(A[si][1])
F.append(A[ti][0])
F.sort()
a=F[0]
b=F[1]
for i in range(N):
    if i==si or i==ti:
        continue
    x,y =A[i]
    if a<=x<=b:
        F.append(x)
        E.append(y)
        continue
    if a<=y<=b:
        F.append(y)
        E.append(x)
        continue
    if y<a:
        F.append(y)
        E.append(x)
        continue
    if b<x:
        F.append(x)
        E.append(y)
        continue
    if y-b<a-x:
        F.append(y)
        E.append(x)
        continue
    if y-b>a-x:
        F.append(x)
        E.append(y)
        continue
#print(A,C,D,E,F,si,ti)
print(min(ans,(max(E)-min(E))*(max(F)-min(F)) ))

Submission status: Wrong Answer

Solution code:

N = int(input())

big = []
small = []
for i in range(N):
    x,y=list(map(int,input().split()))
    
    big.append(max(x,y))
    small.append(min(x,y))
    

big_max=max(big)
small_max = max(small)
big_min=min(big)
small_min=min(small)

ans1 = (big_max-big_min)*(small_max-small_min)
ans2 = abs(small_max-big_min)*(big_max-small_min)
ans3 = (big_max-small_max)*(big_min-small_min)

print(min(ans1,ans2,ans3))

Submission status: Wrong Answer

Solution code:

N = int(input())

big = []
small = []
for i in range(N):
    x,y=list(map(int,input().split()))
    
    big.append(max(x,y))
    small.append(min(x,y))
    

big_max=max(big)
small_max = max(small)
big_min=min(big)
small_min=min(small)

ans1 = (big_max-big_min)*(small_max-small_min)
ans2 = abs(small_max-big_min)*(big_max-small_min)
ans3 = (big_max-small_max)*(big_min-small_min)

print(max(ans1,ans2,ans3))

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(max(ans))