Problem:


Score : 500 points

Problem Statement

There are N integers X_1, X_2, \cdots, X_N, and we know that A_i \leq X_i \leq B_i.
Find the number of different values that the median of X_1, X_2, \cdots, X_N can take.

Notes

The median of X_1, X_2, \cdots, X_N is defined as follows. Let x_1, x_2, \cdots, x_N be the result of sorting X_1, X_2, \cdots, X_N in ascending order.

If N is odd, the median is x_{(N+1)/2};

if N is even, the median is (x_{N/2} + x_{N/2+1}) / 2.

Constraints

2 \leq N \leq 2 \times 10^5

1 \leq A_i \leq B_i \leq 10^9

All values in input are integers.

Input

Input is given from Standard Input in the following format:

N
A_1 B_1
A_2 B_2
:
A_N B_N

Output

Print the answer.

Sample Input 1

2
1 2
2 3

Sample Output 1

3

If X_1 = 1 and X_2 = 2, the median is \frac{3}{2};

if X_1 = 1 and X_2 = 3, the median is 2;

if X_1 = 2 and X_2 = 2, the median is 2;

if X_1 = 2 and X_2 = 3, the median is \frac{5}{2}.

Thus, the median can take three values: \frac{3}{2}, 2, and \frac{5}{2}.

Sample Input 2

3
100 100
10 10000
1 1000000000

Sample Output 2

9991



Sample input:
2
1 2
2 3


Sample output:
3

Submission status: Wrong Answer

Solution code:
N = int(input())
A = [0 for _ in range(N)]
B = [0 for _ in range(N)]
for k in range(N):
  A[k], B[k] = map(int, input().split())

if N%2 == 1:
  medianmax = B[0]
  medianmin = A[0]
  for k in range(1, N//2 +1):
    if min(B[2*k-1], B[2*k]) < medianmin and max(A[2*k], A[2*k-1]) > medianmin:
      medianmin = medianmin
    elif B[2*k] < medianmin and B[2*k-1] < medianmin:
      medianmin = max(A[2*k], A[2*k-1])
    elif A[2*k] > medianmin and A[2*k-1] > medianmin:
      medianmin = min(A[2*k], A[2*k-1])
    else:
      medianmin = min(medianmin, max(A[2*k-1], A[2*k]))
    if min(B[2*k-1], B[2*k]) < medianmax and max(A[2*k], A[2*k-1]) > medianmax:
      medianmax = medianmax
    elif A[2*k] > medianmin and A[2*k-1] > medianmin:
      medianmax = min(B[2*k], B[2*k-1])
    elif B[2*k] < medianmax and B[2*k-1] < medianmax:
      medianmax = max(B[2*k], B[2*k-1])
    else:  
      medianmax = max(medianmax, min(B[2*k-1], B[2*k]))
  print(medianmax-medianmin+1)
else:
  medianmax = B[0]
  medianmin = A[0]
  for k in range(1, N//2):
    if min(B[2*k-1], B[2*k]) < medianmin and max(A[2*k], A[2*k-1]) > medianmin:
      medianmin = medianmin
    elif B[2*k] < medianmin and B[2*k-1] < medianmin:
      medianmin = max(A[2*k], A[2*k-1])
    elif A[2*k] > medianmin and A[2*k-1] > medianmin:
      medianmin = min(A[2*k], A[2*k-1])
    else:
      medianmin = min(medianmin, max(A[2*k-1], A[2*k]))
    if min(B[2*k-1], B[2*k]) < medianmax and max(A[2*k], A[2*k-1]) > medianmax:
      medianmax = medianmax
    elif A[2*k] > medianmin and A[2*k-1] > medianmin:
      medianmax = min(B[2*k], B[2*k-1])
    elif B[2*k] < medianmax and B[2*k-1] < medianmax:
      medianmax = max(B[2*k], B[2*k-1])
    else:  
      medianmax = max(medianmax, min(B[2*k-1], B[2*k]))
  mi = abs(medianmin + A[-1])
  ma = abs(medianmax + B[-1])
  print(ma-mi+1)

Submission status: Wrong Answer

Solution code:
N = int(input())
A = [0 for _ in range(N)]
B = [0 for _ in range(N)]
for k in range(N):
  A[k], B[k] = map(int, input().split())

if N%2 == 1:
  medianmax = B[0]
  medianmin = A[0]
  for k in range(1, N//2 +1):
    if min(B[2*k-1], B[2*k]) < medianmin and max(A[2*k], A[2*k-1]) > medianmin:
      medianmin = medianmin
    elif A[2*k] > medianmin and A[2*k-1] > medianmin:
      medianmin = min(A[2*k], A[2*k-1])
    else:
      medianmin = min(medianmin, max(A[2*k-1], A[2*k]))
    if min(B[2*k-1], B[2*k]) < medianmax and max(A[2*k], A[2*k-1]) > medianmax:
      medianmax = medianmax
    elif B[2*k] < medianmax and B[2*k-1] < medianmax:
      medianmax = max(B[2*k], B[2*k-1])
    else:  
      medianmax = max(medianmax, min(B[2*k-1], B[2*k]))
  print(medianmax-medianmin+1)
else:
  medianmax = B[0]
  medianmin = A[0]
  for k in range(1, N//2):
    if min(B[2*k-1], B[2*k]) < medianmin and max(A[2*k], A[2*k-1]) > medianmin:
      medianmin = medianmin
    elif A[2*k] > medianmin and A[2*k-1] > medianmin:
      medianmin = min(A[2*k], A[2*k-1])
    else:
      medianmin = min(medianmin, max(A[2*k-1], A[2*k]))
    if min(B[2*k-1], B[2*k]) < medianmax and max(A[2*k], A[2*k-1]) > medianmax:
      medianmax = medianmax
    elif B[2*k] < medianmax and B[2*k-1] < medianmax:
      medianmax = max(B[2*k], B[2*k-1])
    else:  
      medianmax = max(medianmax, min(B[2*k-1], B[2*k]))
  mi = abs(medianmin + A[-1])
  ma = abs(medianmax + B[-1])
  print(ma-mi+1)

Submission status: Wrong Answer

Solution code:
N = int(input())
A = [0 for _ in range(N)]
B = [0 for _ in range(N)]
for k in range(N):
  A[k], B[k] = map(int, input().split())

if N%2 == 1:
  medianmax = B[0]
  medianmin = A[0]
  for k in range(1, N//2 +1):
    if A[2*k] > medianmin and A[2*k-1] > medianmin:
      medianmin = min(A[2*k], A[2*k-1])
    else:
      medianmin = min(medianmin, max(A[2*k-1], A[2*k]))
    if B[2*k] < medianmax and B[2*k-1] < medianmax:
      medianmax = max(B[2*k], B[2*k-1])
    else:  
      medianmax = max(medianmax, min(B[2*k-1], B[2*k]))
  print(medianmax-medianmin+1)
else:
  medianmax = B[0]
  medianmin = A[0]
  for k in range(1, N//2):
    if A[2*k] > medianmin and A[2*k-1] > medianmin:
      medianmin = min(A[2*k], A[2*k-1])
    else:
      medianmin = min(medianmin, max(A[2*k-1], A[2*k]))
    if B[2*k] < medianmax and B[2*k-1] < medianmax:
      medianmax = max(B[2*k], B[2*k-1])
    else:  
      medianmax = max(medianmax, min(B[2*k-1], B[2*k]))
  mi = abs(medianmin + A[-1])
  ma = abs(medianmax + B[-1])
  print(ma-mi+1)

Submission status: Wrong Answer

Solution code:
N = int(input())
A = [0 for _ in range(N)]
B = [0 for _ in range(N)]
for k in range(N):
  A[k], B[k] = map(int, input().split())

if N%2 == 1:
  medianmax = B[0]
  medianmin = A[0]
  for k in range(1, N//2 +1):
    if A[2*k] > medianmin and A[2*k-1] > medianmin:
      medianmin = min(A[2*k], A[2*k-1])
    else:
      medianmin = min(medianmin, max(A[2*k-1], A[2*k]))
    if B[2*k] < medianmax and B[2*k-1] < medianmax:
      medianmax = max(B[2*k], B[2*k-1])
    else:  
      medianmax = max(medianmax, min(B[2*k-1], B[2*k]))
  print(medianmax-medianmin+1)
else:
  medianmax = B[0]
  medianmin = A[0]
  for k in range(1, N//2):
    if A[2*k] > medianmin and A[2*k-1] > medianmin:
      medianmin = min(A[2*k], A[2*k-1])
    else:
      medianmin = min(medianmin, max(A[2*k-1], A[2*k]))
    if B[2*k] < medianmax and B[2*k-1] < medianmax:
      medianmax = max(B[2*k], B[2*k-1])
    else:  
      medianmax = max(medianmax, min(B[2*k-1], B[2*k]))
  mi = abs(medianmin + A[-1])*2
  ma = abs(medianmax + B[-1])*2
  print((ma-mi)//2+1)

Submission status: Wrong Answer

Solution code:
N = int(input())
A,B = [0]*N,[0]*N
for i in range(N):
    A[i],B[i] = map(int,input().split())
if N%2 == 1:
    ans = B[int((N-1)/2)] - A[int((N-1)/2)] + 1
elif N%2 == 0:
    ans = B[int(N/2)] + B[int(N/2-1)] - A[int(N/2)] - A[int(N/2-1)] + 1
print(ans)

Submission status: Wrong Answer

Solution code:
N = int(input())
A,B,X = [0]*N,[0]*N,[0]*N
for i in range(N):
    A[i],B[i] = map(int,input().split())
if N%2 == 1:
    ans = B[int((N-1)/2)] - A[int((N-1)/2)] + 1
elif N%2 == 0:
    ans = B[int(N/2)] + B[int(N/2)-1] - A[int(N/2)] - A[int(N/2)-1] + 1
print(ans)

Submission status: Wrong Answer

Solution code:
import numpy as np
import math
from decimal import *
#from numba import njit

def getVar():
    return map(int, input().split())
def getArray():
    return list(map(int, input().split()))
def getNumpy():
    return np.array(list(map(int, input().split())), dtype='int64')

def main():
    N = int(input())
    A = np.empty(N, dtype='int64')
    B = np.empty(N, dtype='int64')
    for i in range(N):
        (a,b) = getVar()
        A[i] = a
        B[i] = b
    
    if N%2 == 0:
        l1 = 10**9
        u1 = 0
        l2 = 10**9
        u2 = 0
        c = N//2 - 1
        for i in range(N):
            a = A[i]
            b = B[i]
            lower1 = np.count_nonzero(A<=b)
            upper1 = np.count_nonzero(B>=a)
            if lower1 >= c and upper1 >= c:
                #print(f'  {A[np.where(A.argsort() == c)][0]}')
                l1 = min(l1, max(a, A[np.where(A.argsort() == c)][0]))
                #print(f'  {B[np.where(B.argsort() == (N-c-1))][0]}')
                u1 = max(u1, min(b, B[np.where(B.argsort() == (N-c-2))][0]))
                #print(f'    {l1} {u1}')
            if lower1 >= c+1 and upper1 >= c+1:
                #print(f'  {A[np.where(A.argsort() == c+1)][0]}')
                l2 = min(l2, max(a, A[np.where(A.argsort() == c+1)][0]))
                #print(f'  {B[np.where(B.argsort() == (N-c-1))][0]}')
                u2 = max(u2, min(b, B[np.where(B.argsort() == (N-c-1))][0]))
                #print(f'    {l2} {u2}')
        print((u1+u2)-(l1+l2)+1)
    else:
        l = 10**9
        u = 0
        c = N//2
        for i in range(N):
            a = A[i]
            b = B[i]
            lower = np.count_nonzero(A<=b)
            upper = np.count_nonzero(B>=a)
            if lower >= c and upper >= c:
                #print(f'  {A[np.where(A.argsort() == c)][0]}')
                l = min(l, max(a, A[np.where(A.argsort() == c)][0]))
                #print(f'  {B[np.where(B.argsort() == (N-c-1))][0]}')
                u = max(u, min(b, B[np.where(B.argsort() == (N-c-1))][0]))
                #print(f'    {l} {u}')
        print(u-l+1)



main()

Submission status: Wrong Answer

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

al = []
bl = []
for a,b in ab:
  al.append(a)
  bl.append(b)
al.sort()
bl.sort()

if N%2 == 0:
  ans = ((bl[N//2] + bl[N//2 -1])//2 - (al[N//2] + al[N//2 -1])//2) *2 +1
else:
  ans = bl[N//2] - al[N//2] +1
print(ans)

Submission status: Wrong Answer

Solution code:
n = int(input())
a=[(0,0)]*n
b=0
for i in range(n):
    h,m=list(map(int,input().split()))
    a[i]=(h,m)
a=sorted(a,key=lambda g:g[0],reverse=True)
a=sorted(a,key=lambda g:g[1])
if n%2:
    k=(n-1)//2
    z=a[k][1]
    for i in range(k+1,n):
        z=min(z,a[i][1])
        
    print(z-a[k][0]+1)
else:
    k=n//2
    z=a[k-1][1]
    for i in range(k+1,n):
        z=min(z,a[i][1])
    if z==a[k-1][1]:
    
        print(a[k][1]+a[k-1][1]-(a[k][0]+a[k-1][0])+1)
    else:
        print(2*z-(a[k][0]+a[k-1][0])+1)

Submission status: Wrong Answer

Solution code:
n = int(input())
a=[(0,0)]*n
b=0
for i in range(n):
    h,m=list(map(int,input().split()))
    a[i]=(h,m)
a=sorted(a,key=lambda g:g[0],reverse=True)
a=sorted(a,key=lambda g:g[1])
if n%2:
    k=(n-1)//2
    print(a[k][1]-a[k][0]+1)
else:
    k=n//2
    print(a[k][1]+a[k-1][1]-(a[k][0]+a[k-1][0])+1)

Submission status: Wrong Answer

Solution code:
from statistics import median

t=int(input())
n=t
low=list()
high=list()
while t!=0:
     t-=1
     L,H=list(map(int,input().split()))
     low.append(L)
     high.append(H)
diff=int(median(high)-median(low))
if n%2 == 0:
     ans=(diff*2)+1
     print(ans)
else:
     ans=diff+1
     print(ans)

Submission status: Wrong Answer

Solution code:
N = int(input())
A = []
B = []
for i in range(N):
    a, b = map(int, input().split())
    A.append(a)
    B.append(b)
A.sort()
B.sort()
# print(A,B)
if N % 2 == 0:
    n = N // 2
    # print(B[-n] , A[n-1])
    print((B[-n] - A[n-1] + 1) * (B[-n] - A[n-1]) // 2)
else:
    n = N //2 + 1
    print((B[-n] - A[n-1] + 1))

Submission status: Wrong Answer

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

def med(s: list):
    n = len(s)
    s = sorted(s, reverse = True)
    return s[(n + 1) // 2 - 1] if n & 1 else (s[n // 2] + s[n // 2 - 1]) // 2

n = int(input())
a, b = [], []
for i in range(n):
    aa, bb = map(int, input().split())
    a.append(aa), b.append(bb)
ma, mb = med(a), med(b)
print((mb - ma) + 1 if n & 1 else (mb - ma) * 2 + 1)

Submission status: Wrong Answer

Solution code:
def main():
    n = int(input())
    a = [None]*n
    b = [None]*n
    for i in range(n):
        a[i],b[i] = map(int, input().split())
    a.sort()
    b.sort()    
    if n&1:
        print(b[n//2]-a[n//2]+1)
    else:
        print(b[n//2-1]+b[n//2]-a[n//2]+1)
            
if __name__ == "__main__":
    main()

Submission status: Wrong Answer

Solution code:
def main():
    n = int(input())
    a = [None]*n
    b = [None]*n
    for i in range(n):
        a[i], b[i] = map(int, input().split())
    if n&1:
        print(b[n//2]-a[n//2]+1)
    else:
        print(b[n//2-1]+b[n//2]-a[n//2-1]-a[n//2]+1)
        

if __name__ == "__main__":
    main()

Submission status: Wrong Answer

Solution code:
import statistics

N = int(input())
A = []
B = []
for i in range(N):
    a, b = map(int, input().split())
    A.append(a)
    B.append(b)
Am = statistics.median(A)
Bm = statistics.median(B)

if N % 2 == 0:
    print(round(2 * Bm - Am) + 1)
else:
    print(Bm - Am + 1)

Submission status: Wrong Answer

Solution code:
import statistics

N = int(input())
A = []
B = []
for i in range(N):
    a, b = list(map(int, input().split()))
    A.append(a)
    B.append(b)
Am = statistics.median(A)
Bm = statistics.median(B)

if N % 2 == 0:
    print(2 * round(Bm - Am) + 1)
else:
    print(Bm - Am + 1)

Submission status: Wrong Answer

Solution code:
import statistics
import math

N = int(input())
A = []
B = []
for i in range(N):
    a, b = list(map(int, input().split()))
    A.append(a)
    B.append(b)
Am = statistics.median(A)
Bm = statistics.median(B)

if N % 2 == 0:
    print(2 * round(Bm - Am) + 1)
else:
    print(round(Bm - Am) + 1)

Submission status: Wrong Answer

Solution code:
import statistics
import math

N = int(input())
A = []
B = []
for i in range(N):
    a, b = list(map(int, input().split()))
    A.append(a)
    B.append(b)
Am = statistics.median(A)
Bm = statistics.median(B)

print(Am)
print(Bm)

if N % 2 == 0:
    print(2 * round(Bm - Am) + 1)
else:
    print(round(Bm - Am) + 1)

Submission status: Wrong Answer

Solution code:
n=int(input())
a,b=[],[]
for i in range(n):
  inp=list(map(int,input().split()))
  a.append(inp[0])
  b.append(inp[1])
am=sum(a[(n-1)//2:n//2+1])
bm=sum(b[(n-1)//2:n//2+1])
print(bm-am+1)

Submission status: Wrong Answer

Solution code:
import statistics
import math

N = int(input())

min_x = []
max_x = []

for i in range(N):
    A, B = map(int, input().split())
    min_x.append(A)
    max_x.append(B)

min_x.sort()
max_x.sort()

result = []

if len(min_x) % 2 == 0:
    min_median = (min_x[len(min_x)//2-1] + min_x[len(min_x)//2]) / 2
    max_median = (max_x[len(min_x)//2-1] + max_x[len(min_x)//2]) / 2
    print(len(range(math.floor(min_median), math.ceil(max_median) + 1)))

else:
    min_median = min_x[len(min_x)//2]
    max_median = max_x[len(min_x)//2]
    print(len(range(min_median, max_median + 1)))

Submission status: Wrong Answer

Solution code:
from statistics import median

N = int(input())
A = [0] * N
B = [0] * N
max=0
min =0
for c in range(N):
    A[c], B[c] = map(int, input().split())

med_A = median(A)
med_B = median(B)

if N%2==0:
    print((med_B-med_A)*2+1)
else:
    print(med_B-med_A+1)

Submission status: Wrong Answer

Solution code:
from statistics import median

N = int(input())
A = [0] * N
B = [0] * N
for c in range(N):
    A[c], B[c] = map(int, input().split())

A_med = median(A)
B_med = median(B)

if N % 2 == 0:
    print(2 * (B_med - A_med) + 1)
else:
    print(B_med - A_med + 1)

Submission status: Wrong Answer

Solution code:
import statistics
N = int(input())
A = [list(map(int, input().split(" "))) for i in range(N)]
xMIN = []
xMAX = []


for i in range(N):
    xMIN.append(A[i][0])

for j in range(N):
    xMAX.append(A[j][1])


medianMIN = statistics.median(xMIN)
medianMAX = statistics.median(xMAX)

if N%2==0:
    print(int(medianMAX-medianMIN+2))
else:
    print(int(medianMAX-medianMIN+1))

Submission status: Wrong Answer

Solution code:
n = int(input())
X=[]
X1=[]
for i in range(n):
    a,b = map(int, input().split())
    X.append(a)
    X1.append(b)
X.sort()
X1.sort(reverse=True)
if n % 2: 
    print(X1[n//2] - X[n//2] + 1)
else: 
    print((X1[n//2]+X1[n//2-1]) - (X[n//2]+X1[n//2-1]) + 1)

Submission status: Wrong Answer

Solution code:
N=int(input())
X1=[]
X=[]
print(X1, X)
for i in range(N):
    x,r=map(int, input().split())
    X1.append(x)
    X.append(r)
X.sort()
X1.sort()
 
if N%2==0:
    print(X[N//2]+X[N//2-1]-X1[N//2]-X1[N//2-1]+1)    
else:
    print(X[N//2]-X1[N//2]+1)

Submission status: Wrong Answer

Solution code:
inp=int(input())
mylist=[]
mylist2=[]
print(mylist, mylist2)
for i in range(inp):
    x,r=map(int, input().split())
    mylist.append(x)
    mylist2.append(r)
mylist2.sort()
mylist.sort()
 
if inp%2==0:
    print(mylist2[inp//2]+mylist2[inp//2-1]-mylist[inp//2]-mylist[inp//2-1]+1)    
else:
    print(mylist2[inp//2]-mylist[inp//2]+1)

Submission status: Wrong Answer

Solution code:
inp=int(input())
mylist=[]
for i in range(inp):
    x,r = [int(num) for num in input().split()]
    mylist.append(x)
    mylist.append(r)
mylist.sort()    
mylis=len(mylist)
if len(mylist)%2==1:
    ans=(mylis-1)/2+1
    finalAns=mylist[int(ans-1)]
else:
    ans=(mylis/2)
    ans2=(mylis/2+1)
    finalAns=(mylist[int(ans-1)]+mylist[int(ans2-1)])/2
str=str(finalAns)+" "
if str.endswith('.0 ')==True:
    finalAns=int(finalAns)    
print(finalAns)

Submission status: Wrong Answer

Solution code:
N = int(input())
t = N // 2
a_list = []
b_list = []
for i in range(N):
    ab = list(map(int, input().split()))
    a_list.append(ab[0])
    b_list.append(ab[1])

if N%2 == 1:
    a_median = a_list[t]
    b_median = b_list[t]
    print(b_median-a_median+1)
elif N%2 == 0:
    a_median = (a_list[t-1]+a_list[t])/2
    b_median = (b_list[t-1]+b_list[t])/2
    print(int(2*(b_median-a_median)+1))

Submission status: Wrong Answer

Solution code:
import numpy as np

N = int(input())
a_list = []
b_list = []
for i in range(N):
    ab = list(map(int, input().split()))
    a_list.append(ab[0])
    b_list.append(ab[1])

if N%2 == 1:
    a_median = np.median(a_list).astype('int')
    b_median = np.median(b_list).astype('int')
    print(b_median-a_median+1)
elif N%2 == 0:
    a_median = np.median(a_list).astype('int')
    b_median = np.median(b_list).astype('int')
    print(2*(b_median-a_median)+1)

Submission status: Wrong Answer

Solution code:
import numpy as np

N = int(input())
a_list = []
b_list = []
for i in range(N):
    ab = list(map(int, input().split()))
    a_list.append(ab[0])
    b_list.append(ab[1])

if N%2 == 1:
    a_median = np.median(a_list)
    b_median = np.median(b_list)
    print(b_median-a_median+1)
elif N%2 == 0:
    a_median = np.median(a_list)
    b_median = np.median(b_list)
    print(2*(b_median-a_median)+1)

Submission status: Wrong Answer

Solution code:
import numpy as np

N = int(input())
a_list = []
b_list = []
for i in range(N):
    ab = list(map(int, input().split()))
    a_list.append(ab[0])
    b_list.append(ab[1])

if N%2 == 1:
    a_median = np.median(a_list).astype('int')
    b_median = np.median(b_list).astype('int')
    print(b_median-a_median+1)
elif N%2 == 0:
    a_median = np.median(a_list).astype('int')
    b_median = np.median(b_list).astype('int')
    print(2*(b_median-a_median+1))

Submission status: Wrong Answer

Solution code:
n = int(input())
al = []
bl = []
for _ in range(n):
    a, b = map(int, input().split()) 
    al.append(a)
    bl.append(b)

al.sort()
bl.sort()


if n%2 == 1:
    print(bl[n//2] - al[n//2] + 1)
else:
    print((bl[n//2] - al[n//2-1])*2 + 1)

Submission status: Wrong Answer

Solution code:
N = int(input())
l = []
for _ in range(N):
    A, B = map(int, input().split())
    l.append((A, B))

t = N//2
tl = sorted(l)
tr = sorted(l, key=lambda x:-x[1])

if N%2:
    print(tr[t][1]-tl[t][0]+1)
else:
    # a1, a2 = tl[t][0], tr[t][1]
    a3, a4 = tl[t-1][0], tr[t-1][1]
    print((a4-a3+1)*(a4-a3)//2)

Submission status: Wrong Answer

Solution code:
N = int(input())
l = []
for _ in range(N):
    A, B = map(int, input().split())
    l.append((A, B))

t = N//2
tl = sorted(l)
tr = sorted(l, key=lambda x:-x[1])

if N%2:
    print(tr[t][1]-tl[t][0]+1)
else:
    a1, a2 = tl[t][0], tr[t][1]
    a3, a4 = tl[t-1][0], tr[t-1][1]
    print((a2-a1+1)*(a4-a3+1))

Submission status: Wrong Answer

Solution code:
N = int(input())
l = []
for _ in range(N):
    A, B = map(int, input().split())
    l.append((A, B))

t = N//2
tl = sorted(l)
tr = sorted(l, key=lambda x:-x[1])

if N%2:
    print(tr[t][1]-tl[t][0]+1)
else:
    a1, a2 = tl[t-1][0], tr[t][1]
    a3, a4 = tl[t][0], tr[t-1][1]
    v1 = (a2-a1+1)*(a4-a3+1)
    v2 = (a2-a3+1)*(a2-a3+1) if a3<=a2 else 0
    print(v1-v2)

Submission status: Wrong Answer

Solution code:
N = int(input())
l = []
for _ in range(N):
    A, B = map(int, input().split())
    l.append((A, B))

t = N//2
tl = sorted(l)
tr = sorted(l, key=lambda x:-x[1])

if N%2:
    print(tr[t][1]-tl[t][0]+1)
else:
    print(1)

Submission status: Wrong Answer

Solution code:
from statistics import*
(n,),*t=[map(int,t.split())for t in open(0)]
a,b=map(median,zip(*t))
print(int(b-a)*(2-n%2)+1)

Submission status: Wrong Answer

Solution code:
from statistics import*
(n,),*t=[map(int,t.split())for t in open(0)]
a,b=map(median,zip(*t))
print(int(b-a+2-n%2))

Submission status: Wrong Answer

Solution code:
n=int(input())
l=[list(map(int,input().split())) for i in range(n)]
work1=[x[0] for x in l]
work2=[x[1] for x in l]
if n%2==1 : 
    mmin=work1[n//2]
    mmax=work2[n//2]
else:
    mmin=work1[n//2]+work1[n//2-1]
    mmax=work2[n//2]+work2[n//2-1]
print(mmax-mmin+1)

Submission status: Wrong Answer

Solution code:
from sys import stdin
from statistics import median


def main():
    i = 0
    n = 10**10
    a = []
    b = []
    for line in stdin:
        if i == 0:
            n = int(line)
            i += 1
            continue
        (ai, bi) = line.split()
        a.append(int(ai))
        b.append(int(bi))
        i += 1
        if i > n:
            break

    a_mid = median(a)
    b_mid = median(b)

    if n % 2 == 0:
        print((b_mid - a_mid) * 2 + 1)
    else:
        print(b_mid - a_mid + 1)

main()

Submission status: Wrong Answer

Solution code:
from sys import stdin
from statistics import median


def main():
    i = 0
    n = 10**10
    a = []
    b = []
    for line in stdin:
        if i == 0:
            n = int(line)
            i += 1
            continue
        (ai, bi) = line.split()
        a.append(int(ai))
        b.append(int(bi))
        i += 1
        if i > n:
            break

    a_mid = median(a)
    b_mid = median(b)
    if a_mid == b_mid:
        print(1)
        return
    if b_mid - a_mid < 1:
        print(3)
        return
    if n % 2 == 0:
        print(int(b_mid - a_mid) * 2 + 1)
    else:
        print(int(b_mid - a_mid) + 1)

main()

Submission status: Wrong Answer

Solution code:
from sys import stdin
from statistics import median


def main():
    i = 0
    n = 10**10
    a = []
    b = []
    for line in stdin:
        if i == 0:
            n = int(line)
            i += 1
            continue
        (ai, bi) = line.split()
        a.append(int(ai))
        b.append(int(bi))
        i += 1
        if i > n:
            break

    a_mid = median(a)
    b_mid = median(b)
    if a_mid == b_mid:
        print(1)
        return
    if b_mid - a_mid < 1:
        print(2)
        return
    if n % 2 == 0:
        print(int(b_mid - a_mid) * 2 + 1)
    else:
        print(int(b_mid - a_mid) + 1)

main()

Submission status: Wrong Answer

Solution code:
from sys import stdin
from statistics import median


def main():
    i = 0
    n = 10**10
    a = []
    b = []
    for line in stdin:
        if i == 0:
            n = int(line)
            i += 1
            continue
        (ai, bi) = line.split()
        a.append(int(ai))
        b.append(int(bi))
        i += 1
        if i > n:
            break

    a_mid = median(a)
    b_mid = median(b)
    if n % 2 == 0:
        print(int(b_mid - a_mid) * 2 + 1)
    else:
        print(int(b_mid - a_mid) + 1)

main()

Submission status: Wrong Answer

Solution code:
N = int(input())
A = []
B = []
for i in range(N):
    a,b = input().split()
    A.append(int(a))
    B.append(int(b))
A.sort()
B.sort(reverse = True)
minnum = A[0]
maxnum = B[0] 
if N%2!=0:
  ans = maxnum - minnum +1
else:
  ans = 2*(maxnum - minnum) -1
print(ans)

Submission status: Wrong Answer

Solution code:
n = int(input())
a, b = [0] * n, [0] * n
for i in range(n):
    a[i], b[i] = map(int, input().split())
a.sort()
b.sort()
if n % 2:
    under = a[n // 2]
    upper = b[n // 2]
    print(upper - under + 1)
else:
    under = (a[n // 2 - 1] + a[n // 2]) // 2
    upper = (b[n // 2 - 1] + b[n // 2]) // 2
    print((upper - under) * 2 + 1)
"""
# 　どのx　もその中に持てない区間が何個あるかを累積和で持っておく。
aa, ba, aidx = zip(*sorted(zip(a, b, range(n))))  # aでソート
bb, ab, bidx = zip(*sorted(zip(b, a, range(n))))  # aでソート

if n % 2:
    print(bb[n // 2] - aa[n // 2] + 1)
else:
    if aidx[n // 2 - 1] == bidx[n // 2]:
        ans = (bb[n // 2 - 1] - aa[n // 2 - 1] + 1) * (bb[n // 2] - aa[n // 2] + 1)
    else:
        ans = (bb[n // 2 - 1] - aa[n // 2 - 1] + 1) * (bb[n // 2 - 1] - aa[n // 2] + 1)
    print(ans)"""

Submission status: Wrong Answer

Solution code:
n=int(input())
AB=[list(map(int,input().split())) for _ in range(n)]

if n % 2 == 1:
  mid=(n+1)//2
  print(AB[mid-1][1]-AB[mid-1][0]+1)
else:
  mid=n//2
  print(AB[mid][1]+AB[mid-1][1]-AB[mid][0]-AB[mid-1][0]+1)

Submission status: Wrong Answer

Solution code:
N = int(input())
A = []
B = []
for _ in range(N):
  a,b = [int(i) for i in input().split()]
  A.append(a)
  B.append(b)
A.reverse()
B.reverse()
if N%2 == 1:
  M = ((N+1)//2)-1
  print(B[M]-A[M]+1)
  exit()
M = (N//2)-1
L = (N//2)
print(B[M]+B[L]-A[M]-A[L]+1)

Submission status: Wrong Answer

Solution code:
N = int(input())
A = []
B = []
for i in range(N):
    a, b = map(int, input().split())
    A.append(a)
    B.append(b)
A.sort()
B.sort()
    
if(N%2 != 0):    
    print(B[N//2+1]-A[N//2+1]+1)
else:
    print(B[N//2]+B[N//2-1] - A[N//2]-A[N//2-1] + 1)

Submission status: Wrong Answer

Solution code:
import sys

# import re
import math
import collections
# import decimal
import bisect
import itertools
import fractions
# import functools
import copy
import heapq
import decimal
# import statistics
import queue
import numpy as np

sys.setrecursionlimit(10000001)
INF = 10 ** 16
MOD = 10 ** 9 + 7

ni = lambda: int(sys.stdin.readline())
ns = lambda: map(int, sys.stdin.readline().split())
na = lambda: list(map(int, sys.stdin.readline().split()))


# ===CODE===


def main():
    n = ni()
    a = []
    b = []
    a_total = 0
    b_total = 0
    for _ in range(n):
        ai, bi = ns()
        a.append(ai)
        b.append(bi)
        a_total += ai
        b_total += bi

    if n % 2:
        ans = b[n // 2] - a[n // 2] + 1
    else:
        ans = b[n // 2] + b[n // 2 - 1] - (a[n // 2] + a[n // 2 - 1]) + 1
    print(ans)


if __name__ == '__main__':
    main()

Submission status: Wrong Answer

Solution code:
import sys

# import re
import math
import collections
# import decimal
import bisect
import itertools
import fractions
# import functools
import copy
import heapq
import decimal
# import statistics
import queue
import numpy as np

sys.setrecursionlimit(10000001)
INF = 10 ** 16
MOD = 10 ** 9 + 7

ni = lambda: int(sys.stdin.readline())
ns = lambda: map(int, sys.stdin.readline().split())
na = lambda: list(map(int, sys.stdin.readline().split()))


# ===CODE===


def main():
    n = ni()
    a = []
    b = []
    a_total = 0
    b_total = 0
    for _ in range(n):
        ai, bi = ns()
        a.append(ai)
        b.append(bi)
        a_total += ai
        b_total += bi

    if n % 2:
        ans = b[n // 2] - a[n // 2] + 1
    else:
        ans = (b[n // 2] - a[n // 2]) * 2 + 1
    print(ans)


if __name__ == '__main__':
    main()

Submission status: Wrong Answer

Solution code:
n=int(input())

a = [0]*n
b = [0]*n
 
for i in range(n):
    a[i], b[i] = map(int, input().split())

a.sort()
b.sort()

youso = int(n/2)

if n % 2 != 0:
    print(b[youso]-a[youso]+1)
else:
    print((b[youso]+b[youso-1])//2-(a[youso]+a[youso-1])//2+2)

Submission status: Wrong Answer

Solution code:
n=int(input())
for i in range(n):
  a,b=map(int,input().split())
print(134)

Submission status: Wrong Answer

Solution code:
import sys
input = lambda: sys.stdin.readline().rstrip()

n = int(input())
a = []
b = []
for _ in range(n):
    a_, b_ = map(int, input().split())
    a.append(a_)
    b.append(b_)
a.sort()
b.sort()
if n % 2 == 1:
    a_m = a[n // 2]
    b_m = b[n // 2]
    print(b_m - a_m + 1)
else:
    a_m = (a[n // 2 - 1] + a[n // 2]) / 2
    b_m = (b[n // 2 - 1] + b[n // 2]) / 2
    print(int(b_m - a_m) * 2 + 1)

Submission status: Wrong Answer

Solution code:
import math
n = int(input())
a = []
b = []
for i in range(n):
    x, y = map(int, input().split())
    a.append(x)
    b.append(y)

res = 0
if n % 2 == 1:
    m = n // 2
    m1 = a[m]
    m2 = b[m]
    res = m2 - m1 + 1
else:
    ml = n // 2 - 1
    m1 = a[ml] + a[ml + 1]
    m2 = b[ml] + b[ml + 1]
    res = m2 - m1 + 1

print(res)

Submission status: Wrong Answer

Solution code:
N = int(input())
AB = []
for _ in range(N):
    AB.append(list(map(int, input().split())))
if N % 2 == 1:
    idx = N // 2
    ans = AB[idx][1] - AB[idx][0] + 1
else:
    idx1 = (N-1) // 2
    idx2 = (N-1) //2 + 1
    lower_bound = AB[idx1][0] + AB[idx2][0]
    upper_bbound = AB[idx1][1] + AB[idx2][1]
    diff = upper_bbound - lower_bound + 1
    ans = diff
print(ans)

Submission status: Wrong Answer

Solution code:
import statistics
import math

N = int(input())
A_B = [[int(i) for i in input().split(' ')] for n in range(N)]

t = list(zip(*A_B))

A_sta = statistics.median(t[0])
B_sta = statistics.median(t[1])

if N % 2 == 0:
    count = 2 * (B_sta - A_sta + 1)
else:
    count = B_sta - A_sta + 1

print(count)

Submission status: Wrong Answer

Solution code:
def main():
    n = int(input())
    al = []
    bl = []
    for _ in range(n):
        a, b = map(int, input().split())
        al.append(a)
        bl.append(b)
    if n%2:
        print(bl[n//2]-al[n//2]+1)
    else:
        print(bl[n//2]+bl[n//2-1]-al[n//2]-al[n//2-1]+1)

if __name__ == "__main__":
    main()

Submission status: Wrong Answer

Solution code:
N = int(input())
A = [0] * (N + 1)
B = [0] * (N + 1)

count = 0

for i in range(1, N + 1):
  A[i], B[i] = map(int, input().split())

if N % 2 == 1:
  centerA = int(A[(N + 1) // 2])
  centerB = int(B[(N + 1) // 2])
else:
  centerA = (A[N // 2] + A[N // 2 + 1]) / 2
  centerB = (B[N // 2] + B[N // 2 + 1]) / 2

#print(centerA, centerB)  

if N % 2 == 1:
  count = int(centerB) - int(centerA) + 1
else:
  count = int(centerB * 2) - int(centerA * 2) + 1

print(int(count))

Submission status: Wrong Answer

Solution code:
N = int(input())
A = [0] * (N + 1)
B = [0] * (N + 1)

count = 0

for i in range(1, N + 1):
  A[i], B[i] = map(int, input().split())

if N % 2 == 1:
  centerA = A[(N + 1) // 2]
  centerB = B[(N + 1) // 2]
else:
  centerA = (A[N // 2] + A[N // 2 + 1]) / 2
  centerB = (B[N // 2] + B[N // 2 + 1]) / 2

#print(centerA, centerB)  

if N % 2 == 1:
  count = centerB - centerA + 1
else:
  count = int(centerB * 2) - int(centerA * 2) + 1

print(int(count))

Submission status: Wrong Answer

Solution code:
N = int(input())
A = [0] * (N + 1)
B = [0] * (N + 1)

count = 0

for i in range(1, N + 1):
  A[i], B[i] = map(int, input().split())

if N % 2 == 1:
  centerA = A[(N + 1) // 2]
  centerB = B[(N + 1) // 2]
else:
  centerA = (A[N // 2] + A[N // 2 + 1]) / 2
  centerB = (B[N // 2] + B[N // 2 + 1]) / 2

#print(centerA, centerB)  

if N % 2 == 1:
  count = centerB - centerA + 1
else:
  count = (centerB - centerA) * 2 + 1

print(int(count))