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:
import math
import decimal


N=int(input())
A=[]
for i in range(N):
    A.append(list(map(int,input().split())))

a=[]
b=[]

for i in range(N):
    a.append(A[i][0])
    b.append(A[i][1])
a.sort()
b.sort()

if(N%2==0):
    a_mid=(a[N//2-1]+a[N//2])/2
    b_mid=(b[N//2-1]+b[N//2])/2
    '''
    a[N//2-1]=decimal.Decimal(a[N//2-1])
    a[N//2]=decimal.Decimal(a[N//2])
    b[N//2-1]=decimal.Decimal(b[N//2-1])
    b[N//2]=decimal.Decimal(b[N//2])
    a_mid=(a[N//2-1]+a[N//2])/decimal.Decimal(2)
    b_mid=(b[N//2-1]+b[N//2])/decimal.Decimal(2)
    '''
    #a_mid=decimal.Decimal((a[N//2-1]+a[N//2])/2)
    #b_mid=decimal.Decimal((b[N//2-1]+b[N//2])/2)
    if(a_mid-int(a_mid)<0.5):
        a_mid=int(a_mid)+0.5
    elif(0.5<a_mid-int(a_mid)):
        a_mid=math.ceil(a_mid)

    if(b_mid-int(b_mid)<0.5):
        b_mid=int(b_mid)+0.5
    elif(0.5<b_mid-int(b_mid)):
        b_mid=math.ceil(b_mid)



    sa=b_mid-a_mid
    print(int(sa)*2+1)


else:

    a_mid=a[int(N/2)]
    b_mid=b[int(N/2)]



    sa=b_mid-a_mid
    print(int(sa)+1)

Submission status: Wrong Answer

Solution code:
import math
import decimal


N=int(input())
A=[]
for i in range(N):
    A.append(list(map(int,input().split())))

a=[]
b=[]

for i in range(N):
    a.append(A[i][0])
    b.append(A[i][1])
a.sort()
b.sort()

if(N%2==0):
    a_mid=(a[N//2-1]+a[N//2])/2
    b_mid=(b[N//2-1]+b[N//2])/2
    #a_mid=decimal.Decimal((a[N//2-1]+a[N//2])/2)
    #b_mid=decimal.Decimal((b[N//2-1]+b[N//2])/2)
    if(a_mid-int(a_mid)<0.5):
        a_mid=int(a_mid)+0.5
    elif(0.5<a_mid-int(a_mid)):
        a_mid=math.ceil(a_mid)

    if(b_mid-int(b_mid)<0.5):
        b_mid=int(b_mid)+0.5
    elif(0.5<b_mid-int(b_mid)):
        b_mid=math.ceil(b_mid)



    sa=b_mid-a_mid
    print(int(sa)*2+1)


else:

    a_mid=a[int(N/2)]
    b_mid=b[int(N/2)]



    sa=b_mid-a_mid
    print(int(sa)+1)

Submission status: Wrong Answer

Solution code:
import math
import decimal


N=int(input())
A=[]
for i in range(N):
    A.append(list(map(int,input().split())))

a=[]
b=[]

for i in range(N):
    a.append(A[i][0])
    b.append(A[i][1])
a.sort()
b.sort()

if(N%2==0):
    a_mid=(a[N//2-1]+a[N//2])/2
    b_mid=(a[N//2-1]+a[N//2])/2
    #a_mid=decimal.Decimal((a[N//2-1]+a[N//2])/2)
    #b_mid=decimal.Decimal((b[N//2-1]+b[N//2])/2)
    if(a_mid-int(a_mid)<0.5):
        a_mid=int(a_mid)+0.5
    elif(0.5<a_mid-int(a_mid)):
        a_mid=math.ceil(a_mid)

    if(b_mid-int(b_mid)<0.5):
        b_mid=int(b_mid)+0.5
    elif(0.5<b_mid-int(b_mid)):
        b_mid=math.ceil(b_mid)


    sa=b_mid-a_mid
    print(int(sa)*2+1)


else:

    a_mid=a[int(N/2)]
    b_mid=b[int(N/2)]



    sa=b_mid-a_mid
    print(int(sa)+1)

Submission status: Wrong Answer

Solution code:
import math

N=int(input())
A=[]
for i in range(N):
    A.append(list(map(int,input().split())))

a=[]
b=[]

for i in range(N):
    a.append(A[i][0])
    b.append(A[i][1])
a.sort()
b.sort()

if(N%2==0):

    a_mid=(a[N//2-1]+a[N//2])/2
    b_mid=(b[N//2-1]+b[N//2])/2
    if(a_mid-int(a_mid)<0.5):
        a_mid=int(a_mid)+0.5
    elif(0.5<a_mid-int(a_mid)):
        a_mid=math.ceil(a_mid)

    if(b_mid-int(b_mid)<0.5):
        b_mid=int(b_mid)+0.5
    elif(0.5<b_mid-int(b_mid)):
        b_mid=math.ceil(b_mid)


    sa=b_mid-a_mid
    print(int(sa)*2+1)


else:

    a_mid=a[int(N/2)]
    b_mid=b[int(N/2)]



    sa=b_mid-a_mid
    print(int(sa)+1)

Submission status: Wrong Answer

Solution code:
def main():
    n = int(input())
    A,B = [],[]
    for i in range(n):
        a,b = map(int,input().split())
        A.append(a)
        B.append(b)
    A = sorted(A)
    B = sorted(B)
    if n%2==0:
        print(B[n//2]-A[n//2-1]+1)
    else:
        print(B[n-(n+1)//2]-A[(n+1)//2-1]+1)
if __name__ == "__main__":
    main()

Submission status: Wrong Answer

Solution code:
N = int(input())
l = []
for _ in range(N):
  A, B = list(map(int,input().split()))
  l.append([A,B])
 
if N%2==1:
  lp = sorted(l, key = lambda x:x[0])
  fir = lp[(N-1)//2][0]
  lm = sorted(l, key= lambda x:x[0], reverse = True)
  fim = lm[(N-1)//2][-1]
  print(abs(fir-fim)+1)
  
else:
  lp = sorted(l, key = lambda x:x[0])
  fir = (lp[N//2][0]+lp[N//2-1][0])/2
  lm = sorted(l, key= lambda x:x[0], reverse = True)
  fim = (lm[N//2][-1]+lm[N//2-1][-1])/2
  print(int(abs(fir-fim)*2+1))

Submission status: Wrong Answer

Solution code:
N = int(input())
l = []
for _ in range(N):
  A, B = list(map(int,input().split()))
  l.append([A,B])
 
if N%2==0:
  lp = sorted(l, key = lambda x:x[0])
  fir = lp[(N-1)//2][0]
  lm = sorted(l, key= lambda x:x[0], reverse = True)
  fim = lm[(N-1)//2][-1]
  print(abs(fir-fim)+1)
  
else:
  lp = sorted(l, key = lambda x:x[0])
  fir = (lp[N//2][0]+lp[N//2-1][0])/2
  lm = sorted(l, key= lambda x:x[0], reverse = True)
  fim = (lm[N//2][-1]+lm[N//2-1][-1])/2
  print(abs(fir-fim)*2+1)

Submission status: Wrong Answer

Solution code:
def median(A,N):
    A.sort()
    if N % 2 == 1:
        return A[N//2]
    else:
        return (A[(N-1)//2] + A[(N-1)//2+1])/2

def main():
    N = int(input())
    AB = [list(map(int,input().split())) for _ in range(N)]

    A = [AB[i][0] for i in range(N)]
    B = [AB[i][1] for i in range(N)]

    if N % 2 == 1:
        ans = max(int(median(B,N)-median(A,N))+1,0)
    else:
        ans = max(2*int(median(B,N)-median(A,N))+1,0)
    print(ans)

if __name__ == "__main__":
    main()

Submission status: Wrong Answer

Solution code:
def median(A,N):
    A.sort()
    if N % 2 == 1:
        return A[N//2]
    else:
        return (A[(N-1)//2] + A[(N-1)//2+1])/2

def main():
    N = int(input())
    AB = [list(map(int,input().split())) for _ in range(N)]

    A = [AB[i][0] for i in range(N)]
    B = [AB[i][1] for i in range(N)]

    if N % 2 == 1:
        ans = max(int(median(B,N)-median(A,N))+1,0)
    else:
        ans = max(2*int(median(B,N)-median(A,N))+1,0)
    print(median(B,N))
    print(median(A,N))
    print(ans)

if __name__ == "__main__":
    main()

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)
if N%2==1:
    print(B[N//2]-A[N//2]+1)
else:
    A_chu=(A[N//2-1]+A[N//2])/2
    B_chu=(B[N//2-1]+B[N//2])/2
    ans=(B_chu-A_chu)*2+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)
if N%2==1:
    print(B[N//2]-A[N//2]+1)
else:
    A_chu=(A[N//2-1]+A[N//2])/2
    B_chu=(B[N//2-1]+B[N//2])/2
    ans=(B_chu-A_chu+1)*2-1
    print(int(ans))

Submission status: Wrong Answer

Solution code:
import statistics

n = int(input())
la = []
lb = []
for i in range(n):
  a, b = map(int, input().split())
  la.append(a)
  lb.append(b)
a = statistics.median(la)
b = statistics.median(lb)
if n % 2 == 1:
  print(b - a + 1)
else:
  print((b - a) * 2 + 1)

Submission status: Wrong Answer

Solution code:
import statistics

n = int(input())
la = []
lb = []
for i in range(n):
  a, b = map(int, input().split())
  la.append(a)
  lb.append(b)
a = statistics.median(la)
b = statistics.median(lb)
if n % 2 == 1:
  print(b - a + 1)
else:
  print((b - a) * 2 - 1)

Submission status: Wrong Answer

Solution code:
from statistics import median

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

mn = median(A)
mx = median(B)

if N % 2 == 1:
    print(int(mx - mn + 1))        # mn, mn + 1, mn + 2, ..., mx
else:
    print(int(mx - mn * 2 + 1))    # mn, mn + 0.5, mn + 1, ..., mx

Submission status: Wrong Answer

Solution code:
from statistics import median

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

mn = median(A)
mx = median(B)

if N % 2 == 1:
    print(int(mx - mn) + 1)          # mn, mn + 1, mn + 2, ..., mx
else:
    print(int(mx - mn) * 2 + 1)    # mn, mn + 0.5, mn + 1, ..., mx

Submission status: Wrong Answer

Solution code:
N = int(input())
X_vec = {}
for n in range(N):
    A, B = list(map(int,input().split()))

    X_vec[n] =set(range(A,B+1))
if N %2 !=0:
    candi = X_vec[((N + 1) // 2) - 1]

    print(len(candi))
else:
    ans = []
    small= X_vec[N//2 -1]
    large = X_vec[N//2]
    print(len(small | large))

Submission status: Wrong Answer

Solution code:
n = int(input())
a, b = [], []
for i in range(n):
    x, y = map(int, input().split())
    a.append(x)
    b.append(y)
a.sort()
b.sort()
if n%2==0:
    p = n//2
    right = (a[p]+a[p-1])/2 -1
    left = (b[p]+b[p-1])/2
    r = left-right
    if int(r)==r:
        print(int(r)*2)
    else:
        print(int(r)*2 +1)
else:
    p = n//2
    right = a[p]
    left = b[p]
    print(int(left-right)+1)

Submission status: Wrong Answer

Solution code:
n = int(input())
a, b = [], []
for i in range(n):
    x, y = map(int, input().split())
    a.append(x)
    b.append(y)
a.sort()
b.sort()
if n%2==0:
    p = n//2
    right = (a[p]+a[p-1])/2 -1
    left = (b[p]+b[p-1])/2
else:
    p = n//2
    right = a[p]
    left = b[p]
print(int(left-right)+1)

Submission status: Wrong Answer

Solution code:
import numpy as np
(n,),*l = [[*map(int,i.split())]for i in open(0)]
a,b = np.median(l,axis=0)
if n%2>0:
    print(int(b-a+1))
else:
    print(int(b-a)*2+1)

Submission status: Wrong Answer

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


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

    As = sorted(A)
    Bs = sorted(B)

    if N % 2 == 0:
        i1 = N // 2
        i2 = N // 2 - 1
        low = As[i1] + As[i2]
        up = Bs[i1] + B[i2]
        ans = up - low + 1
    else:
        i = (N - 1) // 2
        low = As[i]
        up = Bs[i]
        ans = up - low + 1

    print(ans)


if __name__ == '__main__':
    solve()

Submission status: Wrong Answer

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


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

    As = sorted(A)
    Bs = sorted(B)

    if N % 2 == 0:
        i1 = N // 2
        i2 = N // 2 - 1
        low = As[i1] + As[i2]
        up = Bs[i1] + B[i2]
        ans = up - low + 1
        print(ans)
        exit()
    else:
        i = (N - 1) // 2
        low = As[i]
        up = Bs[i]
        ans = up - low + 1
        print(ans)
        exit()


if __name__ == '__main__':
    solve()

Submission status: Wrong Answer

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

INF = 10**9 + 1


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

    As = sorted(A)
    Bs = sorted(B)

    if N % 2 == 0:
        i1 = N // 2
        i2 = N // 2 - 1
        low = (As[i1] + As[i2]) / 2
        up = (Bs[i1] + B[i2]) / 2
        ans = (up - low) * 2 + 1
        print(int(ans + 0.01))
        exit()
    else:
        i = (N - 1) // 2
        low = As[i]
        up = Bs[i]
        ans = up - low + 1
        print(ans)
        exit()


if __name__ == '__main__':
    solve()

Submission status: Wrong Answer

Solution code:
import sys
import math

N = int(sys.stdin.readline().strip())
ABlist = []
for _ in range(N):
    a, b = map(int, sys.stdin.readline().strip().split())
    ABlist.append((a, b))

Asorted = sorted(ABlist)
Bsorted = sorted(ABlist, key=lambda x: x[1])
if N % 2 == 1:
    left = Asorted[(N-1)//2][0]
    right = Bsorted[(N-1)//2][1]
    # print(left, right)
    print(right - left + 1)
else:
    if N == 2:
        left = (Asorted[(N-1)//2][0] + Asorted[(N-1)//2 + 1][0]) / 2
        right = (Bsorted[(N-1)//2][1] + Bsorted[(N-1)//2 + 1][1]) / 2
    else:
        left = (Asorted[(N-1)//2][0] + Asorted[(N-1)//2 + 2][0]) / 2
        right = (Bsorted[(N-1)//2 - 1][1] + Bsorted[(N-1)//2 + 1][1]) / 2
    print(int((right - left) * 2 + 1))

Submission status: Wrong Answer

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

INF = 10**9 + 1


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

    As = sorted(A)
    Bs = sorted(B)

    if N % 2 == 0:
        i1 = N // 2
        i2 = N // 2 - 1
        low = (As[i1] + As[i2]) / 2
        up = (Bs[i1] + B[i2]) / 2
        ans = (up - low) * 2 + 1
        print(int(ans))
        exit()
    else:
        i = (N - 1) // 2
        low = As[i]
        up = Bs[i]
        ans = up - low + 1
        print(ans)
        exit()


if __name__ == '__main__':
    solve()

Submission status: Wrong Answer

Solution code:
N = int(input())
AB = [list(map(int,input().split())) for _ in range(N)]
 
A = []
B = []
for i in range(N):
  A.append(AB[i][0])
  B.append(AB[i][1])

if N % 2 == 0:
    n = N // 2
    med1 = A[n-1] + A[n]
    med2 = B[n-1] + B[n]
    x = med2 - med1 + 1
else:
    n = N // 2
    med1 = A[n]
    med2 = B[n]
    x = med2 - med1 + 1
    
print(x)

Submission status: Wrong Answer

Solution code:
#!/usr/bin/env python3

import sys
# import time
# import math
# import numpy as np
# import scipy.sparse.csgraph as cs            # csgraph_from_dense(ndarray, null_value=inf), bellman_ford(G, return_predecessors=True), dijkstra, floyd_warshall
# import random                                # random, uniform, randint, randrange, shuffle, sample
# import string                                # ascii_lowercase, ascii_uppercase, ascii_letters, digits, hexdigits
# import re                                    # re.compile(pattern) => ptn obj; p.search(s), p.match(s), p.finditer(s) => match obj; p.sub(after, s)
# from bisect import bisect_left, bisect_right # bisect_left(a, x, lo=0, hi=len(a)) returns i such that all(val<x for val in a[lo:i]) and all(val>-=x for val in a[i:hi]).
# from collections import deque                # deque class. deque(L): dq.append(x), dq.appendleft(x), dq.pop(), dq.popleft(), dq.rotate()
# from collections import defaultdict          # subclass of dict. defaultdict(facroty)
# from collections import Counter              # subclass of dict. Counter(iter): c.elements(), c.most_common(n), c.subtract(iter)
# from datetime import date, datetime          # date.today(), date(year,month,day) => date obj; datetime.now(), datetime(year,month,day,hour,second,microsecond) => datetime obj; subtraction => timedelta obj
# from datetime.datetime import strptime       # strptime('2019/01/01 10:05:20', '%Y/%m/%d/ %H:%M:%S') returns datetime obj
# from datetime import timedelta               # td.days, td.seconds, td.microseconds, td.total_seconds(). abs function is also available.
# from copy import copy, deepcopy              # use deepcopy to copy multi-dimentional matrix without reference
# from functools import reduce                 # reduce(f, iter[, init])
# from functools import lru_cache              # @lrucache ...arguments of functions should be able to be keys of dict (e.g. list is not allowed)
# from heapq import heapify, heappush, heappop # built-in list. heapify(L) changes list in-place to min-heap in O(n), heappush(heapL, x) and heappop(heapL) in O(lgn).
# from heapq import nlargest, nsmallest        # nlargest(n, iter[, key]) returns k-largest-list in O(n+klgn).
# from itertools import count, cycle, repeat   # count(start[,step]), cycle(iter), repeat(elm[,n])
# from itertools import groupby                # [(k, list(g)) for k, g in groupby('000112')] returns [('0',['0','0','0']), ('1',['1','1']), ('2',['2'])]
# from itertools import starmap                # starmap(pow, [[2,5], [3,2]]) returns [32, 9]
# from itertools import product, permutations  # product(iter, repeat=n), permutations(iter[,r])
# from itertools import combinations, combinations_with_replacement
# from itertools import accumulate             # accumulate(iter[, f])
# from operator import itemgetter              # itemgetter(1), itemgetter('key')
# from fractions import gcd                    # for Python 3.4 (previous contest @AtCoder)



def main():
    mod = 1000000007                # 10^9+7
    inf = float('inf')              # sys.float_info.max = 1.79...e+308
    # inf = 2 ** 64 - 1             # (for fast JIT compile in PyPy) 1.84...e+19
    sys.setrecursionlimit(10**6)    # 1000 -> 1000000
    def input(): return sys.stdin.readline().rstrip()
    def ii():    return int(input())
    def mi():    return map(int, input().split())
    def mi_0():  return map(lambda x: int(x)-1, input().split())
    def lmi():   return list(map(int, input().split()))
    def lmi_0(): return list(map(lambda x: int(x)-1, input().split()))
    def li():    return list(input())
    
    
    n = ii()
    left = []
    right = []
    for _ in range(n):
        a, b = mi()
        left.append(a)
        right.append(b)
    left.sort()
    right.sort()

    if n % 2 == 0:
        x = (left[n//2-1] + left[n//2]) / 2
        y = (right[n//2-1] + right[n//2]) / 2
        print((y - x + 1) * 2)
    else:
        x = left[n//2]
        y = right[n//2]
        print(y - x + 1)
    


if __name__ == "__main__":
    main()

Submission status: Wrong Answer

Solution code:
n = int(input())
la = []
lb = []

for i in range(n):
    a, b = map(int, input().split())
    la.append(a)
    lb.append(b)

la.sort()
lb.sort()

if n % 2 == 1:
    lr = (n + 1) // 2
    ma = la[lr-1]
    mb = lb[lr-1]
    print(mb-ma+1)
else:
    l = n // 2
    r = n // 2 + 1
    ma = (la[l-1] + la[r-1]) / 2
    mb = (lb[l - 1] + lb[r - 1]) / 2
    print((mb-ma)*2+1)

Submission status: Wrong Answer

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

def main():
    N,*ab = map(int, read().split())

    AB = []
    for a, b in zip(*[iter(ab)]*2):
        AB.append((a, b))

    AB.sort()
    a, _ = AB[N // 2]
    
    AB.sort(key=lambda x: x[1])
    _, b = AB[N // 2]

    if N % 2 == 0:
        ans = (b - a + 1) * 2 - 1
    else:
        ans = b - a + 1
    
    print(ans)


if __name__ == "__main__":
    main()

Submission status: Wrong Answer

Solution code:
#from collections import deque,defaultdict
from sys import stdin
input = stdin.readline
printn = lambda x: print(x,end='')
inn = lambda : int(input())
inl   = lambda: list(map(int, input().split()))
inm   = lambda:      map(int, input().split())
ins = lambda : input().strip()
DBG = True # and False
BIG = 10**18
R = 10**9 + 7

def ddprint(x):
  if DBG:
    print(x)

n = inn()
a = []
b = []
for i in range(n):
    aa,bb = inm()
    a.append(aa)
    b.append(bb)
a.sort()
b.sort(reverse=True)
m = n//2 - (0 if n%2==1 else 1)
print(b[m]-a[m]+1)

Submission status: Wrong Answer

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

if N % 2 == 1:
  n = N // 2
  a, b = AB[n]
  print(b - a + 1)
else:
  n = N // 2
  a0, b0 = AB[n-1]
  a1, b1 = AB[n]
  left = a0 + a1; right = b0 + b1
  print(right - left + 1)

Submission status: Wrong Answer

Solution code:
import bisect
n = int(input())
a = []
b = []

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

Submission status: Wrong Answer

Solution code:
import bisect
n = int(input())
a = []
b = []

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

Submission status: Wrong Answer

Solution code:
N=int(input())
a=[]
b=[]
for _ in range(N):
    A,B=map(int,input().split())
    a.append(A)
    b.append(B)
a=sorted(a)
b=sorted(b)
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)

Submission status: Wrong Answer

Solution code:
N=int(input())
a=[]
b=[]
for _ in range(N):
    A,B=map(int,input().split())
    a.append(A)
    b.append(B)
a=sorted(a)
b=sorted(b)
if N%2==1:
    print(b[N//2]-a[N//2]+1)
else:
    print((b[N//2]-a[N//2])*2+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 == 1:
    print(B[(N - 1) // 2] - A[(N - 1) // 2] + 1)
else:
    print(((B[N // 2] + B[N // 2 - 1]) - (A[N // 2] + A[N // 2 - 1])) * 2 - 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 == 1:
    ans = B[N//2] - A[N//2]+1
    print(ans)
else:
    vmin = A[N//2-1]+B[N//2-1]
    vmax = A[N//2]+B[N//2]
    ans = vmax-vmin+1
    print(ans)

Submission status: Wrong Answer

Solution code:
n=int(input())
a=[]
b=[]
for i in range(n):
    ai,bi=map(int,input().split())
    a.append(ai)
    b.append(bi)
    
if n%2==0:
    n2=n//2
    ca=(a[n2-1]+a[n2])
    cb=(b[n2-1]+b[n2])
    c=cb-ca+1
else:
    n2=(n-1)//2
    ca=a[n2]
    cb=b[n2]
    c=cb-ca+1
    
print(c)

Submission status: Wrong Answer

Solution code:
#!python3

import numpy as np

LI = lambda: list(map(int, input().split()))

# input
N = int(input())
A, B = [None] * N, [None] * N
for i in range(N):
    A[i], B[i] = LI()


def main():
    a, b = np.array(A, dtype=int), np.array(B, dtype=int)
    a.sort()
    b.sort()
    i = N // 2
    if N % 2 == 0:
        a *= 2
        b *= 2
        l = (a[i - 1] + a[i]) // 2
        r = (b[i - 1] + b[i]) // 2
        ans = r - l + 1
    ans = b[i] - a[i] + 1
    print(ans)


if __name__ == "__main__":
    main()

Submission status: Wrong Answer

Solution code:
from heapq import heappush
n=int(input())
A=[]
B=[]
for i in range(n):
  a,b=map(int,input().split())
  heappush(A,a)
  heappush(B,b)
if n%2:
  c=(n+1)//2-1
  print(B[c]-A[c]+1)
else:
  c=n//2
  print(B[c]+B[c-1]-A[c]-A[c-1]+1)

Submission status: Wrong Answer

Solution code:
import sys, re
from collections import deque, defaultdict, Counter
from math import ceil, sqrt, hypot, factorial, pi, sin, cos, radians, gcd
from itertools import accumulate, permutations, combinations, product, groupby, combinations_with_replacement
from operator import itemgetter, mul
from copy import deepcopy
from string import ascii_lowercase, ascii_uppercase, digits
from bisect import bisect, bisect_left
from heapq import heappush, heappop
from functools import reduce
def input(): return sys.stdin.readline().strip()
def INT(): return int(input())
def MAP(): return map(int, input().split())
def LIST(): return list(map(int, input().split()))
def ZIP(n): return zip(*(MAP() for _ in range(n)))
sys.setrecursionlimit(10 ** 9)
INF = float('inf')
mod = 10 ** 9 + 7

N = INT()
A, B = ZIP(N)

if N%2 == 0:
	l = (A[N//2]+A[N//2-1])
	r = (B[N//2]+B[N//2-1])
	print(r-l+1)
else:
	print(B[N//2]-A[N//2]+1)

Submission status: Wrong Answer

Solution code:
N = int(input())
ab = []
for i in range(N):
    ab.append(tuple(map(int,input().split())))
 
up = sorted(ab,key=lambda a:a[0],reverse=True)
down = sorted(ab,key=lambda a:a[1],reverse=True)
 
if N%2 == 1:
    print(abs(up[N//2][1]-down[N//2][0])+1)
else:
    up2 = sorted(ab,key=lambda a:a[0],reverse=True)
    down2 = sorted(ab,key=lambda a:a[1],reverse=True)
    r = (up[N//2][1]+up2[N//2][1])
    l = (down[N//2][0]+down2[N//2][0])
    print(abs(r-l)+1)

Submission status: Wrong Answer

Solution code:
N = int(input())
ab = []
for i in range(N):
    ab.append(tuple(map(int,input().split())))
 
up = sorted(ab,key=lambda a:a[1],reverse=True)
down = sorted(ab,key=lambda a:a[0],reverse=True)
 
if N%2 == 1:
    print(up[N//2][1]-down[N//2][0]+1)
else:
    up2 = sorted(ab,key=lambda a:a[1],reverse=True)
    down2 = sorted(ab,key=lambda a:a[0],reverse=True)
    r = (up[N//2][1]+up2[N//2][1])
    l = (down[N//2][0]+down2[N//2][0])
    print(r-l+1)

Submission status: Wrong Answer

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

A = [i[0] for i in AB]
B = [i[1] for i in AB]
from statistics import median

a_med = median(A)
b_med = median(B)

if N%2==1:
  print(b_med - a_med + 1)
  
else:
  print((b_med - a_med) * 2 + 1)

Submission status: Wrong Answer

Solution code:
n = int(input())
min_s = []
max_s = []
for i in range(n):
    a, b = map(int, input().split())
    min_s.append(a)
    max_s.append(b)

min_s.sort()
max_s.sort()
if n % 2 == 0:
    min_med = (min_s[n//2-1] + min_s[n//2])/2
    max_med = (max_s[n//2-1] + max_s[n//2])/2
    print(int(max_med-min_med)*2+1)

else:
    min_med = min_s[(n+1)//2-1]
    max_med = max_s[(n+1)//2-1]
    print(int((max_med-min_med)+1))

Submission status: Wrong Answer

Solution code:
import sys
from heapq import heappush, heappop
def input(): return sys.stdin.readline().strip()

def main():
    N = int(input())
    lower = []
    upper = []
    for i in range(N):
        a, b = map(int, input().split())
        heappush(lower, (a, i))
        heappush(upper, (-b, i))
    
    if N % 2 != 0:
        for _ in range(N // 2):
            a, i = heappop(lower)
        a0, i0 = heappop(lower)
        for _ in range(N // 2):
            b, i = heappop(upper)
        b1, i1 = heappop(upper)
        print(-b1 - a0 + 1)
    else:
        for _ in range(N // 2 - 1):
            a, i = heappop(lower)
        a0, i0 = heappop(lower)
        a1, i1 = heappop(lower)
        for _ in range(N // 2 - 1):
            b, i = heappop(lower)
        b0, i0 = heappop(upper)
        b1, i1 = heappop(upper)
        print((-b1 - b0) - (a1 + a0) + 1)


    

if __name__ == "__main__":
    main()

Submission status: Wrong Answer

Solution code:
N = int(input())
ab = []
for i in range(N):
    ab.append(tuple(map(int,input().split())))
 
up = sorted(ab,key=lambda a:a[0],reverse=True)
down = sorted(ab,key=lambda a:a[1],reverse=True)
 
if N%2 == 1:
    print(up[N//2][1]-down[N//2][0]+1)
else:
    up2 = sorted(ab,key=lambda a:a[0])
    down2 = sorted(ab,key=lambda a:a[1])
    r = (up[N//2][1]+up2[N//2][1])
    l = (down[N//2][0]+down2[N//2][0])
    print(r-l+1)

Submission status: Wrong Answer

Solution code:
import sys, re
from collections import deque, defaultdict, Counter
from math import ceil, sqrt, hypot, factorial, pi, sin, cos, radians, gcd
from itertools import accumulate, permutations, combinations, product, groupby, combinations_with_replacement
from operator import itemgetter, mul
from copy import deepcopy
from string import ascii_lowercase, ascii_uppercase, digits
from bisect import bisect, bisect_left
from heapq import heappush, heappop
from functools import reduce
def input(): return sys.stdin.readline().strip()
def INT(): return int(input())
def MAP(): return map(int, input().split())
def LIST(): return list(map(int, input().split()))
def ZIP(n): return zip(*(MAP() for _ in range(n)))
sys.setrecursionlimit(10 ** 9)
INF = float('inf')
mod = 10 ** 9 + 7

N = INT()
A, B = ZIP(N)

if N%2 == 0:
	l = (A[N//2]+A[N//2-1])/2
	r = (B[N//2]+B[N//2-1])/2
	print(int((r-l)*2)+1)
else:	
	print(B[N//2]-A[N//2]+1)

Submission status: Wrong Answer

Solution code:
n = int(input())
min_s = []
max_s = []
for i in range(n):
    a, b = map(int, input().split())
    min_s.append(a)
    max_s.append(b)

min_s.sort()
max_s.sort()
if n % 2 == 0:
    min_med = (min_s[n//2-1] + min_s[n//2-1])/2
    max_med = (max_s[n//2-1] + max_s[n//2-1])/2
    print(int(max_med-min_med)*2+1)

else:
    min_med = min_s[(n+1)//2-1]
    max_med = max_s[(n+1)//2-1]
    print(int((max_med-min_med)+1))

Submission status: Wrong Answer

Solution code:
N = int(input())
ab = []
for i in range(N):
    ab.append(tuple(map(int,input().split())))
 
up = sorted(ab,key=lambda a:a[0],reverse=True)
down = sorted(ab,key=lambda a:a[1],reverse=True)
 
if N%2 == 1:
    print(up[N//2][1]-down[N//2][0]+1)
else:
    up2 = sorted(ab,key=lambda a:a[0],reverse=True)
    down2 = sorted(ab,key=lambda a:a[1],reverse=True)
    r = (up[N//2][1]+up2[N//2][1])
    l = (down[N//2][0]+down2[N//2][0])
    print(r-l+1)

Submission status: Wrong Answer

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

lb = sorted(v for v, _ in X)[N // 2 - 1 + N % 2]
ub = sorted(v for _, v in X)[N // 2 - 1 + N % 2]

if N % 2 == 0:
    print((ub - lb) * 2 + 1)
else:
    print(ub - lb + 1)

Submission status: Wrong Answer

Solution code:
N = int(input())
ab = []
for i in range(N):
    ab.append(tuple(map(int,input().split())))
 
up = sorted(ab,key=lambda a:a[0],reverse=True)
down = sorted(ab,key=lambda a:a[1])
 
if N%2 == 1:
    print(up[N//2][1]-down[N//2][0]+1)
else:
    r = (up[N//2-1][1]+up[N//2][1])
    l = (down[N//2-1][0]+down[N//2][0])
    print(r-l+1)

Submission status: Wrong Answer

Solution code:
N = int(input())
ab = []
for i in range(N):
    ab.append(tuple(map(int,input().split())))
 
up = sorted(ab,key=lambda a:a[0])
down = sorted(ab,key=lambda a:a[1],reverse=True)
 
if N%2 == 1:
    print(up[N//2][1]-down[N//2][0]+1)
else:
    r = (up[N//2-1][1]+up[N//2][1])
    l = (down[N//2-1][0]+down[N//2][0])
    print(r-l+1)

Submission status: Wrong Answer

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

if n%2==0:
    min_sum = (x[(n//2)-1][0]+x[(n//2)][0])/2
    max_sum = (x[(n//2)-1][1]+x[(n//2)][1])/2
    print(int((max_sum-min_sum)//0.5)+1)
else:
    tmp = x[n//2]
    print(tmp[1]-tmp[0]+1)

Submission status: Wrong Answer

Solution code:
from heapq import heappush
n=int(input())
A=[]
B=[]
for i in range(n):
  a,b=map(int,input().split())
  heappush(A,a)
  heappush(B,b)
if n%2:
  c=(n+1)//2-1
  print(B[c]-A[c]+1)
else:
  c=n//2
  print(int(((B[c]+B[c-1])/2-(A[c]+A[c-1])/2)//0.5+1))