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] * N
B = [0] * N

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

A.sort()
B.sort()

print(A, B)
if N % 2 == 0:
    n1 = N // 2 - 1
    n2 = N // 2
    ans = B[n1] - A[n1] + B[n2] - A[n2] + 1
    print(ans)

else:
    n = N // 2
    ans = B[n] - A[n] + 1
    print(ans)

Submission status: Wrong Answer

Solution code:
mi = []
ma = []
n = int(input())

for _ in range(n):
    A, B = [int(a) for a in input().split()]
    mi.append(A)
    ma.append(B)

mi.sort()
ma.sort()
MI = min(mi[int(n/2)], mi[int((n-1)/2)])
MA = max(ma[int(n/2)], ma[int((n-1)/2)])

print(MA-MI+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)

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

else:
    print(B[N//2]-A[N//2]+1)

Submission status: Wrong Answer

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

Submission status: Wrong Answer

Solution code:
from statistics import median

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

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

Submission status: Wrong Answer

Solution code:
import sys                                               
n = int(sys.stdin.readline())                            
xs = []                                                  
for _ in range(n):                                       
  v = [int(x) for x in sys.stdin.readline().split(" ")]  
  xs.append(v)                                           
                                                         
xs.sort(key=lambda x: x[0])                              
if n % 2 == 0:                                           
  m1 = n // 2 - 1                                        
  m2 = m1 + 1                                            
  a1 = xs[m1][0]                                         
  a2 = xs[m2][0]                                         
  xs.sort(key=lambda x: x[1])                            
  b1 = xs[m1][1]                                         
  b2 = xs[m2][1]                                         
  a = (a1 + b1)                                          
  b = (a2 + b2)                                          
  c = (b - a) + 1                                        
  #print(m1, m2, a1, a2, b1, b2, "*", a, b, c)           
  print(c)                                               
else:                                                    
  m = (n + 1) // 2 - 1                                   
  a = xs[m][0]                                           
  xs.sort(key=lambda x: x[1])                            
  b = xs[m][1]                                           
  c = b - a + 1                                          
  #print(m, a, b, c)                                     
  print(c)

Submission status: Wrong Answer

Solution code:
def make_divisors(n):
    divisors = []
    for i in range(1, int(n**0.5)+1):
        if n % i == 0:
            if i!=1:
                divisors.append(i)
            if i != n // i:
                divisors.append(n//i)

    # divisors.sort()
    return divisors

def resolve():
    N = int(input())
    divs = make_divisors(N)
    divs.sort()
    count = 0
    pdivs = []
    while divs:
        pdivs.append(divs[0])
        divs = [i for i in divs if i % divs[0] != 0]

    count = 0
    for i in pdivs:
        x = i
        while N % x ==0:
            count +=1
            N //= x
            x *= i
    print(count)
resolve()

Submission status: Wrong Answer

Solution code:
import sys
N=int(sys.stdin.readline().strip())
A=[]
B=[]
for _ in range(N):
    a,b=map(int, sys.stdin.readline().split())
    A.append(a)
    B.append(b)
A.sort()
B.sort(reverse=True)
if N%2==1:
    print B[N/2]-A[N/2]+1
else:
    print (B[N/2-1]-A[N/2-1])*2-1

Submission status: Wrong Answer

Solution code:
import numpy as np

#f = open('./input_E.txt')
#
#N = int(f.readline())
#A = []
#B = []
#for i in range(N):
#    a,b=map(int, f.readline().split())
#    A.append(a)
#    B.append(b)
    
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()

A_array = np.array(A)
B_array = np.array(B)

A_argsort = np.argsort(A)
B_argsort = np.argsort(B)
A_argsort_rev = np.argsort(A)[::-1]
B_argsort_rev = np.argsort(B)[::-1]


#start_list = []
#stop_list = []
#
#possible = False
#for i,b in enumerate(B):
#    A_small = A_array[A_array <= b]
#    alive = len(A_small) - i
#    if not possible:
#        if alive >= (N+1)/2:
#            start = A[(N+1)//2+i-1]
#            start_list.append(start)
#            possible = True
#    else:
#        if alive <= (N+1)/2:
#            stop = B[i]
#            stop_list.append(stop)
#            possible = False
#
#cnt=0
#for i in range(len(start_list)):
#    cnt += stop_list[i]-start_list[i]+1
#    
#print(cnt)

AB = np.array([A,B])
AB_Asort = AB[:,A_argsort]
AB_Bsort_rev = AB[:,B_argsort_rev]

if N%2==1:
    sup_start = AB_Asort[0,(N-1)//2]
    sup_end = AB_Asort[1,:(N-1)//2+1].max()
    inf_end = AB_Bsort_rev[1,(N-1)//2]
    inf_start =  AB_Bsort_rev[0,:(N-1)//2+1].min()
#    if sup_end < inf_start:
#        ans = 0
#    else:
    sup_inf = [sup_start, sup_end, inf_start, inf_end]
    sup_inf.sort()
    ans = sup_inf[2]-sup_inf[1]+1
        
else:
    sup_start1 = AB_Asort[0,N//2-1]
    sup_end1 = AB_Asort[1,:N//2].max()
    inf_end1 = AB_Bsort_rev[1,N//2]
    inf_start1 =  AB_Bsort_rev[0,:N//2+1].min()
    
    sup_inf1 = [sup_start1, sup_end1, inf_start1, inf_end1]
    sup_inf1.sort()
    region1 = [sup_inf1[1],sup_inf1[2]]

    sup_start2 = AB_Asort[0,N//2]
    sup_end2 = AB_Asort[1,:N//2+1].max()
    inf_end2 = AB_Bsort_rev[1,N//2-1]
    inf_start2 =  AB_Bsort_rev[0,:N//2].min()

    sup_inf2 = [sup_start2, sup_end2, inf_start2, inf_end2]
    sup_inf2.sort()
    region2 = [sup_inf2[1],sup_inf2[2]]    
    
    l = max(region1[1]-region2[0],0)
    n1 = region1[1]-region1[0]+1
    n2 = region2[1]-region2[0]+1
    
    n = min(n1,n2)
    m = max(n1,n2)
    
    ans = n*m - n*(n-1)//2 -l*(l+1)//2

print(str(int(ans)))

Submission status: Wrong Answer

Solution code:
def main():
    N = int(input())
    A,B = [],[]
    for _ in range(N):
        a,b = [int(x) for x in input().split()]
        A.append(a)
        B.append(b)
    A.sort()
    B.sort()
    if N % 2 == 1:
        minMed = A[N//2]
        maxMed = B[N//2]
        print(int(maxMed-minMed)+1)
    else:
        minMed = (A[N//2-1] + A[N//2]) / 2
        maxMed = (B[N//2-1] + B[N//2]) / 2
        print(int(maxMed-minMed)+2)

if __name__ == '__main__':
    main()

Submission status: Wrong Answer

Solution code:
from statistics import median
N=int(input())
a,b=[],[]
#print(map(int,input().split())
for i in range(N):
  i,j=map(int,input().split())
  a.append(i)
  b.append(j)
amed,bmed=median(a),median(b)
  
if N%2==1:
  print(bmed-amed+1)
else:
  print(2*(bmed-amed)+1)

Submission status: Wrong Answer

Solution code:
import sys

readline = sys.stdin.readline
N = int(readline())
A = []
B = []
for _ in range(N):
    a, b = map(int, readline().split())
    A.append(a)
    B.append(b)
A.sort()
B.sort()
if N % 2 == 0:
    mi = (A[N//2-1]+A[N//2])//2
    ma = (B[N//2-1]+B[N//2])//2
    ans = (ma-mi)*2+1
else:
    mi = A[N//2]
    ma = B[N//2]
    ans = (ma-mi)+1
print(ans)

Submission status: Wrong Answer

Solution code:
import sys

readline = sys.stdin.readline
N = int(readline())
A = []
B = []
for _ in range(N):
    a, b = map(int, readline().split())
    A.append(a)
    B.append(b)
A.sort()
B.sort()
if N % 2 == 0:
    mi = (A[N//2-1]+A[N//2])//2
    ma = (B[N//2-1]+B[N//2])//2
    ans = (ma-mi)*2+1
else:
    mi = A[(N+1)//2-1]
    ma = B[(N+1)//2-1]
    ans = (ma-mi)+1
print(ans)

Submission status: Wrong Answer

Solution code:
def main():
    from sys import setrecursionlimit, stdin
    from os import environ
    from collections import defaultdict, deque, Counter
    from math import ceil, floor, gcd
    from itertools import accumulate, combinations, combinations_with_replacement
    setrecursionlimit(10**6)
    dbg = (lambda *something: print(*something)) if 'TERM_PROGRAM' in environ else lambda *x: 0
    input = lambda: stdin.readline().rstrip()
    LMIIS = lambda: list(map(int,input().split()))
    II = lambda: int(input())
    P = 10**9+7
    INF = 10**9+10
    U = list()
    L = list()
    N = II()
    for i in range(N):
        a,b = LMIIS()
        U.append(b)
        L.append(a)
    U.sort()
    L.sort()
    if N % 2 == 1:
        upper = U[(1+N)//2-1]
        lower = L[(1+N)//2-1]
        print(int(upper-lower)+1)
    else:
        upper = (U[0]+U[-1])
        lower = (L[0] + L[-1])
        print(upper-lower+1)
    
    
        




    
main()

Submission status: Wrong Answer

Solution code:
def main():
    from sys import setrecursionlimit, stdin
    from os import environ
    from collections import defaultdict, deque, Counter
    from math import ceil, floor, gcd
    from itertools import accumulate, combinations, combinations_with_replacement
    setrecursionlimit(10**6)
    dbg = (lambda *something: print(*something)) if 'TERM_PROGRAM' in environ else lambda *x: 0
    input = lambda: stdin.readline().rstrip()
    LMIIS = lambda: list(map(int,input().split()))
    II = lambda: int(input())
    P = 10**9+7
    INF = 10**9+10
    U = list()
    L = list()
    N = II()
    for i in range(N):
        a,b = LMIIS()
        U.append(b)
        L.append(a)
    U.sort()
    L.sort()
    if N % 2 == 1:
        upper = U[(1+N)//2-1]
        lower = L[(1+N)//2-1]
        print(int(upper-lower)+1)
    else:
        upper = (U[0]+U[-1])/2
        lower = (L[0] + L[-1])/2
        print(int((upper-lower)*2+1))
    
    
        




    
main()

Submission status: Wrong Answer

Solution code:
N = int(input())
left = []
right = []
for _ in range(N):
    l, r = map(int, input().split())
    left.append(l)
    right.append(r)
left.sort()
right.sort()
if N%2==0:
    for i, (l, r) in enumerate(zip(left, right), 1):
        if i==N//2:
            L = l
            R = r
        if i==N//2+1:
            R +=r
            L += l
            print((R-L)*2-1)
else:
    for i, (l, r) in enumerate(zip(left, right), 1):
        if i==N//2+1:
            print(r-l+1)

Submission status: Wrong Answer

Solution code:
# E - Count Median

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:
    A_median = A[(N+1)//2-1]
    B_median = B[(N+1)//2-1]
    print(B_median - A_median + 1)
else:
    A_median = (A[N//2 - 1] + A[N//2])/2
    B_median = (B[N//2 - 1] + B[N//2])/2
    print(int(B_median - A_median)*2 + 1)

Submission status: Wrong Answer

Solution code:
N = int(input())
left = []
right = []
for _ in range(N):
    l, r = map(int, input().split())
    left.append(l)
    right.append(r)
left.sort()
right.sort()
if N%2==0:
    for i, (l, r) in enumerate(zip(left, right), 1):
        if i==N//2:
            L = (l+r)
        if i==N//2+1:
            R = (l+r)
            print((R-L)+1)
else:
    for i, (l, r) in enumerate(zip(left, right), 1):
        if i==N//2+1:
            print(r-l+1)

Submission status: Wrong Answer

Solution code:
N = int(input())
left = []
right = []
for _ in range(N):
    l, r = map(int, input().split())
    left.append(l)
    right.append(r)
left.sort()
right.sort()
if N%2==0:
    for i, (l, r) in enumerate(zip(left, right)):
        if i==N//2:
            L = (l+r)
        if i==N//2+1:
            R = (l+r)
            print((R-L)+1)
else:
    for i, (l, r) in enumerate(zip(left, right), 1):
        if i==N//2+1:
            print(r-l+1)

Submission status: Wrong Answer

Solution code:
from collections import defaultdict

N = int(input())

AB = [tuple(map(int, input().split())) for _ in range(N)]
ALL = []
ALL_append = ALL.append
for i in range(N):
    a = AB[i][0]
    b = AB[i][1]
    ALL_append((a, i))
    ALL_append((b, i))

ALL.sort()
# print (ALL)
dic = defaultdict(int)
for i, x in enumerate(ALL):
    dic[x] = i

lst1 = [0] * (2 * N + 1)
lst2 = [0] * (2 * N + 1)

for i, (a, b) in enumerate(AB):
    lst1[dic[(a, i)]] += 1
    lst2[dic[(b, i)]] += 1

for i in range(2 * N):
    lst1[i + 1] += lst1[i]
    lst2[i + 1] += lst2[i]

half = (N + 1) // 2

for i in range(2 * N + 1):
    if lst1[i] >= half:
        left1 = ALL[i][0]
        break

for j in range(i, 2 * N + 1):
    if lst2[j + 1] > half:
        left2 = ALL[j][0]
        break

# print (left1, left2)

lst1 = [0] * (2 * N + 1)
lst2 = [0] * (2 * N + 1)

for i, (a, b) in enumerate(AB):
    lst1[dic[(a, i)]] += 1
    lst2[dic[(b, i)]] += 1

for i in range(2 * N, 0, -1):
    lst1[i - 1] += lst1[i]
    lst2[i - 1] += lst2[i]


for i in range(2 * N, 0, -1):
    if lst2[i] >= half:
        right1 = ALL[i][0]
        break

for j in range(i, 0, -1):
    if lst1[j - 1] > half:
        right2 = ALL[j][0]
        break

# print (right2, right1)

if N % 2 == 1:
    print (left2 - left1 + 1)
else:
    min_ = left1 + right2
    max_ = left2 + right1
    print (max_ - min_ + 1)

Submission status: Wrong Answer

Solution code:
N = int(input())
left = []
right = []
for _ in range(N):
    l, r = map(int, input().split())
    left.append(l)
    right.append(r)
left.sort()
right.sort()
if N%2==0:
    for i, (l, r) in enumerate(zip(left, right[1:]), 1):
        if i==N//2:
            print((r-l)*2-1)
else:
    for i, (l, r) in enumerate(zip(left, right), 1):
        if i==N//2+1:
            print(r-l+1)

Submission status: Wrong Answer

Solution code:
import statistics
import math

n = int(input())
 
a = []
for _ in range(n):
    a.append(list(map(int,input().split())))

b = [[],[]]
for i in range(n):
    b[0].append(a[i][0])
    b[1].append(a[i][1])

x = statistics.median(b[0])
y = statistics.median(b[1])

if n % 2 != 0:
    ans = y - x + 1

else:
    ans = round(y - x) * 2 + 1

print(ans)

Submission status: Wrong Answer

Solution code:
n = int(input())

ab = [list(map(int, input().split())) for _ in range(n)]
ab_a = sorted(ab, key=lambda x:int(x[1]))
ab_b = sorted(ab, key=lambda x:int(x[1]))

if n%2 == 1:
    print(ab_b[n//2][1]-ab_a[n//2][0]+1)
else:
    print(int(((ab_b[n//2][1]+ab_b[n//2-1][1])/2.0-(ab_a[n//2][0]+ab_a[n//2-1][0])/2.0)*2+1))

Submission status: Wrong Answer

Solution code:
N = int(input())

A = [None] * N
B = [None] * N

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

medians = []

if N % 2 == 0:
    a_median = (A[N // 2 - 1] + A[N // 2]) // 2
    b_median = (B[N // 2 - 1] + B[N // 2]) // 2
    ans = abs(a_median - b_median) * 2 + 1
else:
    a_median = A[(N + 1) // 2 - 1]
    b_median = B[(N + 1) // 2 - 1]
    ans = abs(a_median - b_median) + 1

print(ans)

Submission status: Wrong Answer

Solution code:
n=int(input())
ab,ba=[],[]
for i in range(n):
    a,b=map(int,input().split())
    ab.append([a,b])
ab.sort()
ans=0
if n%2==1:
    s=ab[n//2][0]
    g=ab[n//2][1]
    ans=g-s+1
else:
    s1,s2=ab[n//2-1][0],ab[n//2][0]
    g1,g2=ab[n//2-1][1],ab[n//2][1]
    ans=(g2+g1)-(s2+s1)+1
print(ans)

Submission status: Wrong Answer

Solution code:
n = int(input())
ab = [list(map(int, input().split())) for _ in range(n)]
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]

if n % 2 == 0:
    print((r-l)*2-1)
else:
    print(r-l+1)

Submission status: Wrong Answer

Solution code:
from statistics import median


def main():
    N = int(input())
    A = [None] * N
    B = [None] * N
    for i in range(N):
        A[i], B[i] = map(int, input().split())
    min_median = median(A)
    max_median = median(B)
    if N % 2 == 1:
        print(max_median - min_median + 1)
    else:
        print(max_median, min_median)
        print(round((max_median-min_median)*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()
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)

Submission status: Wrong Answer

Solution code:
n = int(input())
ab = [list(map(int, input().split())) for _ in range(n)]
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(l,r)
print(r-l+1)

Submission status: Wrong Answer

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

Submission status: Wrong Answer

Solution code:
from statistics import median


def main():
    N = int(input())
    A = [None] * N
    B = [None] * N
    for i in range(N):
        A[i], B[i] = map(int, input().split())
    min_median = median(A)
    max_median = median(B)
    if N % 2 == 1:
        print(max_median - min_median + 1)
    else:
        print(round(max_median-min_median)*2+1)


if __name__ == "__main__":
    main()

Submission status: Wrong Answer

Solution code:
n = int(input())
minnums = [[] for _ in range(n)]
maxnums = [[] for _ in range(n)]

for i in range(n):
  minnums[i], maxnums[i] = map(int, input().split())
  
minnums.sort()
maxnums.sort()

if n % 2:
  minmedian = minnums[n // 2]
  maxmedian = maxnums[n // 2]
  print(maxmedian - minmedian + 1)
else:
  minmedian = (minnums[n // 2 - 1] + minnums[n // 2]) / 2
  maxmedian = (maxnums[n // 2 - 1] + maxnums[n // 2]) / 2
  print(int((maxmedian - minmedian) * 2 + 1))


print(minmedian, maxmedian)

Submission status: Wrong Answer

Solution code:
#
# 　　  ⋀_⋀　 
#　　  (･ω･)  
# .／ Ｕ ∽ Ｕ＼
#  │＊　合　＊│
#  │＊　格　＊│ 
#  │＊　祈　＊│ 
#  │＊　願　＊│ 
#  │＊　　　＊│ 
#      ￣
#
import sys
sys.setrecursionlimit(10**6)
input=sys.stdin.readline
from math import floor,sqrt,factorial,hypot,log #log2ないｙｐ
from heapq import heappop, heappush, heappushpop
from collections import Counter,defaultdict,deque
from itertools import accumulate,permutations,combinations,product,combinations_with_replacement
from bisect import bisect_left,bisect_right
from copy import deepcopy
from fractions import gcd
from random import randint
def ceil(a,b): return (a+b-1)//b
inf=float('inf')
mod = 10**9+7
def pprint(*A): 
    for a in A:     print(*a,sep='\n')
def INT_(n): return int(n)-1
def MI(): return map(int,input().split())
def MF(): return map(float, input().split())
def MI_(): return map(INT_,input().split())
def LI(): return list(MI())
def LI_(): return [int(x) - 1 for x in input().split()]
def LF(): return list(MF())
def LIN(n:int): return [I() for _ in range(n)]
def LLIN(n: int): return [LI() for _ in range(n)]
def LLIN_(n: int): return [LI_() for _ in range(n)]
def LLI(): return [list(map(int, l.split() )) for l in input()]
def I(): return int(input())
def F(): return float(input())
def ST(): return input().replace('\n', '')
def main():
    N=I()
    AB=LLIN(N)
    l = []
    r = []
    for a,b in AB:
        l.append(a)
        r.append(b)
    l.sort()
    r.sort(reverse = True)

    l_lim = l[(N-1)//2]
    r_lim = r[(N-1)//2]
    # print(l_lim, r_lim)
    if(N&1):
        print(r_lim - l_lim + 1)
    else:
        l_lim2 = l[(N-1)//2 + 1]
        r_lim2 = r[(N-1)//2 + 1]
        l_lim2 *= 2
        r_lim2 *= 2
        l_lim  *= 2
        r_lim  *= 2
        # print("lim2",l_lim2, r_lim2)
        ans = max(0,(r_lim2 - l_lim2) + 1)
        # print(ans)
        L_low = (l_lim + l_lim2)//2
        L_high = min(l_lim2, (l_lim2 + r_lim)//2)
        # print("L",L_low, L_high)
        ans += int((L_high - L_low))
        R_low = max(r_lim2,(r_lim2 + l_lim)//2)
        R_high = (r_lim + r_lim2)//2
        # print("R",R_low,R_high)
        ans += int((R_high - R_low))
        # print("A")
        print(ans)
    # ABL=sorted(AB, key=lambda x:x[1])
    # ABR=sorted(AB, key=lambda x:x[0],reverse = True)

    # left_lim = 0
    # for a,b in ABL[:(N-1)//2]:
    #     left_lim = max(left_lim, b)
    
    # right_lim = inf
    # for a,b in ABR[:(N-1)//2]:
    #     right_lim = min(a, right_lim)
    
    # print(left_lim, right_lim)


if __name__ == '__main__':
    main()

Submission status: Wrong Answer

Solution code:
n = int(input())
ab = [tuple(map(int, input().split())) for _ in range(n)]
a, b = map(list, zip(*ab))
a.sort()
b.sort(reverse=True)
a1, b1 = a[n//2], b[n//2]
a2, b2 = a[n//2-1], b[n//2-1]
ans = b1 - a1 + 1
if n % 2 == 0:
    ans += int((b1+b2)/2 - (a1+a2)/2 + 1)
    if a1 == a2 and b1 == b2: ans -= 1

print(ans)

Submission status: Wrong Answer

Solution code:
import math,string,itertools,fractions,heapq,collections,re,array,bisect,sys,copy,functools
import time,random

sys.setrecursionlimit(10**7)
inf = 10**20
eps = 1.0 / 10**10
mod = 10**9+7
mod2 = 998244353
dd = [(-1,0),(0,1),(1,0),(0,-1)]
ddn = [(-1,0),(-1,1),(0,1),(1,1),(1,0),(1,-1),(0,-1),(-1,-1)]

def LI(): return list(map(int, sys.stdin.readline().split()))
def LLI(): return [list(map(int, l.split())) for l in sys.stdin.readlines()]
def LI_(): return [int(x)-1 for x in sys.stdin.readline().split()]
def LF(): return [float(x) for x in sys.stdin.readline().split()]
def LS(): return sys.stdin.readline().split()
def I(): return int(sys.stdin.readline())
def F(): return float(sys.stdin.readline())
def S(): return input()
def pf(s): return print(s, flush=True)
def pe(s): return print(str(s), file=sys.stderr)
def JA(a, sep): return sep.join(map(str, a))
def JAA(a, s, t): return s.join(t.join(map(str, b)) for b in a)


def main():
    n = I()
    ab = [LI() for _ in range(n)]
    aa = sorted(map(lambda x: x[0], ab))
    ba = sorted(map(lambda x: x[1], ab))

    if n % 2 == 1:
        a = aa[n//2]
        b = ba[n//2]
        return b - a + 1
    a1 = aa[n//2-1]
    a2 = aa[n//2]
    b1 = ba[n//2-1]
    b2 = ba[n//2]

    r = b2 - b1 + 1
    r += a2 - a1 + 1

    return r - 1

print(main())

Submission status: Wrong Answer

Solution code:
import numpy as np
n = int(input())
A, B = [], []
for _ in range(n):
    a,b = map(int,input().split())
    A.append(a)
    B.append(b)

x = np.median(A)
y = np.median(B)
if n%2==0:
    print(int((y-x)/0.5+1))
else:
    print(y-x+1)

Submission status: Wrong Answer

Solution code:
import statistics
import math

n = int(input())
aa,bb = [],[]

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

Submission status: Wrong Answer

Solution code:
n = int(input())
A = [-1] * n
B = [-1] * n
for i in range(n):
    A[i], B[i] = map(int, input().split())

A.sort()
B.sort()

if n % 2 == 1:
    avrA = A[n // 2]
    avrB = B[n // 2]

    print(avrB - avrA + 1)
else:
    avr_low_A = A[n // 2 - 1]
    avr_high_A = A[n // 2]
    avr_low_B = B[n // 2 - 1]
    avr_high_B = B[n // 2]

#     x = avr_low_B - avr_low_A + 1
#     y = avr_high_B - avr_high_A + 1
#     sum = 0
#     if x > y:
#         x, y = y, x
#     for i in range(2, x + 1):
#         m = (y - x + 1) * x
#         sum += x + y - m + 1
#
    print((avr_high_A + avr_high_B) - (avr_low_A + avr_low_B) + 1)

Submission status: Wrong Answer

Solution code:
import sys
sys.setrecursionlimit(10**9)

def main():
    N = int(input())
    rg = []

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

    rg.sort()
    if N % 2 == 1:
        a,b = rg[N//2]
        print(b-a+1)
        exit()

    a,b = rg[N//2-1]
    c,d  =rg[N//2]

    print(b+d-a-c+1)


if __name__ == "__main__":
  main()

Submission status: Wrong Answer

Solution code:
import sys
sys.setrecursionlimit(10**9)

def main():
    N = int(input())
    rg = []

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

    rg.sort()
    if N % 2 == 1:
        a,b = rg[(N+1)//2-1]
        print(b-a+1)
        exit()

    a,b = rg[N//2-1]
    c,d  =rg[N//2]

    print(b+d-a-c+1)




if __name__ == "__main__":
  main()

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)
m_a = median(A)
m_b = median(B)

m = m_b - m_a
if m == 0:
    print(1)
elif m == 0.5:
    print(2)
else:
    a, b = m_a, m_b
    if type(m_a) is float:
        a = int(m_a + 0.5)
    if type(m_b) is float:
        b = int(m_b)
    m = b - a + 1
    for ab in [m_a, m_b]:
        if type(ab) is float:
            m += 1
    print(m)

Submission status: Wrong Answer

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

lab = len(AB)

if lab%2 != 0:
  ans = AB[N//2][1]-AB[N//2][0]+1
else:
  ans = max(AB[N//2][1],AB[N//2-1][1])-min(AB[N//2][0],AB[N//2-1][0])+1

print(ans)

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)
m_a = median(A)
m_b = median(B)
m = m_b - m_a
if m == 0:
    print(1)
    exit()
if n%2 == 0:
    m += 2
else:
    m += 1

print(int(m))

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)
m_a = median(A)
m_b = median(B)
m = m_b - m_a
if n%2 == 0:
    m += 2
else:
    m += 1

print(int(m))

Submission status: Wrong Answer

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

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 +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())
ab =[list(map(int,input().split())) for _ in range(n)]

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 +1
else:
  ca = a[(n+1)//2-1]
  cb = b[(n+1)//2-1]
  ans = (cb-ca)//0.5 +1

print(int(ans))

Submission status: Wrong Answer

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

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

print(int(ans))

Submission status: Wrong Answer

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

if n%2==0:
    idx_1,idx_2=(n-2)//2, (n-2)//2 + 1
    print(abs(a_ls[idx_1]+a_ls[idx_2]-b_ls[idx_1]-b_ls[idx_2])+1)
else:
    idx=(n-1)//2
    print(abs(a_ls[idx]-b_ls[idx])+1)

Submission status: Wrong Answer

Solution code:
n=int(input())
ab=[list(map(int, input().split())) for _ in range(n)]
a=[]
b=[]
for a_i, b_i in ab:
    a.append(a_i)
    b.append(b_i)
a.sort()
b.sort()

import statistics
a_med=statistics.median(a)
b_med=statistics.median(b)

if n%2==0:
    ans=2*b_med-2*a_med+1
else:
    ans=b_med-a_med+1
print(ans)

Submission status: Wrong Answer

Solution code:
n=int(input())
ab=[list(map(int, input().split())) for _ in range(n)]
a=[]
b=[]
for a_i, b_i in ab:
    a.append(a_i)
    b.append(b_i)
a.sort()
b.sort()

import statistics
a_med=statistics.median(a)
b_med=statistics.median(b)

if n%2==0:
    print(int(int(b_med-a_med)/0.5+1))
else:
    print(int(b_med-a_med+1))

Submission status: Wrong Answer

Solution code:
#!/usr/bin/env python3
# from typing import *
import sys
import math
input = sys.stdin.readline
sys.setrecursionlimit(10**6)


def solve(N, A, B):
    sorted(A)
    sorted(B)
    if N % 2 == 0:
        print(B[N//2-1]+B[N//2] - (A[N//2-1]+A[N//2]) + 1)
    else:
        print(B[N//2] - A[N//2] + 1)

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

if __name__ == '__main__':
    main()
'''
cd ~/Desktop/Programming/AtCoder/contest/abc169/abc169_e && sh test_py.sh
cd ~/Desktop/Programming/AtCoder/contest/abc169/abc169_e && sh etest_py.sh
cd ~/Desktop/Programming/AtCoder/contest/abc169/abc169_e && sh submit_py.sh
'''

Submission status: Wrong Answer

Solution code:
import statistics
n = int(input())

a = [0 for _ in range(n)]
b = [0 for _ in range(n)]
ans = 0

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

ma = statistics.median(a)
mb = statistics.median(b)

if(n%2 == 1):
    ans = int(mb-ma) + 1
else:
    ans = 2*int(mb-ma) + 1

print(ans)

Submission status: Wrong Answer

Solution code:
import statistics
n = int(input())

a = [0 for _ in range(n)]
b = [0 for _ in range(n)]
ans = 0

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

ma = statistics.median(a)
mb = statistics.median(b)

if(n%2 == 1):
    ans = int(mb-ma)
else:
    ans = 2*int(mb-ma) + 1

print(ans)