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
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines

n = int(readline())
ab = list(map(int,read().split()))
a = ab[::2]
b = ab[1::2]
a.sort()
b.sort()

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

print(ans)

Solution (Python):
def N(): return int(input())
def NM():return map(int,input().split())
def L():return list(NM())
def LN(n):return [N() for i in range(n)]
def LL(n):return [L() for i in range(n)]
n=N()
l=LL(n)
l.sort()
if n%2==1:
    a,b=l[n//2]
    l.sort(key=lambda x:x[1])
    c,d=l[n//2]
    print(d-a+1)
else:
    l.sort()
    a,_=l[n//2-1]
    b,_=l[n//2]
    l.sort(key=lambda x:x[1])
    _,c=l[n//2-1]
    _,d=l[n//2]
    print(c+d-a-b+1)

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())
aa=[]
bb=[]
for _ in range(n):
  a,b=map(int,input().split())
  aa.append(a)
  bb.append(b)
aa.sort()
bb.sort()
if n%2==1:
  print(bb[n//2]-aa[n//2]+1)
else:
  am=aa[n//2]+aa[n//2-1]
  bm=bb[n//2]+bb[n//2-1]
  print(bm-am+1)

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

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:
    m = A[N//2]; M = B[N//2]
    print(M-m+1)
else:
    m1 = A[N//2-1]; m2 = A[N//2]
    M1 = B[N//2-1]; M2 = B[N//2]
    ans = M1 + M2 - (m1+m2) + 1
    print(ans)

Solution (Python):
import sys
input = sys.stdin.readline
n = int(input())
ab = [list(map(int,input().split())) for i in range(n)]
l,r = list(zip(*ab))
l = list(l)
r = list(r)
l.sort()
r.sort()
if n%2:
  print((r[n//2]-l[n//2])+1)
else:
  print(((r[n//2-1]+r[n//2])-(l[n//2-1]+l[n//2]))+1)

Solution (Python):
from statistics import median

la = []
lb = []
for _ in range(int(input())):
    a, b = map(int, input().split())
    la.append(a)
    lb.append(b)

ma = median(la)
mb = median(lb)
if len(la) % 2:
    print(int((mb - ma) + 1))
else:
    print(int(2 * (mb - ma) + 1))

Solution (Python):
import sys
import numpy as np

read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines

N = int(readline())
AB = np.array(read().split(), np.int64)

A = AB[::2]
B = AB[1::2]

A.sort()
B.sort()

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)

Solution (Python):
import sys
input = sys.stdin.buffer.readline
n=int(input())
l=[list(map(int,input().split())) for _ in range(n)]
l.sort()
if n%2:
	m=l[n//2][0]
else:
	m=(l[n//2-1][0]+l[n//2][0])/2
l.sort(key=lambda x:-x[1])
if n%2:
	M=l[n//2][1]
else:
	M=(l[n//2-1][1]+l[n//2][1])/2
if n%2:
	print(M-m+1)
else:
	print(int(2*(M-m)+1))

Solution (Python):
def main():
    n = int(input())
    ab = [list(map(int, input().split())) for _ in [0]*n]
    if n % 2 == 1:
        min_a = sorted([a for a, b in ab])[n//2]
        max_a = sorted([b for a, b in ab])[n//2]
        print(max_a-min_a+1)
    else:
        min_a = sum(sorted([a for a, b in ab])[n//2-1:n//2+1])*2
        max_a = sum(sorted([b for a, b in ab])[n//2-1:n//2+1])*2
        print((max_a-min_a+2)//2)


main()

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

ranges = [tuple(map(int,input().split())) for _ in range(N)]
A = sorted(a for a,b in ranges)
B = sorted(b for a,b in ranges)
if N % 2 == 0:
    a = A[N//2-1]+A[N//2]
    b = B[N//2-1]+B[N//2]
    print(b-a+1)
else:
    a = A[N//2]
    b = B[N//2]
    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())
def md(x):
    u = sorted(x)
    if len(u) % 2 == 0:
        return u[len(u) // 2] + u[len(u) // 2 - 1]
    else:
        return u[len(u) // 2]
u, v = md(a), md(b)
print(v - u + 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 & 1:
    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)

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

def solve_odd(n,AB):
    AB.sort()
    median_min=AB[n//2][0]
    AB.sort(key=lambda x: x[1])
    median_max=AB[n//2][1]
    
    return max(0,median_max-median_min+1)

def solve_even(n,AB):
    AB.sort()
    median_min=AB[n//2-1][0]+AB[n//2][0]
    AB.sort(key=lambda x: x[1])
    median_max=AB[n//2-1][1]+AB[n//2][1]
    
    return max(0,median_max-median_min+1)

def main():
    n=int(input())
    AB=[list(map(int,input().split())) for _ in range(n)]
    if n%2==0:
        ans=solve_even(n,AB)
    else:
        ans=solve_odd(n,AB)
    print(ans)
    
if __name__=='__main__':
    main()

Solution (Python):
import sys

readline = sys.stdin.readline
readall = sys.stdin.read
ns = lambda: readline().rstrip()
ni = lambda: int(readline().rstrip())
nm = lambda: map(int, readline().split())
nl = lambda: list(map(int, readline().split()))
prn = lambda x: print(*x, sep='\n')

n = ni()
a = list(map(int, readall().split()))
l = a[::2]
h = a[1::2]
l.sort()
h.sort()
ml = l[n//2] if n&1 else (l[n//2] + l[n//2-1])
mh = h[n//2] if n&1 else (h[n//2] + h[n//2-1])
print(mh - ml + 1)

Solution (Python):
import sys

sys.setrecursionlimit(500005)
stdin = sys.stdin

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

n = ni()
a = []
b = []
for i in range(n):
    u, v = na()
    a.append(u)
    b.append(v)

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