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

Solution (Python):

import sys
input=sys.stdin.readline

N=int(input())
A=[0 for i in range(N)]
B=[0 for i in range(N)]

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

if N%2==0:
    f=(A_sort[int(N/2)]+A_sort[int(N/2)-1])/2
    t=(B_sort[int(N/2)]+B_sort[int(N/2)-1])/2
    ans=int((t-f)*2+1)
else:
    f=A_sort[int((N-1)/2)]
    t=B_sort[int((N-1)/2)]
    ans=int((t-f)+1)
    
print(ans)

Solution (Python):
import sys
sys.setrecursionlimit(10**6)


def main(input, print):
    n = int(input())
    li = [0] * n
    ri = [0] * n
    for i in range(n):
        li[i], ri[i] = map(int, input().split())
    li.sort()
    ri.sort()
    ans = 0
    if n % 2 == 1:
        l = li[n//2]
        r = ri[n//2]
        ans = r-l+1
    else:
        l = li[n//2-1]+li[n//2]
        r = ri[n//2-1]+ri[n//2]
        ans = r-l+1
    print(ans)


if __name__ == '__main__':
    main(sys.stdin.readline, print)

Solution (Python):
import itertools
N = int(input())
AB = [list(map(int, input().split())) for n in range(N)]
sortA = sorted(AB, key= lambda x:x[0])
sortB = sorted(AB, key= lambda x:x[1])
if N % 2 == 0:
  k1 = int(N/2-1)
  k2 = int(N/2)
  minM = sortA[k1][0] + sortA[k2][0]
  maxM = sortB[k1][1] + sortB[k2][1]
  print(maxM-minM+1)
else:
  k = int((N+1)/2)-1
  A = sortA[k][0]
  B = sortB[k][1]
  print(B-A+1)

Solution (Python):
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(reverse=True)
if N%2==1:
  mid = (N+1)//2-1
  ans = B[mid]-A[mid]+1
else:
  mid1 = N//2-1
  mid2 = N//2
  ans = (B[mid1]+B[mid2])-(A[mid1]+A[mid2])+1

print(ans)

Solution (Python):
import numpy as np

def solve():
    N = int(input())
    AB = np.array([list(map(int, input().split() )) for _ in range(N)], dtype=np.int64)
    A = AB[:,0]
    B = AB[:,1]
    Amed = np.median(A)
    Bmed = np.median(B)
    if N % 2 ==1:
        print(int(Bmed - Amed+1))
    else:
        print(int((Bmed - Amed )*2+1))


if __name__ == '__main__':
    solve()

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

def median(arr):
    arr.sort()
    n = len(arr)
    if n % 2 == 1:
        return arr[(n + 1) // 2 - 1]
    else:
        return (arr[n//2 - 1] + arr[n//2]) / 2

med_a = median(A)
med_b = median(B)
if N % 2 == 1:
    ans = int(med_b) - int(med_a) + 1
else:
    ans = med_b * 2 - med_a * 2 + 1
    ans = int(ans)

print(ans)

Solution (Python):
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:

    a = [ai for ai, bi in ab]
    b = [bi for ai, bi in ab]

    a.sort()
    b.sort()

    ll = a[n//2-1]
    lr = b[n//2-1]

    rl = a[n//2]
    rr = b[n//2]


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

Solution (Python):
n=int(input())
alis=[]
blis=[]
for i in range(n):
  a,b=map(int,input().split())
  alis.append(a)
  blis.append(b)
  
  
alis=sorted(alis)
blis=sorted(blis)
if n%2!=0:
  print(blis[int((n-1)/2)]-alis[int((n-1)/2)]+1)
else:
  bb=(blis[int(n/2)-1]+blis[int(n/2)])
  aa=(alis[int(n/2)-1]+alis[int(n/2)])
  print(bb-aa+1)

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

A.sort()
B.sort()
if N%2 == 1:
  med_minimum = A[(N-1)//2]
  med_maximum = B[(N-1)//2]
else:
  med_minimum = (A[(N-2)//2] + A[(N-2)//2+1])
  med_maximum = (B[(N-2)//2] + B[(N-2)//2+1])
print(med_maximum - med_minimum + 1)

Solution (Python):
from decimal import *

n = int(input())

a = []; b = []
ans = 0
for i in range(n):
    ai, bi = map(int,input().split())
    a.append(ai); b.append(bi)
a.sort()
b.sort()

if n % 2 == 1:
    med = (n + 1) // 2
    ans = (b[med - 1] - a[med - 1]) + 1
    print(int(ans))
else:
    med0 = n // 2
    med1 = (n // 2) + 1
    amed = (Decimal(a[med0-1])+Decimal(a[med1-1]))/Decimal(2)
    bmed = (Decimal(b[med0-1])+Decimal(b[med1-1]))/Decimal(2)
    ans = int(((bmed - amed) * Decimal(2) + Decimal(1)))
    print(ans)

Solution (Python):
from sys import stdin
readline = stdin.readline

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

A.sort()
B.sort()

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

Solution (Python):
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

A.sort()
B.sort()

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

Solution (Python):
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)
    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])
        max_m = (new_b[n // 2 - 1] + new_b[n // 2])
        print((max_m - min_m) + 1)


if __name__ == '__main__':
    main()

Solution (Python):
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()
ans = 0
if n % 2 == 1:
    ans = B[n // 2] - A[n // 2] + 1
else:
    large = B[n // 2] + B[n // 2 - 1]
    small = A[n // 2] + A[n // 2 - 1]
    ans = large - small + 1

print(ans)

Solution (Python):
def main():
    n = int(input())
    a = []
    b = []
    for _ in range(n):
        ta, tb = [int(i) for i in input().split()]
        a.append(ta)
        b.append(tb)
    a = sorted(a)
    b = sorted(b)

    if n % 2:
        mid_idx = (n + 1)//2 -1
        print(b[mid_idx] -a[mid_idx] + 1)
    else:
        mid_idx = [n//2 - 1, n//2]
        mid_a = (a[mid_idx[1]] + a[mid_idx[0]])
        mid_b = (b[mid_idx[1]] + b[mid_idx[0]])
        print(mid_b - mid_a + 1)

if __name__ == '__main__':
    main()

Solution (Python):
N = int(input())
A = [0 for _ in range(N)]
B = [0 for _ in range(N)]

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

A_sort = sorted(A)
B_sort = sorted(B)

if N % 2 == 1:
    print(B_sort[N//2] - A_sort[N//2] + 1)
else:
    med_A = (A_sort[N//2] + A_sort[N//2 - 1])
    med_B = (B_sort[N//2] + B_sort[N//2 - 1])
    print(med_B - med_A + 1)

Solution (Python):
n = int(input())

v1, v2 = [], []
for _ in range(n):
    a, b = map(int, input().split())
    v1.append(a)
    v2.append(b)
v1.sort()
v2.sort()

if n & 1:
    m = n // 2
    print(v2[m] - v1[m] + 1)
else:
    m = n // 2
    print(v2[m-1]-v1[m-1] + v2[m]-v1[m] + 1)

Solution (Python):
ii = lambda : int(input())
mi = lambda : map(int,input().split())
li = lambda : list(map(int,input().split()))

import statistics as st

n = ii()
a = []
b = []
for i in range(n):
    aa,bb = mi()
    a.append(aa)
    b.append(bb)

a.sort()
b.sort()

minmed = st.median(a)
maxmed = st.median(b)

if len(a) %2 == 0:
    ans = maxmed*2 - minmed*2 + 1
else:
    ans = maxmed-minmed+1
print(int(ans) )

Solution (Python):
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()

Solution (Python):
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()

Solution (Python):
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))

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

lb = sorted(v for v, _ in X)
ub = sorted(v for _, v in X)

if N % 2 == 0:
    l = lb[N // 2 - 1] + lb[N // 2]
    u = ub[N // 2 - 1] + ub[N // 2]
    print(u - l + 1)
else:
    l = lb[N // 2]
    u = ub[N // 2]
    print(u - l + 1)

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

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

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

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

Solution (Python):
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.sort()
    R.sort()
        
    
    
        
    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()

Solution (Python):
import numpy as np

n = int(input())

a = []
b = []


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

a_med = np.median(a)
b_med = np.median(b)

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

Solution (Python):
N = int(input())

a_array = []
b_array = []

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

a_array.sort()
b_array.sort()

if N % 2 != 0:
    mid_min = a_array[(N - 1) // 2]
    mid_max = b_array[(N - 1) // 2]
    print(mid_max - mid_min + 1)

else:
    mid_min = (a_array[N // 2 - 1] + a_array[N // 2]) / 2
    mid_max = (b_array[N // 2 - 1] + b_array[N // 2]) / 2
    print(int((mid_max - mid_min) * 2) + 1)

Solution (Python):
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])+(b[n//2-1]-a[n//2-1])+1
print (ans)

Solution (Python):
N = int(input())
A = [list(map(int, input().split())) for _ in range(N)]
AX = [A[i][0] for i in range(N)]
BX = [A[i][1] for i in range(N)]
AX.sort()
BX.sort()
if N % 2 == 1:
  L = AX[(N-1)//2]
  R = BX[(N-1)//2]
  print(R-L+1)
else:
  L = AX[N//2-1] + AX[N//2]
  R = BX[N//2-1] + BX[N//2]
  print(R-L+1)

Solution (Python):
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:
    m = n//2
    ans = b[m] - a[m] + 1
else:
    ml = n//2-1
    mr = n//2
    ma = (a[ml] + a[mr])/2 
    mb = (b[ml] + b[mr])/2
    ans = int((mb - ma)*2 + 1)
print(ans)

Solution (Python):
import sys
input = sys.stdin.readline
def main():
    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:
        print(b[n//2]-a[n//2]+1)
    else:
        print((b[n//2]+b[n//2-1]) - (a[n//2]+a[n//2-1])+1)
    
if __name__ == "__main__":
    main()

Solution (Python):

def main():
    N, *AB = map(int, open(0).read().split())
    A, B = AB[::2], AB[1::2]
    A.sort(), B.sort()
    mid = N // 2
    if N % 2:
        print(B[mid] - A[mid] + 1)
    else:
        print((B[mid] + B[mid - 1]) - (A[mid] + A[mid - 1]) + 1)


if __name__ == "__main__":
    main()

Solution (Python):
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(abs(A[N//2]-B[N//2])+1)
else:
    print(abs(A[N//2]+A[N//2-1]-B[N//2]-B[N//2-1])+1)

Solution (Python):
import sys
input = sys.stdin.readline

N = int(input())
AB = [[int(i) for i in input().split()] for _ in range(N)]
AB.sort()
ans = 0
if N & 1:
    l = AB[N//2][0]
    AB.sort(key=lambda x: x[1])
    ans = AB[N // 2][1] - l + 1
else:
    l = (AB[N // 2][0], AB[N // 2 - 1][0])
    AB.sort(key=lambda x: x[1])
    r = (AB[N // 2][1], AB[N // 2 - 1][1])
    ans = sum(r) - sum(l) + 1
print(ans)

Solution (Python):
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:
    front = n//2
    back = (n-1)//2
    print((b[front] + b[back] - (a[front] + a[back]) + 1))

Solution (Python):
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:
    min_m, max_m = a[n // 2], b[n // 2]
    ans = max_m - (min_m - 1)
else:
    min_m2 = a[n // 2] + a[n // 2 - 1]
    max_m2 = b[n // 2] + b[n // 2 - 1]
    ans = max_m2 - min_m2 + 1
print(ans)

Solution (Python):

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 = int(N/2)
    xmin = (A[n-1]+A[n])
    xmax = (B[n-1]+B[n])
    count = int(xmax)-int(xmin+0.5)+1
else:
    n = int((N+1)/2)
    xmin = A[n-1]
    xmax = B[n-1]
    count = xmax-xmin+1

print(count)

Solution (Python):
def median(q):
    l = len(q)
    q = sorted(q,reverse=True)
    if l%2 == 0:
        return (q[int(l/2)]+q[int(l/2)-1])/2
    else:
        return q[int((l+1)/2-1)]

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

med_a = median(a)  
med_b = median(b)  

if n%2 == 0:  
    print(int(2*(med_b-med_a)+1))
else:  
    print((med_b-med_a)+1)

Solution (Python):
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 == 0:
        p = (A[n//2-1] + A[n//2])/2
        q = (B[n//2-1] + B[n//2])/2
        print(int((q-p+0.5)*2))
    else:
        print(B[n//2] - A[n//2] + 1)

if __name__ == "__main__":
    main()

Solution (Python):
def calc_median(X):
    
    Xl = len(X)
    if Xl % 2:
        
        ret = X[Xl // 2]
    else:
        ret = (X[Xl // 2 - 1] + X[Xl // 2]) / 2

    return ret


N, *AB = map(int, open(0).read().split())

A = sorted(AB[::2])
B = sorted(AB[1::2])

AM = calc_median(A)
BM = calc_median(B)

if N % 2:
    ans = BM - AM + 1
else:
    ans = int((BM - AM) * 2 + 1)

print(ans)

Solution (Python):
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//2
  mid2 = mid1 - 1
  smallest = mins[mid1] + mins[mid2]
  largest = maxs[mid1] + maxs[mid2]
  print(largest - smallest + 1)

Solution (Python):
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:
    medi = N // 2
    ans = B[medi] - A[medi] + 1
else:
    medi1 = N // 2 - 1
    medi2 = medi1 + 1
    A_medi = (A[medi1] + A[medi2]) / 2
    B_medi = (B[medi1] + B[medi2]) / 2
    ans = (B_medi - A_medi) * 2 + 1
print(int(ans))

Solution (Python):
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 = int((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))

Solution (Python):

def main():
    import sys
    imput = sys.stdin.readline
    
    
    
    N = int(input())
    A, B = [0] * N, [0] * N
    for i in range(N):
        A[i], B[i] = map(int, input().split())

    
    import statistics as st
    import math

    p = st.median(A)
    q = st.median(B)

    
    if N % 2 == 0:
        print(int((q-p)/0.5)+1)
    else:
        print(int(q-p)+1)

    
if __name__ == "__main__":
    main()

Solution (Python):
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:
    n=N//2
    ans=B[n]-A[n]+1
else:
    n1=N//2-1
    n2=N//2
    ans=B[n1]-A[n1]+B[n2]-A[n2]+1

print(ans)

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

Solution (Python):
import sys
input=lambda: sys.stdin.readline().rstrip()
n=int(input())
A,B=[],[]
for _ in range(n):
  a,b=map(int,input().split())
  A.append(a)
  B.append(b)
A.sort()
B.sort()
if n%2==1:
  l=A[n//2]
  r=B[n//2]
  print(r-l+1)
else:
  l=A[n//2-1]+A[n//2]
  r=B[n//2-1]+B[n//2]
  print(r-l+1)

Solution (Python):
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 = (mi[int(n/2)] + mi[int((n-1)/2)])/2
ma = (ma[int(n/2)] + ma[int((n-1)/2)])/2

if n%2 == 0:
    print(int((ma-mi+0.5) * 2))
else:
    print(int(ma-mi+1))

Solution (Python):
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(int(2*(m2-m1))+1)
    else:
        print(B[(n+1)//2-1]-A[(n+1)//2-1]+1)    
main()

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

Solution (Python):
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)

Solution (Python):
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 + a2)                                           
  b = (b1 + b2)                                           
  c = (b - a) + 1                                         
  
  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(c)

Solution (Python):
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 len(A)%2 != 0:
  ans = B[N//2]-A[N//2]+1
else:
  ans = (B[N//2]+B[N//2-1]) - (A[N//2]+A[N//2-1]) + 1

print(ans)

Solution (Python):
import numpy as np

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

medA = np.median(Aarray)
medB = np.median(Barray)

if N%2 == 1:
    ans = medB-medA+1
else:
    ans = 2*(medB-medA)+1
    

print(str(int(ans)))

Solution (Python):
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()
if N%2==0:
    A_med=float(A[N/2]+A[N/2-1])/2
    B_med=float(B[N/2]+B[N/2-1])/2
    print int((B_med-A_med)*2+1)
else:
    A_med=A[N/2]
    B_med=B[N/2]
    print B_med-A_med+1

Solution (Python):
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]
        maxMed = B[N//2-1] + B[N//2]
        print(int(maxMed-minMed)+1)

if __name__ == '__main__':
    main()

Solution (Python):
def main():
    n = int(input())
    a_list = []
    b_list = []
    for _ in range(n):
        a, b = map(int, input().split())
        a_list.append(a)
        b_list.append(b)
    a_sorted = list(sorted(a_list))
    b_sorted = list(sorted(b_list))
    if n%2:
        print(b_sorted[n//2]-a_sorted[n//2]+1)
    else:
        print((b_sorted[n//2-1]+b_sorted[n//2]-a_sorted[n//2-1]-a_sorted[n//2])+1)
        

if __name__ == "__main__":
    main()

Solution (Python):
from statistics import median
N=int(input())
a,b=[],[]

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(int(bmed-amed+1))
else:
  print(int(2*(bmed-amed)+1))

Solution (Python):



def solve(N, As, Bs):
    As.sort()
    Bs.sort()
    ans = 0
    
    if N % 2 == 1:
        x = (N + 1) // 2 - 1
        ans = Bs[x] - As[x] + 1
    
    else:
        lowx = N // 2 - 1
        highx = N // 2
        ans = (Bs[lowx] + Bs[highx]) - (As[lowx] + As[highx]) + 1
    print(ans)
    pass


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

Solution (Python):
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]
    ma = B[N//2-1]+B[N//2]
else:
    mi = A[N//2]
    ma = B[N//2]
print(ma-mi+1)

Solution (Python):
import sys
sys.setrecursionlimit(10**6)
readline = sys.stdin.readline

n = int(input())

ls = []; rs = []
for _ in range(n):
    a,b = [int(i) for i in readline().split()]
    ls.append(a)
    rs.append(b)

ls.sort()
rs.sort()

ans = 0

if n%2 == 1:
    l = ls[n//2]
    r = rs[n//2]
    ans = r-l+1
else:
    l2 = ls[n//2-1]+ls[n//2]
    r2 = rs[n//2-1]+rs[n//2]
    ans = r2-l2+1

print(ans)

Solution (Python):
N = int(input())
As = []
Bs = []
for i in range(N):
  A, B = map(int, input().split())
  As.append(A)
  Bs.append(B)
As.sort()
Bs.sort()
if N%2 == 1:
  A = As[N//2]
  B = Bs[N//2]
  r = B-A+1
else:
  A = As[(N-1)//2]+As[N//2]
  B = Bs[(N-1)//2]+Bs[N//2]
  r = B-A+1
print(r)

Solution (Python):
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[N//2-1]+U[N//2])
        lower = (L[N//2-1]+L[N//2])
        print(upper-lower+1)
    
    
        




    
main()

Solution (Python):
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)+1)
else:
    for i, (l, r) in enumerate(zip(left, right), 1):
        if i==N//2+1:
            print(r-l+1)

Solution (Python):
N = int(input())

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

A.sort()
B.sort()

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

Solution (Python):


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

Solution (Python):
n = int(input())
al=[]
bl=[]
for i in range(n):
    a , b = map(int, input().split())
    al.append(a)
    bl.append(b)
al.sort()
bl.sort()
if n%2==1:
    mi = al[n//2]
    ma = bl[n//2]
    print(int(ma-mi)+1)
else:
    mi = (al[n//2-1]+al[n//2])/2
    ma = (bl[n//2-1]+bl[n//2])/2
    print(int((ma-mi)*2+1))

Solution (Python):
N = int(input())
lower = []
upper = []
for i in range(N):
    a, b = map(int, input().split())
    lower.append(a)
    upper.append(b)
lower.sort()
upper.sort()
if N % 2 == 1:
    print(upper[(N-1)//2]-lower[(N-1)//2]+1)
else:
    print(upper[N//2]+upper[N//2 - 1]-lower[N//2]-lower[N//2 - 1]+1)

Solution (Python):
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)

Solution (Python):
n = int(input())

ab = [list(map(int, input().split())) for _ in range(n)]
ab_a = sorted(ab, key=lambda x:int(x[0]))
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))

Solution (Python):
import numpy as np

n = int(input())
arr = np.array([[int(x) for x in input().split()] for _ in range(n)])
med_a = np.median(arr[:, 0])
med_b = np.median(arr[:, 1])

if n % 2 == 0:
    print(int(med_b * 2 - med_a * 2 + 1))
else:
    print(int(med_b - med_a + 1))

Solution (Python):
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(abs(median(b) - median(a)) + 1)
else:
    print(int(abs(median(b) - median(a)) * 2) + 1)

Solution (Python):
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(reverse=True)
ans=0
if n%2==1:
    s=a[n//2]
    g=b[n//2]
    ans=g-s+1
else:
    s1,s2=a[n//2-1],a[n//2]
    g2,g1=b[n//2-1],b[n//2]
    ans=(g2+g1)-(s2+s1)+1
print(ans)

Solution (Python):
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(abs(median(b) - median(a)) + 1)
else:
    print(int(abs(median(b) - median(a)) * 2) + 1)

Solution (Python):
import statistics
import math

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:
    ans = statistics.median(b) - statistics.median(a) + 1
else:
    ans = (statistics.median(b) - statistics.median(a))*2 + 1
print(int(ans))

Solution (Python):
from statistics import median

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

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

Solution (Python):
from statistics import median

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(abs(median(b) - median(a)) + 1)
else:
    print(int(abs(median(b) - median(a)) * 2) + 1)

Solution (Python):
from statistics import median

n = int(input())
ab = [list(map(int, input().split())) for _ in range(n)]
a = [i for i, j in ab]
b = [j for i, j in ab]

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

Solution (Python):
N = int(input())
A_list = []
B_list = []
for i in range(N):
    A, B = map(int, input().split())
    A_list.append(A)
    B_list.append(B)
sort_A = sorted(A_list)
sort_B = sorted(B_list)

if N % 2 == 0:
    center_A = (sort_A[N//2] + sort_A[N//2-1])/2
    center_B = (sort_B[N//2] + sort_B[N//2-1])/2
    print(int((center_B-center_A)*2)+1)
else:
    center_A = sort_A[N//2]
    center_B = sort_B[N//2]
    print(center_B-center_A+1)