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:
from collections import defaultdict
from fractions import Fraction
N = int(input())
A = [0 for  _ in range(N)]
B = [0 for  _ in range(N)]
for i in range(N):
    A[i], B[i] = [int(i) for i in input().split()]
A.sort()
B.sort()

if N%2 == 1:
    target = ((N+1)//2)-1
    print(B[target]-A[target]+1)
else:
    target1 = ((N)//2)-1
    target2 = (N)//2
    print((B[target2]-A[target1]) * 2-1)

Submission status: Wrong Answer

Solution code:
from collections import defaultdict
from fractions import Fraction
N = int(input())
A = [0 for  _ in range(N)]
B = [0 for  _ in range(N)]
for i in range(N):
    A[i], B[i] = [int(i) for i in input().split()]
A.sort()
B.sort()
print(A)
print(B)
if N%2 == 1:
    target = ((N+1)//2)-1
    print(B[target]-A[target]+1)
else:
    target1 = ((N)//2)-1
    target2 = (N)//2
    d = defaultdict(int)
    for i in range(A[target1] , B[target1]+1):
        for j in range(A[target2] , B[target2]+1):
            d[(i+j)/2] += 1
    print(len(d.keys()))

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=sorted(a)
b=sorted(b)

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

print(ans)

Submission status: Wrong Answer

Solution code:
import numpy as np

        
n = int(input())

a = np.zeros(n,dtype=int)
b = np.zeros(n,dtype=int)

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

#listをsortする
if n==2:
    a0 = [a[0]]
    b0 = [b[0]]
    if a[1]>=a[0]:
        a0.append(a[1])
    else:
        a0.insert(0,a[1])
    if b[1]>=a[0]:
        b0.append(b[1])
    else:
        b0.insert(0,b[1])
else:
    a0 = [a[0]]
    b0 = [b[0]]
    if a[1]>=a[0]:
        a0.append(a[1])
    else:
        a0.insert(0,a[1])
    if b[1]>=a[0]:
        b0.append(b[1])
    else:
        b0.insert(0,b[1])    
    for i in range(2,n):
        if a[i]>=a0[len(a0)-1]:
            a0.append(a[i])
        elif a[i]<=a0[0]:
            a0.insert(0,a[i])
        else:
            for j in range(len(a0)-1):
                if a0[j]<=a[i] and a[i]<=a0[j+1]:
                    a0.insert(j+1,a[i])
        if b[i]>=b0[len(b0)-1]:
            b0.append(b[i])
        elif b[i]<=b0[0]:
            b0.insert(0,b[i])
        else:
            for j in range(len(b0)-1):
                if b0[j]<=b[i] and b[i]<=b0[j+1]:
                    b0.insert(j+1,b[i])

                    
if n%2 == 1:
    a0cen = a0[(n-1)//2]
    b0cen = b0[(n-1)//2]
    nn = b0cen - a0cen + 1
else:
    a0cen1 = a0[(n-2)//2]+a0[n//2]
    b0cen1 = b0[(n-2)//2]+b0[n//2]
    nn = int(b0cen1 -a0cen1 +1)

print(nn)

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

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

def m_r(c):
    return (c[n//2] + c[n//2 - 1])

z = m_r(b) - m_r(a) + 1
print(z)

Submission status: Wrong Answer

Solution code:
# -*- coding: utf-8 -*-
# 整数の入力
import math
import numpy as np

if __name__ == "__main__":
    N = int(input())
    A = []
    B = []
    for i in range(N):
        t = list(map(int, input().split()))
        A.append(t[0])
        B.append(t[1])
    A.sort()
    B.sort()

    a = 0
    if N % 2 == 0:
        i = N // 2
        j = N // 2 - 1
        a = A[j] + B[i]
        b = B[j] + B[i]
        print(b - a + 1)
    else:
        i = N // 2
        a = B[i] - A[i] + 1

        print(a)

Submission status: Wrong Answer

Solution code:
import numpy as np

        
n = int(input())

a = np.zeros(n,dtype=int)
b = np.zeros(n,dtype=int)

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

#listをsortする
if n == 1:
    a0 = [a[0]]
    b0 = [b[0]]
elif n==2:
    a0 = [a[0]]
    b0 = [b[0]]
    if a[1]>=a[0]:
        a0.append(a[1])
    else:
        a0.insert(0,a[1])
    if b[1]>=a[0]:
        b0.append(b[1])
    else:
        b0.insert(0,b[1])
else:
    a0 = [a[0]]
    b0 = [b[0]]
    if a[1]>=a[0]:
        a0.append(a[1])
    else:
        a0.insert(0,a[1])
    if b[1]>=a[0]:
        b0.append(b[1])
    else:
        b0.insert(0,b[1])    
    for i in range(2,n):
        if a[i]>=a0[len(a0)-1]:
            a0.append(a[i])
        elif a[i]<=a0[0]:
            a0.insert(0,a[i])
        else:
            for j in range(len(a0)-1):
                if a0[j]<=a[i] and a[i]<=a0[j+1]:
                    a0.insert(j+1,a[i])
        if b[i]>=b0[len(b0)-1]:
            b0.append(b[i])
        elif b[i]<=b0[0]:
            b0.insert(0,b[i])
        else:
            for j in range(len(b0)-1):
                if b0[j]<=b[i] and b[i]<=b0[j+1]:
                    b0.insert(j+1,b[i])

                    
if n%2 == 1:
    a0cen = a0[int((n-1)/2)]
    b0cen = b0[int((n-1)/2)]
    nn = b0cen - a0cen + 1
else:
    a0cen1 = a0[int((n-2)/2)]+a0[int(n/2)]
    b0cen1 = b0[int((n-2)/2)]+b0[int(n/2)]
    nn = int(b0cen1 -a0cen1 +1)

print(nn)

Submission status: Wrong Answer

Solution code:
import numpy as np

        
n = int(input())

a = np.zeros(n,dtype=int)
b = np.zeros(n,dtype=int)

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

#listをsortする
if n == 1:
    a0 = [a[0]]
    b0 = [b[0]]
elif n==2:
    a0 = [a[0]]
    b0 = [b[0]]
    if a[1]>=a[0]:
        a0.append(a[1])
    else:
        a0.insert(0,a[1])
    if b[1]>=a[0]:
        b0.append(b[1])
    else:
        b0.insert(0,b[1])
else:
    a0 = [a[0]]
    b0 = [b[0]]
    if a[1]>=a[0]:
        a0.append(a[1])
    else:
        a0.insert(0,a[1])
    if b[1]>=a[0]:
        b0.append(b[1])
    else:
        b0.insert(0,b[1])    
    for i in range(2,n):
        if a[i]>=a0[len(a0)-1]:
            a0.append(a[i])
        elif a[i]<=a0[0]:
            a0.insert(0,a[i])
        else:
            for j in range(len(a0)-1):
                if a0[j]<=a[i] and a[i]<=a0[j+1]:
                    a0.insert(j+1,a[i])
        if b[i]>=b0[len(b0)-1]:
            b0.append(b[i])
        elif b[i]<=b0[0]:
            b0.insert(0,b[i])
        else:
            for j in range(len(b0)-1):
                if b0[j]<=b[i] and b[i]<=b0[j+1]:
                    b0.insert(j+1,b[i])

                    
if n%2 == 1:
    a0cen = a0[int((n-1)/2)]
    b0cen = b0[int((n-1)/2)]
    nn = b0cen - a0cen + 1
else:
    a0cen = (a0[int((n-2)/2)]+a0[int(n/2)])/2
    b0cen = (b0[int((n-2)/2)]+b0[int(n/2)])/2
    nn = int(2*b0cen -2*a0cen +1)

print(nn)

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:
    n=(N+1)//2
    ans=B[n-1]-A[n-1]+1
else:
    n=N//2
    ans1=(A[n-1]+A[n])/2
    ans2=(B[n-1]+B[n])/2
    ans=(ans2-ans1)*2+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()
if N%2!=0:
    n=(N+1)//2
    ans=B[n-1]-A[n-1]+1
else:
    n=N//2
    ans1=(A[n-1]+A[n])//2
    ans2=(B[n-1]+B[n])//2
    ans=(ans2-ans1)*2+1
print(ans)

Submission status: Wrong Answer

Solution code:
def main():
    N = int(input())  # 文字列または整数(一変数)

    mins = []
    maxs = []

    for i in range(N):
        a, b = map(int, input().split())
        mins.append(a)
        maxs.append(b)

    mins.sort()
    maxs.sort()

    if N % 2 == 1:
        # 奇数の場合
        mid = N // 2
        print(maxs[mid] - mins[mid] + 1)

    else:
        mid1 = (N-1) // 2
        mid2 = mid1 - 1
        smallest = mins[mid1] + mins[mid2]
        largest = maxs[mid1] + maxs[mid2]
        print(largest - smallest + 1)


if __name__ == '__main__':
    main()

Submission status: Wrong Answer

Solution code:
# -*- coding: utf-8 -*-
# 整数の入力
import math
import numpy as np

if __name__ == "__main__":
    N = int(input())
    AB = []
    for i in range(N):
        AB.append(list(map(int, input().split())))

    a = 0
    if N % 2 == 0:
        i = N // 2
        j = N // 2 - 1
        a = AB[j][0] + AB[i][0]
        b = AB[j][1] + AB[i][1]
        print(b - a + 1)
    else:
        i = N // 2
        a = AB[i][1] - AB[i][0] + 1

        print(a)

Submission status: Wrong Answer

Solution code:
# -*- coding: utf-8 -*-
# 整数の入力
import math
import numpy as np

if __name__ == "__main__":
    N = int(input())
    AB = []
    for i in range(N):
        AB.append(list(map(int, input().split())))

    a = 0
    if N % 2 == 0:
        i = N // 2
        j = N // 2 - 1
        a = AB[j][0] + AB[i][0]
        b = AB[j][1] + AB[i][1]
        print(i, j, a,b )
        print(b - a + 1)
    else:
        i = N // 2
        a = AB[i][1] - AB[i][0] + 1

        print(a)
    
    print('end')

Submission status: Wrong Answer

Solution code:
from math import ceil, floor

N = int(input())

A, B = [], []
for i in range(N):
    _a, _b = [int(x) for x in input().split()]
    A.append(_a)
    B.append(_b)

A.sort()
B.sort()

min_mid, max_mid = 0, 0
if N % 2 != 0:
    mid = int((N-1)/2)
    min_mid, max_mid = A[mid], B[mid]
else:
    mid = int(N / 2)
    min_mid = floor((A[mid-1] + A[mid]) / 2)
    max_mid = ceil((B[mid-1] + B[mid]) / 2)

res = str(max_mid - min_mid + 1)
print(res)

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

sorted_A = A
sorted_B = B

if N % 2 != 0:
  center_A = sorted_A[N//2]
  center_B = sorted_B[N//2]
  print(abs(center_B - center_A) + 1)
else:
  center_A = (sorted_A[N//2-1] + sorted_A[N//2]) //2
  center_B = (sorted_B[N//2-1] + sorted_B[N//2]) //2
  print(abs(center_B - center_A)*2 + 1)

Submission status: Wrong Answer

Solution code:
N = int(input())
A = []
B = []

for i in range(N):
  hoge = input().split()
  A.append(int(hoge[0]))
  B.append(int(hoge[1]))

sorted_A = sorted(A)
sorted_B = sorted(B)

if N % 2 != 0:
  center_A = sorted_A[N//2]
  center_B = sorted_B[N//2]
  print(abs(center_B - center_A) + 1)
else:
  center_A = (sorted_A[N//2-1] + sorted_A[N//2]) //2
  center_B = (sorted_B[N//2-1] + sorted_B[N//2]) //2
  print(abs(center_B - center_A)*2 + 1)

Submission status: Wrong Answer

Solution code:
N = int(input())
A = []
B = []

for i in range(N):
  hoge = input().split()
  A.append(int(hoge[0]))
  B.append(int(hoge[1]))

sorted_A = sorted(A)
sorted_B = sorted(B)

if N % 2 != 0:
  center_A = sorted_A[(N+1)//2-1]
  center_B = sorted_B[(N+1)//2-1]
  print(abs(center_A - center_B) + 1)
else:
  center_A = (sorted_A[N//2-1] + sorted_A[N//2]) //2
  center_B = (sorted_B[N//2-1] + sorted_B[N//2]) //2
  print(abs(center_A - center_B)*2 + 1)

Submission status: Wrong Answer

Solution code:
def main():
    n = int(input())
    A = []
    B = []
    for _ in range(n):
        a, b = map(int, input().split())
        A += [a]
        B += [b]
    A.sort()
    B.sort()
    if n % 2 == 0:
        mid_pos = n // 2
        mid_A = (A[mid_pos - 1] + A[mid_pos]) // 2
        mid_B = (B[mid_pos - 1] + B[mid_pos]) // 2
        cnt = (mid_B - mid_A) * 2 + 1
    else:
        mid_pos = (n + 1) // 2 - 1
        mid_A = A[mid_pos]
        mid_B = B[mid_pos]
        cnt = mid_B - mid_A + 1
    print(cnt)

if __name__ == "__main__":
    main()

Submission status: Wrong Answer

Solution code:
def main():
    n = int(input())
    A = []
    B = []
    for _ in range(n):
        a, b = map(int, input().split())
        A += [a]
        B += [b]
    if n % 2 == 0:
        mid_pos = n // 2
        mid_A = (A[mid_pos - 1] + A[mid_pos]) // 2
        mid_B = (B[mid_pos - 1] + B[mid_pos]) // 2
        cnt = (mid_B - mid_A) * 2 + 1
    else:
        mid_pos = (n + 1) // 2 - 1
        mid_A = A[mid_pos]
        mid_B = B[mid_pos]
        cnt = mid_B - mid_A + 1
    print(cnt)



if __name__ == "__main__":
    main()

Submission status: Wrong Answer

Solution code:
import sys
import  math
import fractions
from collections import defaultdict
stdin = sys.stdin
     
ns = lambda: stdin.readline().rstrip()
ni = lambda: int(stdin.readline().rstrip())
nm = lambda: map(int, stdin.readline().split())
nl = lambda: list(map(int, stdin.readline().split()))


N=int(input())
min_l=[]
max_l=[]
for k in range(N):
    A,B=nm()
    min_l.append(A)
    max_l.append(B)

min_l.sort()
max_l.sort()

if(N%2==0):
    print(((max_l[N//2-1]+max_l[N//2])/2-(min_l[N//2-1]+min_l[N//2])/2)*2+1)    
else:
    print(((max_l[(N-1)//2])-(min_l[(N-1)//2]))+1)

Submission status: Wrong Answer

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


if N % 2 == 0:
    maxab = ab[(N // 2) - 1][1]
    minab = ab[N // 2][0]
    x1 = (ab[(N // 2) - 1][0] + ab[N // 2][0])
    x2 = (ab[(N // 2) - 1][1] + ab[N // 2][1])
    print(x2 - x1 + 1)

else:
    print(ab[N // 2][1] - ab[N // 2][0] + 1)

Submission status: Wrong Answer

Solution code:
import sys
import math
from decimal import Decimal, ROUND_HALF_UP, ROUND_HALF_EVEN
from collections import deque
from bisect import bisect_left
from itertools import product
def I(): 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 LI2(N): return [list(map(int, sys.stdin.readline().split())) for i in range(N)]
#文字列を一文字ずつ数字に変換、'5678'を[5,6,7,8]とできる
def LSI(): return list(map(int, list(sys.stdin.readline().rstrip())))
def LSI2(N): return [list(map(int, list(sys.stdin.readline().rstrip()))) for i in range(N)]
#文字列として取得
def ST(): return sys.stdin.readline().rstrip()
def LST(): return sys.stdin.readline().rstrip().split()
def LST2(N): return [sys.stdin.readline().rstrip().split() for i in range(N)]
def FILL(i,h): return [i for j in range(h)]
def FILL2(i,h,w): return [FILL(i,w) for j in range(h)]
def FILL3(i,h,w,d): return [FILL2(i,w,d) for j in range(h)]
def FILL4(i,h,w,d,d2): return [FILL3(i,w,d,d2) for j in range(h)]
def sisha(num,digit): return Decimal(str(num)).quantize(Decimal(digit),rounding=ROUND_HALF_UP)
#'0.01'や'1E1'などで指定、整数に戻すならintをかます
MOD = 1000000007
INF = float("inf")
sys.setrecursionlimit(10**6+10)

N = I()
L = LI2(N)
A = [i[0] for i in L]
B = [i[1] for i in L]
A.sort()
B.sort()
if N%2==0:
    medA = (A[N//2-1]+A[N//2])/2
    medB = (B[N//2-1]+B[N//2])/2
    print(int(medB-medA+0.1)*2+1)
else:
    medA = A[(N-1)//2]
    medB = B[(N-1)//2]
    print(medB-medA+1)

Submission status: Wrong Answer

Solution code:
import sys
import math
from decimal import Decimal, ROUND_HALF_UP, ROUND_HALF_EVEN
from collections import deque
from bisect import bisect_left
from itertools import product
def I(): 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 LI2(N): return [list(map(int, sys.stdin.readline().split())) for i in range(N)]
#文字列を一文字ずつ数字に変換、'5678'を[5,6,7,8]とできる
def LSI(): return list(map(int, list(sys.stdin.readline().rstrip())))
def LSI2(N): return [list(map(int, list(sys.stdin.readline().rstrip()))) for i in range(N)]
#文字列として取得
def ST(): return sys.stdin.readline().rstrip()
def LST(): return sys.stdin.readline().rstrip().split()
def LST2(N): return [sys.stdin.readline().rstrip().split() for i in range(N)]
def FILL(i,h): return [i for j in range(h)]
def FILL2(i,h,w): return [FILL(i,w) for j in range(h)]
def FILL3(i,h,w,d): return [FILL2(i,w,d) for j in range(h)]
def FILL4(i,h,w,d,d2): return [FILL3(i,w,d,d2) for j in range(h)]
def sisha(num,digit): return Decimal(str(num)).quantize(Decimal(digit),rounding=ROUND_HALF_UP)
#'0.01'や'1E1'などで指定、整数に戻すならintをかます
MOD = 1000000007
INF = float("inf")
sys.setrecursionlimit(10**6+10)

N = I()
L = LI2(N)
A = [i[0] for i in L]
B = [i[1] for i in L]
A.sort()
B.sort()
if N%2==0:
    medA = (A[N//2-1]+A[N//2])//2
    medB = (B[N//2-1]+B[N//2])//2
    print((medB-medA)*2+1)
else:
    medA = A[(N-1)//2]
    medB = B[(N-1)//2]
    print(medB-medA+1)

Submission status: Wrong Answer

Solution code:
n = int(input())

ls = []
rs = []
for _ in range(n):
    x, y = map(int, input().split())
    ls.append(x)
    rs.append(y)

if n % 2 == 1:
    print(rs[len(rs)//2] - ls[len(ls)//2] + 1)
else:
    a = (rs[len(rs)//2-1] * 10 + rs[len(rs)//2] * 10) // 2
    b = (ls[len(ls)//2-1] * 10 + ls[len(ls)//2] * 10) // 2
    print((a - b) // 5 + 1)

Submission status: Wrong Answer

Solution code:
n = int(input())

ls = []
rs = []
for _ in range(n):
    x, y = map(int, input().split())
    ls.append(x)
    rs.append(y)

if n % 2 == 1:
    print(rs[len(rs)//2] - ls[len(ls)//2] + 1)
else:
    a = (rs[len(rs)//2-1] * 10 + rs[len(rs)//2] * 10) / 2
    b = (ls[len(ls)//2-1] * 10 + ls[len(ls)//2] * 10) / 2
    print(int((a - b) // 5 + 1))

Submission status: Wrong Answer

Solution code:
n = int(input())

ls = []
rs = []
for _ in range(n):
    x, y = map(int, input().split())
    ls.append(x)
    rs.append(y)

if n % 2 == 1:
    print(rs[len(rs)//2] - ls[len(ls)//2] + 1)
else:
    a = (rs[len(rs)//2-1] * 10 + rs[len(rs)//2] * 10) / 2
    b = (ls[len(ls)//2-1] * 10 + ls[len(ls)//2] * 10) / 2
    print((a - b) // 5 + 1)

Submission status: Wrong Answer

Solution code:
n = int(input().strip())
ab = [tuple(map(int, input().split())) for _ in range(n)]

mid_min = 0
mid_max = 0

ab.sort(key=lambda x: x[0])
if n & 1:
    mid_min = ab[n // 2][0]
else:
    mid_min = (ab[(n - 1) // 2][0] + ab[n // 2][0]) / 2

ab.sort(key=lambda x: x[1])
if n & 1:
    mid_max = ab[n // 2][1]
else:
    mid_max = (ab[(n - 1) // 2][1] + ab[n // 2][1]) / 2

if n & 1:
    print(mid_max - mid_min + 1)
else:
    print(int(mid_max - mid_min) * 2 + 1)

Submission status: Wrong Answer

Solution code:
n = int(input())

ls = []
rs = []
for _ in range(n):
    x, y = map(int, input().split())
    ls.append(x)
    rs.append(y)

if n % 2 == 1:
    print(rs[len(rs)//2] - ls[len(ls)//2] + 1)
else:
    a = (rs[len(rs)//2-1] + rs[len(rs)//2]) / 2
    b = (ls[len(ls)//2-1] + ls[len(ls)//2]) / 2
    print(int((10 * a - 10 * b) / 5 + 1))

Submission status: Wrong Answer

Solution code:
import sys
from functools import lru_cache
 
#read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines
sys.setrecursionlimit(10**6)
def read():
  return int(readline())
def reads():
  return map(int, readline().split())
def mp(arg):
  return map(int,arg.split())
n=read()
a,b=[0]*n,[0]*n
for i in range(n):
  a[i],b[i]=reads()
a=sorted(a)
b=sorted(b)
if n%2==1:
  print(b[(n-1)//2]-a[(n-1)//2]+1)
else:
  mi=(a[n//2-1],a[n//2])
  ma=(b[n//2-1],b[n//2])
  res=0
  res+=(mi[1]+ma[1])-(mi[0]+ma[0])+1
  print(res)

Submission status: Wrong Answer

Solution code:
from sys import stdin

def main():
  s = []
  read = stdin.readline
  N =int(read())
  data = [list(map(int,read().split(" "))) for _ in range(N)]
  A = sorted([i[0] for i in data])
  B = sorted([i[1] for i in data])
  if N%2 == 1:
    a1 = A[((N+1)//2)-1]
    b1 = B[((N+1)//2)-1]
    print(b1 - a1 + 1)
  else:
    l = []
    a1 = A[(N//2)-1]
    b1 = B[(N//2)-1]
    a2 = A[(N//2)]
    b2 = B[(N//2)]
    for i in range(a1,a2+1):
      for j in range(b1,b2+1):
        l += [i+j]
    print(len(set(l)))
    
  
if __name__ == "__main__":
  main()

Submission status: Wrong Answer

Solution code:
from sys import stdin

def main():
  s = []
  read = stdin.readline
  N =int(read())
  data = [list(map(int,read().split(" "))) for _ in range(N)]
  A = [i[0] for i in data]
  B = [i[1] for i in data]
  if N%2 == 1:
    a1 = A[((N+1)//2)-1]
    b1 = B[((N+1)//2)-1]
    print(b1 - a1 + 1)
  else:
    l = []
    a1 = A[(N//2)-1]
    b1 = B[(N//2)-1]
    a2 = A[(N//2)]
    b2 = B[(N//2)]
    for i in range(a1,a2+1):
      for j in range(b1,b2+1):
        l += [i+j]
    print(len(set(l)))
    
  
if __name__ == "__main__":
  main()

Submission status: Wrong Answer

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

if N % 2 == 0:
  k1 = int(N/2-1)
  k2 = int(N/2)
  minM = AB[k1][0] + AB[k2][0]
  maxM = AB[k1][1] + AB[k2][1]
  print(maxM-minM+1)
else:
  k = int((N+1)/2)-1
  A = AB[k][0]
  B = AB[k][1]
  print(B-A+1)

Submission status: Wrong Answer

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

if n % 2:

    ab.sort()
    l = ab[(n+1)//2-1][0]

    ab.sort(key=lambda x:x[1], reverse=True)
    r = ab[(n+1)//2-1][1]

    print(r-l+1)

else:

    ab.sort()
    a = [ai for ai, bi in ab]
    b = [bi for ai, bi in ab]

    ll = a[n//2-1]
    lr = min(max(b[:n//2]), min(b[n//2:]))

    ab.sort(key=lambda x:x[1], reverse=True)
    a = [ai for ai, bi in ab]
    b = [bi for ai, bi in ab]

    rl = max(min(a[:n//2]), max(a[n//2:]))
    rr = b[n//2-1]

    print((lr+rr) - (ll+rl) + 1)

Submission status: Wrong Answer

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

if n % 2:

    ab.sort()
    l = ab[(n+1)//2-1][0]

    ab.sort(key=lambda x:x[1], reverse=True)
    r = ab[(n+1)//2-1][1]

    print(r-l+1)

else:

    ab.sort()
    a = [ai for ai, bi in ab]
    b = [bi for ai, bi in ab]

    ll = a[n//2-1]
    lr = min(max(b[:n//2]), b[n//2])

    ab.sort(key=lambda x:x[1], reverse=True)
    a = [ai for ai, bi in ab]
    b = [bi for ai, bi in ab]

    rl = max(min(a[:n//2]), a[n//2])
    rr = b[n//2-1]

    print((lr+rr) - (ll+rl) + 1)

Submission status: Wrong Answer

Solution code:
import sys


def main():
    input = sys.stdin.buffer.readline
    n = int(input())
    ab = [map(int, input().split()) for _ in range(n)]
    a, b = [list(i) for i in zip(*ab)]
    new_a = sorted(a)
    new_b = sorted(b, reverse=True)
    if n % 2 == 1:
        min_m = new_a[(n + 1) // 2 - 1]
        max_m = new_b[(n + 1) // 2 - 1]
        print((max_m - min_m) + 1)
    else:
        min_m = (new_a[n // 2 - 1] + new_a[n // 2 + 1 - 1]) // 2
        max_m = (new_b[n // 2 - 1] + new_b[n // 2 + 1 - 1]) // 2
        print((max_m - min_m) * 2 + 1)


if __name__ == '__main__':
    main()

Submission status: Wrong Answer

Solution code:
from decimal import *

n = int(input())

if n % 2 == 1:
    med = (n + 1) // 2
    ans = 0
    for i in range(n):
        if (i + 1) == med:
            a, b = map(int, input().split())
            ans = Decimal(b) - Decimal(a) + Decimal(1)
        else:
            input()
    print(int(ans))
else:
    med0 = n // 2
    a0 = 0
    b0 = 0
    med1 = (n // 2) + 1
    a1 = 0
    b1 = 0
    for i in range(n):
        if (i + 1) == med0:
            a0, b0 = map(int, input().split())
        elif (i + 1) == med1:
            a1, b1 = map(int, input().split())
        else:
            input()
    amed = (Decimal(a0)+Decimal(a1))/Decimal(2)
    bmed = (Decimal(b0)+Decimal(b1))/Decimal(2)
    ans = int(((bmed - amed) * Decimal(2) + Decimal(1)))
    print(ans)

Submission status: Wrong Answer

Solution code:
from decimal import *

n = int(input())

if n % 2 == 1:
    med = (n + 1) // 2 - 1
    ans = 0
    for i in range(n):
        if i == med:
            a, b = map(int, input().split())
            ans = b - a + 1
        else:
            input()
    print(ans)
else:
    med0 = n // 2
    a0 = 0
    b0 = 0
    med1 = (n // 2) + 1
    a1 = 0
    b1 = 0
    for i in range(n):
        if (i + 1) == med0:
            a0, b0 = map(int, input().split())
        elif (i + 1) == med1:
            a1, b1 = map(int, input().split())
        else:
            input()
    amed = (Decimal(a0)+Decimal(a1))/Decimal(2)
    bmed = (Decimal(b0)+Decimal(b1))/Decimal(2)
    ans = int(((bmed - amed) * Decimal(2) + Decimal(1)))
    print(ans)

Submission status: Wrong Answer

Solution code:
n = int(input())

if n % 2 == 1:
    med = (n + 1) // 2 - 1
    ans = 0
    for i in range(n):
        if i == med:
            a, b = map(int,input().split())
            ans = b - a + 1
        else:
            input()
    print(ans)
else:
    med0 = n // 2; a0 = 0; b0 = 0
    med1 = (n // 2) + 1; a1 = 0; b1 = 0
    for i in range(n) :
        if (i + 1) == med0:
            a0,b0 = map(int,input().split())
        elif (i + 1) == med1:
            a1,b1 = map(int,input().split())
        else:
            input()
    amed = (a0+a1)/2; bmed=(b0+b1)/2
    ans = int(((bmed - amed) * 2 + 1))
    print(ans)

Submission status: Wrong Answer

Solution code:
n = int(input())

if n % 2 == 1:
    med = (n + 1) // 2 - 1
    ans = 0
    for i in range(n):
        if i == med:
            a, b = map(int,input().split())
            ans = b - a + 1
        else:
            input()
    print(ans)
else:
    med0 = n // 2; med0_list = []
    med1 = (n // 2) + 1; med1_list = []
    for i in range(n) :
        if (i + 1) == med0:
            a,b = map(int,input().split())
            med0_list = [i for i in range(a, b + 1)]
        elif (i + 1) == med1:
            a,b = map(int,input().split())
            med1_list = [i for i in range(a, b + 1)]
        else:
            input()
    all_med = set([]);
    for x in med0_list:
        for y in med1_list:
            all_med.add((x + y) / 2)
    ans = len(all_med)
    print(ans)

Submission status: Wrong Answer

Solution code:
import sys
def input(): return sys.stdin.readline().rstrip()
def main():
    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==1:
        print(B[n//2]-A[n//2]+1)
    else:
        print(max(0,int((B[n//2-1]+B[n//2])/2-(A[n//2-1]+A[n//2])/2)*2)+1)

if __name__=='__main__':
    main()

Submission status: Wrong Answer

Solution code:
import sys
def input(): return sys.stdin.readline().rstrip()
def main():
    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==1:
        print(B[n//2]-A[n//2]+1)
    else:
        print(int((B[n//2-1]+B[n//2])/2-(A[n//2-1]+A[n//2])/2)*2+1)

if __name__=='__main__':
    main()

Submission status: Wrong Answer

Solution code:
N = int(input())
A_list = [0]*N
B_list = [0]*N
for i in range(N):
    A_list[i],B_list[i] = map(int,input().split())

A_list.sort()
B_list.sort()

if N%2 == 1:
    print(B_list[(N+1)//2] - A_list[(N+1)//2] + 1)
else:
    big = (B_list[N//2] + B_list[N//2-1])/2
    small = (A_list[N//2] + A_list[N//2-1])/2
    print(int((big-small)*2 + 1))

Submission status: Wrong Answer

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

def I(): return int(input())
def MI(): return map(int, input().split())
def LI(): return list(map(int, input().split()))

def main():
    N=I()
    L=[]
    R=[]

    
    for i in range(N):
        a,b=MI()
        L.append(a)
        R.append(b)
        
    #中央値の最小値は，Lの中央値．中央値の最大値はRの中央値
    #間は全部埋められそう?
        
    if N%2==0:
        Lm=(L[N//2]+L[N//2-1])
        Rm=(R[N//2]+R[N//2-1])
    else:
        Lm=L[N//2]
        Rm=R[N//2]
    ans=Rm-Lm+1
    print(ans)
        
        
        
        
        
    
            

main()

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

a = sorted([x[0] for x in ab])
b = sorted([y[1] for y in ab])

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

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()
if n % 2 == 1:
    print(b[n//2] - a[n//2] + 1)
else:
    print(b[n//2] - a[(n-1)//2] +1)

Submission status: Wrong Answer

Solution code:
from bisect import bisect_left, bisect_right
def main():
    n = int(input())
    A, B = [None]*n, [None]*n
    for i in range(n):
        A[i], B[i] = map(int, input().split())
    A.sort()
    B.sort()
    if n % 2 == 1:
        m, M = -1, -1
        L, R = -1, 10**9
        while L+1 < R:
            P = (L+R)//2
            idx = bisect_right(A, P)
            if idx >= (n+1)//2:
                R = P
            else:
                L = P
        m = R
        L, R = 0, 10**9+1
        while L+1 < R:
            P = (L+R)//2
            idx = bisect_left(B, P)
            if n-idx >= (n+1)//2:
                L = P
            else:
                R = P
        M = L
        print(max(0, M-m+1))
    else:
        lm, lM = -1, -1
        L, R = -1, 10**9
        while L+1 < R:
            P = (L+R)//2
            idx = bisect_right(A, P)
            if idx >= n//2:
                R = P
            else:
                L = P
        lm = R
        L, R = 0, 10**9+1
        while L+1 < R:
            P = (L+R)//2
            idx = bisect_left(B, P)
            if n-idx >= n//2+1:
                L = P
            else:
                R = P
        lM = L
        rm, rM = -1, -1
        L, R = -1, 10**9
        while L+1 < R:
            P = (L+R)//2
            idx = bisect_right(A, P)
            if idx >= n//2+1:
                R = P
            else:
                L = P
        rm = R
        L, R = -1, 10**9
        while L+1 < R:
            P = (L+R)//2
            idx = bisect_left(B, P)
            if n-idx >= n//2:
                L = P
            else:
                R = P
        rM = L
        print(max(0, int(((lM+rM)/2-(lm+rm)/2+1)*2-1)))

if __name__ == "__main__":
    main()

Submission status: Wrong Answer

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

ab.sort()
a = []
b =[]
for x in ab:
  a.append(x[0])
  b.append(x[1])
a.sort()
b.sort()

ca,cb =0,0
if n % 2 == 0:
  ca = (a[n//2-1] + a[n//2])//2
  cb = (b[n//2-1] + b[n//2])//2
  ans = (cb-ca+0.5)//0.5
else:
  ca = a[(n+1)//2-1]
  cb = b[(n+1)//2-1]
  ans = (cb-ca) +1

print(int(ans))

Submission status: Wrong Answer

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

ab.sort()
a = []
b =[]
for x in ab:
  a.append(x[0])
  b.append(x[1])

ca,cb =0,0
if n % 2 == 0:
  ca = (a[n//2-1] + a[n//2])//2
  cb = (b[n//2-1] + b[n//2])//2
  ans = (cb-ca) / 0.5 +1
else:
  ca = a[(n+1)//2-1]
  cb = b[(n+1)//2-1]
  ans = (cb-ca) +1

print(int(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)

l=[]
r=[]
A.sort()
B.sort()

if N%2==1:
    num=(N+1)//2 - 1
    for i in range(N):
        if i==num:
            m=A[i]
            M=B[i]

    ans=(M-m)+1
else:
    num=(N//2+N//2+1)//2 -1
    for i in range(N):
        if i==num:
            m=A[i]
            M=B[i]
    ans=2*(M-m)+1

print(ans)