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):
def main(N, lines):
    a = sorted(map(lambda line: line[0], lines))
    b = sorted(map(lambda line: line[1], lines))

    if N % 2 == 1:
        mi = a[N // 2]
        ma = b[N // 2]
        print(int(ma - mi + 1))
    else:
        mi = (a[N // 2 - 1] + a[N // 2])
        ma = (b[N // 2 - 1] + b[N // 2])
        print(int(ma - mi + 1))


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

Solution (Python):
n = int(input())
a = [0] * n
b = [0] * n
for i in range(n):
    a[i], b[i] = [int(j) for j in input().split()]
a.sort()
b.sort()
if n % 2 == 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):
N = int(input())
A = [0 for _ in range(N)]
B = [0 for _ in range(N)]
import statistics
for k in range(N):
  A[k], B[k] = map(int, input().split())

if N%2 == 1:
  print(statistics.median(B) - statistics.median(A) +1)
else:
  print(int((statistics.median(B) - statistics.median(A))*2 +1))

Solution (Python):
import statistics

N = int(input())
AB = [map(int, input().split()) for _ in range(N)]
A, B = [list(i) for i in zip(*AB)]


A_median = statistics.median(A)
B_median = statistics.median(B)
if N%2==0:
    print(int((B_median-A_median)*2)+1)
else:
    print(B_median-A_median+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 = sorted(A)
B = sorted(B)
if N%2 == 1:
    ans = B[int((N-1)/2)] - A[int((N-1)/2)] + 1
elif N%2 == 0:
    ans = B[int(N/2)] + B[int(N/2-1)] - A[int(N/2)] - A[int(N/2-1)] + 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 == 1:
    ans = B[n//2]-A[n//2]+1
else:
    x = A[n//2-1]+A[n//2]
    y = B[n//2-1]+B[n//2]
    ans = y-x+1
print(ans)

Solution (Python):


import sys
input = sys.stdin.readline
sys.setrecursionlimit(10**7)
from collections import Counter, deque
from collections import defaultdict
from itertools import combinations, permutations, accumulate, groupby, product
from bisect import bisect_left,bisect_right
from heapq import heapify, heappop, heappush
from math import floor, ceil,pi,factorial
from operator import itemgetter
def I(): return int(input())
def MI(): return map(int, input().split())
def LI(): return list(map(int, input().split()))
def LI2(): return [int(input()) for i in range(n)]
def MXI(): return [[LI()]for i in range(n)]
def SI(): return input().rstrip()
def printns(x): print('\n'.join(x))
def printni(x): print('\n'.join(list(map(str,x))))
inf = 10**17
mod = 10**9 + 7

n=I()
lis1=[]
lis2=[]
for i in range(n):
    a,b=MI()
    lis1.append(a)
    lis2.append(b)
lis1.sort()
lis2.sort()
if n%2==1:
    med1=lis1[n//2]
    med2=lis2[n//2]
    print(med2-med1+1)
if n%2==0:
    med1=lis1[n//2-1]+lis1[n//2]
    med2=lis2[n//2-1]+lis2[n//2]
    print(med2-med1+1)

Solution (Python):
import sys

sys.setrecursionlimit(10 ** 8)
ini = lambda: int(sys.stdin.readline())
inm = lambda: map(int, sys.stdin.readline().split())
inl = lambda: list(inm())
ins = lambda: sys.stdin.readline().rstrip()
debug = lambda *a, **kw: print("\033[33m", *a, "\033[0m", **dict(file=sys.stderr, **kw))

N = ini()
A, B = [], []
for i in range(N):
    a, b = inm()
    A.append(a)
    B.append(b)


def solve():
    sa = sorted(A)
    sb = sorted(B)
    if N % 2 == 1:
        return sb[N // 2] - sa[N // 2] + 1
    else:
        return (sb[N // 2] + sb[N // 2 - 1]) - (sa[N // 2] + sa[N // 2 - 1]) + 1


print(solve())

Solution (Python):
def solve():
  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:
    b = A[N//2]
    u = B[N//2]
    return u-b+1
  b1 = A[N//2-1]
  b2 = A[N//2]
  u1 = B[N//2-1]
  u2 = B[N//2]
  return u1+u2-b1-b2+1
print(solve())

Solution (Python):
n=int(input(""))
a=[]
b=[]
for i in range(n):
    cc=input("").split(" ")
    a+=[int(cc[0])]
    b+=[int(cc[1])]
s=0
a.sort()
b.sort()
if (n%2==0):
    s=(a[int(n/2)]+a[int(n/2)-1]-b[int(n/2)]-b[int(n/2)-1])
else:
    s=a[int((n-1)/2)]-b[int((n-1)/2)]
print(int(-s+1))

Solution (Python):
N=int(input())
A=[0]*N
B=[0]*N
x,y=0,0
for i in range(N):
  x,y=map(int,input().split())
  A[i]=x
  B[i]=y
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 numpy as np

N = int(input())
AB = np.vstack([list(map(int, input().split())) for _ in range(N)])
meds = np.median(AB, axis=0)

if N%2 == 0:
    print(int((meds[1]-meds[0])*2+1))
else:
    print(int(meds[1]-meds[0] +1))

Solution (Python):
def med(l):
	t = len(l)
	if t%2:
		return l[t//2]
	else: return (l[t//2]+l[t//2-1])/2

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

if n%2==0:
	print(int((med(b)-med(a))*2)+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:
        print(b[n//2]-a[n//2]+1)
    else:
        bm = b[n//2]+b[n//2-1]
        am = a[n//2]+a[n//2-1]
        print(bm-am+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:
    a = A[(n+1)//2-1]
    b = B[(n+1)//2-1]
    print(int(b-a+1))
else:
    a = (A[n//2-1]+A[n//2])/2
    b = (B[n//2-1]+B[n//2])/2
    print(int((b-a)*2+1))

Solution (Python):
def main():
    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 & 1:
        j = (N - 1) // 2
        ans = B[j] - A[j] + 1
        print(ans)
        return

    j = N // 2 - 1
    k = N // 2
    ans = (B[j] + B[k]) - (A[j] + A[k]) + 1
    print(ans)
    return


if __name__ == '__main__':
    main()

Solution (Python):

import sys

input = sys.stdin.readline


def S():
    return input().rstrip()


def I():
    return int(input())


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


n = I()
ab = list(map(int, sys.stdin.read().split()))
a = ab[::2]
b = ab[1::2]
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((m2 - m1) * 2 + 1))
else:
    m1 = a[n // 2]
    m2 = b[n // 2]
    print(m2 - m1 + 1)

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

al = []
bl = []
for a,b in ab:
  al.append(a)
  bl.append(b)
al.sort()
bl.sort()

if N%2 == 0:
  ans = (bl[N//2] + bl[N//2 -1]) - (al[N//2] + al[N//2 -1]) +1
else:
  ans = bl[N//2] - al[N//2] +1
print(ans)

Solution (Python):
N = int(input())
a, b = [], []
for i in range(N):
    c, d = map(int, input().split())
    a.append(c)
    b.append(d)
a.sort()
b.sort()
if N%2 == 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):
n = int(input())
a=[]
b=[]
for i in range(n):
    h,m=list(map(int,input().split()))
    a.append(h)
    b.append(m)
a.sort()
b.sort()

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

    
    print(b[k]+b[k-1]-(a[k]+a[k-1])+1)

Solution (Python):
import sys, re
from collections import deque, defaultdict, Counter
from math import ceil, sqrt, hypot, factorial, pi, sin, cos, tan, asin, acos, atan, radians, degrees, log2, gcd
from itertools import accumulate, permutations, combinations, combinations_with_replacement, product, groupby
from operator import itemgetter, mul
from copy import deepcopy
from string import ascii_lowercase, ascii_uppercase, digits
from bisect import bisect, bisect_left, insort, insort_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
from decimal import *




N = INT()
AB = [LIST() for _ in range(N)]

A, B = zip(*AB)
A = list(A)
B = list(B)

A.sort()
B.sort()

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

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

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

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

Solution (Python):

import sys
import math
import os
import itertools
import string
import heapq
import _collections
from collections import Counter
from collections import defaultdict
from collections import deque
from functools import lru_cache
import bisect
import re
import queue
import decimal


class Scanner():
    @staticmethod
    def int():
        return int(sys.stdin.readline().rstrip())

    @staticmethod
    def string():
        return sys.stdin.readline().rstrip()

    @staticmethod
    def map_int():
        return [int(x) for x in Scanner.string().split()]

    @staticmethod
    def string_list(n):
        return [Scanner.string() for i in range(n)]

    @staticmethod
    def int_list_list(n):
        return [Scanner.map_int() for i in range(n)]

    @staticmethod
    def int_cols_list(n):
        return [Scanner.int() for i in range(n)]


MOD = int(1e09) + 7
INF = int(1e15)


def solve():
    N = Scanner.int()
    A = [0 for _ in range(N)]
    B = [0 for _ in range(N)]
    for i in range(N):
        A[i], B[i] = Scanner.map_int()
    A.sort()
    B.sort()
    if N % 2 == 0:
        mA = A[N // 2] + A[N // 2 - 1]
        mB = B[N // 2] + B[N // 2 - 1]
        print(mB - mA + 1)
    else:
        mA = A[N // 2]
        mB = B[N // 2]
        print(mB - mA + 1)


def main():
    
    
    
    
    
    
    solve()


if __name__ == "__main__":
    main()

Solution (Python):



import numpy

def main():
  n = int(input())
  la, lb = [], []
  for _ in range(n):
    a, b = map(int, input().split())
    la.append(a)
    lb.append(b)
  la.sort(), lb.sort()
  
  if n % 2 == 0:
    s = (n-1)//2
    e = s + 2
    ma = sum(la[s:e]) / 2.0
    mb = sum(lb[s:e]) / 2.0
    print(int(2 * (mb - ma) + 1))
  if n % 2 == 1:
    ma = la[n//2]
    mb = lb[n//2]
    print(mb - ma + 1)
    
if __name__=='__main__':
  main()

Solution (Python):
N = int(input())
A = list()
B = list()
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):
  x = A[(N-1)//2]
  y = B[(N-1)//2]
  print(y-x+1)
else:
  x = A[(N//2)-1] + A[N//2]
  y = B[(N//2)-1] + B[N//2]
  print(y-x+1)

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


if __name__ == '__main__':
    main()

Solution (Python):
import math
n = int(input())
a = [0]*n
b = [0]*n
for i in range(n):
  a[i], b[i] = list(map(int, input().split()))
a.sort()
b.sort()
ans = 0
h = int(n/2)
if n % 2 == 0:
  a_harf = a[h-1] + a[h]
  b_harf = b[h-1] + b[h]
  ans = b_harf - a_harf + 1
else:
  ans = b[h] - a[h] + 1
  
print(ans)

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

def med(s: list):
    n = len(s)
    s = sorted(s, reverse = True)
    return s[(n + 1) // 2 - 1] if n & 1 else (s[n // 2] + s[n // 2 - 1]) / 2

n = int(input())
a, b = [], []
for i in range(n):
    aa, bb = map(int, input().split())
    a.append(aa), b.append(bb)
ma, mb = med(a), med(b)
print(int((mb - ma) + 1) if n & 1 else int((mb - ma) * 2 + 1))

Solution (Python):
def main():
    n = int(input())
    a = [None]*n
    b = [None]*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-1]+b[n//2]-a[n//2]+1-a[n//2-1])
            
if __name__ == "__main__":
    main()

Solution (Python):
def main():
    n = int(input())
    al = []
    bl = []
    for _ in range(n):
        a, b = map(int, input().split())
        al.append(a)
        bl.append(b)
    al.sort()
    bl.sort()
    if n%2:
        print(bl[n//2]-al[n//2]+1)
    else:
        print(bl[n//2]+bl[n//2-1]-al[n//2]-al[n//2-1]+1)
 
if __name__ == "__main__":
    main()

Solution (Python):
def main():
    n = int(input())
    a = [None]*n
    b = [None]*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-1]+b[n//2]-a[n//2-1]-a[n//2]+1)
        

if __name__ == "__main__":
    main()

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




if N % 2 == 1:
    minA = sorted([row[0] for row in A])
    maxA = sorted([row[1] for row in A])
    medA = minA[int(N/2)]
    medB = maxA[int(N/2)]
    print(medB-medA+1)
else:
    minA = sorted([row[0] for row in A])
    maxA = sorted([row[1] for row in A])
    medA = (minA[int(N/2-1)]+minA[int(N/2)])/2
    medB = (maxA[int(N/2-1)]+maxA[int(N/2)])/2
    print(int((medB-medA)*2+1))

Solution (Python):


N = int(input().strip())
AB_list = [list(map(int, input().rstrip().split())) for i in range(N)]


A_list,B_list = list(map(list, zip(*AB_list)))

A_list.sort()
B_list.sort()


if N%2 == 0:
    Med_A = A_list[ (N-1)//2 ] + A_list[ (N-1)//2 + 1 ]
    Med_B = B_list[ (N-1)//2 ] + B_list[ (N-1)//2 + 1 ]
    
else:
    Med_A = A_list[ (N-1)//2 ]
    Med_B = B_list[ (N-1)//2 ]


Med_range = Med_B - Med_A + 1
print(Med_range)

Solution (Python):
import statistics

N = int(input())
A = []
B = []
for i in range(N):
    a, b = list(map(int, input().split()))
    A.append(a)
    B.append(b)
Am = statistics.median(A)
Bm = statistics.median(B)

if N % 2 == 0:
    print(round(2 * (Bm - Am) + 1))
else:
    print(Bm - Am + 1)

Solution (Python):
n=int(input())
a,b=[],[]
for i in range(n):
  inp=list(map(int,input().split()))
  a.append(inp[0])
  b.append(inp[1])
a.sort()
b.sort()
am=sum(a[(n-1)//2:n//2+1])
bm=sum(b[(n-1)//2:n//2+1])
print(bm-am+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:
  ma = A[N//2]
  mb = B[N//2]
  print(max(0, mb-ma+1))
else:
  ma = A[N//2] + A[N//2-1]
  mb = B[N//2] + B[N//2-1]
  print(max(0, mb-ma+1))

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

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

Solution (Python):
import statistics
import math

N = int(input())

min_x = []
max_x = []

for i in range(N):
    A, B = map(int, input().split())
    min_x.append(A)
    max_x.append(B)

min_x.sort()
max_x.sort()

result = []

if len(min_x) % 2 == 0:
    min_median = (min_x[len(min_x)//2-1] + min_x[len(min_x)//2])
    max_median = (max_x[len(min_x)//2-1] + max_x[len(min_x)//2])
    print(len(range(math.floor(min_median), math.ceil(max_median) + 1)))

else:
    min_median = min_x[len(min_x)//2]
    max_median = max_x[len(min_x)//2]
    print(max_median - min_median + 1)

Solution (Python):



def solve(N, AB):
    def getMedian(A):
        if N % 2 == 0:
            m1 = A[N // 2 - 1]
            m2 = A[N // 2]
            m = (m1 + m2) / 2
        else:
            m = A[N // 2]
        return m

    A = sorted(a for a, b in AB)
    B = sorted(b for a, b in AB)
    if N % 2 == 0:
        return int(2 * (getMedian(B) - getMedian(A))) + 1
    else:
        return getMedian(B) - getMedian(A) + 1


(N,) = [int(x) for x in input().split()]
AB = [[int(x) for x in input().split()] for i in range(N)]
print(solve(N, AB))

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:
  ma = A[N//2]
  mb = B[N//2]
  print(max(0, mb-ma+1))
else:
  ma = A[N//2] + A[N//2-1]
  mb = B[N//2] + B[N//2-1]
  print(max(0, mb-ma+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 & 1:
        print(b[n//2]-a[n//2]+1)
    else:
        print(b[n//2-1]+b[n//2]-a[n//2-1]-a[n//2]+1)

if __name__ == "__main__":
    main()

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:
    ac = aa[n // 2]
    bc = bb[n // 2]
    print(abs(ac - bc) + 1)

else:
    ac1 = aa[n // 2 - 1]
    bc1 = bb[n // 2 - 1]
    ac2 = aa[n // 2]
    bc2 = bb[n // 2]
    print((bc2 + bc1) - (ac2 + ac1) + 1)

Solution (Python):
from statistics import median

N = int(input())
A = [0] * N
B = [0] * N
max=0
min =0
for c in range(N):
    A[c], B[c] = map(int, input().split())

med_A = median(A)
med_B = median(B)

if N%2==0:
    print(int((med_B-med_A)*2+1))
else:
    print(med_B-med_A+1)

Solution (Python):
from statistics import median

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

A_med = median(A)
B_med = median(B)

if N % 2 == 0:
    print(round(2 * (B_med - A_med) + 1))
else:
    print(B_med - A_med + 1)

Solution (Python):
import statistics
from collections import Counter
N = int(input())
A = [list(map(int, input().split(" "))) for i in range(N)]
xMIN = []
xMAX = []



for i in range(N):
    xMIN.append(A[i][0])

for j in range(N):
    xMAX.append(A[j][1])


if N % 2 != 0:
    medianMIN = statistics.median(xMIN)
    medianMAX = statistics.median(xMAX)
    print(int(medianMAX-medianMIN+1))
else:
    medianMIN_LOW = statistics.median_low(xMIN)
    medianMIN_HIGH = statistics.median_high(xMIN)
    medianMAX_LOW = statistics.median_low(xMAX)
    medianMAX_HIGH = statistics.median_high(xMAX)
    print((medianMAX_LOW+medianMAX_HIGH)-(medianMIN_LOW+medianMIN_HIGH)+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:
    l = A[n // 2]
    r = B[n // 2]
    ans = r - l + 1
    print(ans)
else:
    l = A[n // 2 - 1] + A[n // 2]
    r = B[n // 2 - 1] + B[n // 2]
    ans = r - l + 1
    print(ans)

Solution (Python):
from statistics import median
 
X = []
X1 = []
N=int(input())
for i in range(N):
    a, b = map(int, input().split())
    X.append(a)
    X1.append(b)
 
m1 = median(X)
m2 = median(X1)
if len(X) % 2:
    print(int((m2 - m1) + 1))
else:
    print(int(2 * (m2 - m1) + 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:
    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):
N = int(input())
t = N // 2
a_list = []
b_list = []
for i in range(N):
    ab = list(map(int, input().split()))
    a_list.append(ab[0])
    b_list.append(ab[1])

a_list = sorted(a_list)
b_list = sorted(b_list)

if N%2 == 1:
    a_median = a_list[t]
    b_median = b_list[t]
    print(b_median-a_median+1)
elif N%2 == 0:
    a_median = (a_list[t-1]+a_list[t])/2
    b_median = (b_list[t-1]+b_list[t])/2
    print(int(2*(b_median-a_median)+1))

Solution (Python):
n = int(input())
al = []
bl = []
for _ in range(n):
    a, b = map(int, input().split()) 
    al.append(a)
    bl.append(b)

al.sort()
bl.sort()


if n%2 == 1:
    print(bl[n//2] - al[n//2] + 1)
else:
    print(bl[n//2-1]-al[n//2]+bl[n//2]-al[n//2-1]+1)

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

n = int(input())
a= [0]*n
b= [0]*n

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

if n%2 ==1:
    a.sort()
    b.sort()
    xmin= a[int((n-1)/2)]
    xmax= b[int((n - 1) / 2)]

    print(int(xmax-xmin+1))

if n%2 ==0:
    a.sort()
    b.sort()
    xmin = a[int(n/2-1)]+a[int(n/2)]
    xmax = b[int(n / 2 - 1)] + b[int(n / 2)]
    print(int((xmax-xmin)+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())

if n%2 ==1:
    a.sort()
    b.sort()
    xmin= a[int((n-1)/2)]
    xmax= b[int((n - 1) / 2)]

    print(int(xmax-xmin+1))

if n%2 ==0:
    a.sort()
    b.sort()
    xmin = a[int(n/2-1)]+a[int(n/2)]
    xmax = b[int(n / 2 - 1)] + b[int(n / 2)]
    print(int((xmax-xmin)+1))

Solution (Python):
N = int(input())
t = N//2
la, lb = [], []
for _ in range(N):
    A, B = map(int, input().split())
    la.append(A)
    lb.append(B)
la.sort()
lb.sort()
print(lb[t]-la[t]+1 if N%2 else lb[t-1]-la[t]+lb[t]-la[t-1]+1)

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

t = N//2
tl = sorted(l)
tr = sorted(l, key=lambda x:-x[1])

if N%2:
    print(tr[t][1]-tl[t][0]+1)
else:
    a1, a2 = tl[t-1][0], tr[t][1]
    a3, a4 = tl[t][0], tr[t-1][1]
    print(a4-a3+a2-a1+1)

Solution (Python):
from statistics import*
(n,),*t=[map(int,t.split())for t in open(0)]
a,b=map(median,zip(*t))
print(int((b-a)*(2-n%2))+1)

Solution (Python):
from numpy import*
a,b=median(t:=loadtxt(open(0),skiprows=1),0)
print(int((a-b)*~(~len(t)%2))+1)

Solution (Python):
from numpy import*
t=loadtxt(open(0),skiprows=1)
a,b=median(t,0)
print(int((b-a)*(2-len(t)%2))+1)

Solution (Python):
from numpy import*
(n,),*d=[int_(i.split())for i in open(0)]
a,b=median(d,0)
print(int((b-a)*(2-n%2))+1)

Solution (Python):
from statistics import*
(n,),*t=[map(int,t.split())for t in open(0)]
a,b=map(median,zip(*t))
print(int((b-a)*(2-n%2))+1)

Solution (Python):
n = int(input())
arr_a = []
arr_b = []
for i in range(n):
    a, b = map(int, input().split())
    arr_a.append(a)
    arr_b.append(b)
arr_a.sort()
arr_b.sort()
if n % 2 == 1:
    print(arr_b[n//2] - arr_a[n//2] + 1)
else:
    median_a = (arr_a[int(n/2 -1)] + arr_a[int(n/2)])
    median_b = (arr_b[int(n/2 -1)] + arr_b[int(n/2)])
    print(median_b - median_a + 1)

Solution (Python):


import copy
import random
import bisect 
import fractions 
import math
import sys
import collections

mod = 10**9+7
sys.setrecursionlimit(mod) 

d = collections.deque()
def LI(): return list(map(int, sys.stdin.readline().split()))

N = int(input())
A = [0 for i in range(N)]
B = [0 for i in range(N)]
for i in range(N):
    a,b = LI()
    A[i] = a
    B[i] = b

A.sort()
B.sort()

if N % 2 == 1:
    min_mid = A[(N - 1) // 2]
else:
    min_mid = (A[N //2 - 1] + A[N//2]) / 2

if N % 2 == 1:
    max_mid = B[(N - 1) // 2]
else:
    max_mid = (B[N //2 - 1] + B[N//2]) / 2 

if N % 2 == 0:
    print(int((max_mid - min_mid) / 0.5 + 1))
else:
    print(math.ceil(max_mid) - math.floor(min_mid) + 1)

Solution (Python):
def solve(n, a, b):
    l = (n+1)//2 - 1
    r = l + 1 + (n%2==0)
    lb = sum(sorted(a)[l:r])
    ub = sum(sorted(b)[l:r])
    return (ub - lb) + 1

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

Solution (Python):
n = int(input())
A = []
B = []
for i in range(n):
    x = [int(i) for i in input().split()]
    A.append(x[0])
    B.append(x[1])
A = sorted(A)
B = sorted(B)
if n % 2:
    med_A = A[n//2]
    med_B = B[n//2]
    print(abs(med_A - med_B) + 1)
else:
    med_A  = A[(n-1)//2]+A[n//2] 
    med_B = B[(n-1)//2]+B[n//2]
    print(abs(med_A - med_B) + 1)

Solution (Python):
n=int(input())
l=[list(map(int,input().split())) for i in range(n)]
work1=sorted([x[0] for x in l])
work2=sorted([x[1] for x in l])
if n%2==1 : 
    mmin=work1[n//2]
    mmax=work2[n//2]
else:
    mmin=work1[n//2]+work1[n//2-1]
    mmax=work2[n//2]+work2[n//2-1]
print(mmax-mmin+1)

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):
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:
    lower=(a[n//2]+a[n//2-1])/2
    upper=(b[n//2]+b[n//2-1])/2
    print(int(upper*2-(lower*2-1)))

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

a=[]
b=[]

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

import statistics as st

am = st.median(a)
bm = st.median(b)

if n % 2 == 1:
   print(int(bm-am+1))
else:
   print(int((bm-am)*2+1))

Solution (Python):
N = int(input())
AB = [[int(i) for i in input().split()] for _ in range(N)]

A, B = map(list, zip(*AB))
A.sort()
B.sort()

if N % 2 == 0 :
  print(B[N//2] + B[N//2-1] - A[N//2] - A[N//2-1] + 1)
else :
  print(B[N//2] - A[N//2] + 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:
    under = a[n // 2]
    upper = b[n // 2]
    print(upper - under + 1)
else:
    under = a[n // 2 - 1] + a[n // 2]
    upper = b[n // 2 - 1] + b[n // 2]
    print((upper - under) + 1)
"""

aa, ba, aidx = zip(*sorted(zip(a, b, range(n))))  
bb, ab, bidx = zip(*sorted(zip(b, a, range(n))))  

if n % 2:
    print(bb[n // 2] - aa[n // 2] + 1)
else:
    if aidx[n // 2 - 1] == bidx[n // 2]:
        ans = (bb[n // 2 - 1] - aa[n // 2 - 1] + 1) * (bb[n // 2] - aa[n // 2] + 1)
    else:
        ans = (bb[n // 2 - 1] - aa[n // 2 - 1] + 1) * (bb[n // 2 - 1] - aa[n // 2] + 1)
    print(ans)"""

Solution (Python):
N = int(input())
A = []
B = []
for _ in range(N):
  a,b = [int(i) for i in input().split()]
  A.append(a)
  B.append(b)
A.sort()
B.sort()
if N%2 == 1:
  M = (N-1)//2
  print(B[M]-A[M]+1)
  exit()
M = (N//2)-1
L = (N//2)
print(B[M]+B[L]-A[M]-A[L]+1)

Solution (Python):
n, *AB = map(int, open(0).read().split())
a = sorted(AB[::2])
b = sorted(AB[1::2])
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 - 1] - a[(n + 1) // 2 - 1] + 1)

Solution (Python):
n, *AB = map(int, open(0).read().split())
a = sorted(AB[::2])
b = sorted(AB[1::2])
is_odds = n % 2 == 0
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 - 1] - a[(n + 1) // 2 - 1] + 1)

Solution (Python):
n = int(input())
a = []
b = []
for i in range(n):
	a_1, b_1 = input().split()
	a.append(int(a_1))
	b.append(int(b_1))
a.sort()
b.sort()
is_odds = n % 2 == 0
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 - 1] - a[(n + 1) // 2 - 1] + 1)

Solution (Python):
n = int(input())
a = []
b = []
for i in range(n):
	a_1, b_1 = input().split()
	a.append(int(a_1))
	b.append(int(b_1))
a.sort()
b.sort()
is_odds = n % 2 == 0
a_med = a[(n + 1) // 2 - 1] if not is_odds else a[n // 2 - 1] + a[n // 2]
b_med = b[(n + 1) // 2 - 1] if not is_odds else b[n // 2 - 1] + b[n // 2]
print(b_med - a_med + 1)

Solution (Python):
n = int(input())
a = []
b = []
for i in range(n):
	a_1, b_1 = input().split()
	a.append(int(a_1))
	b.append(int(b_1))
a.sort()
b.sort()
is_odds = n % 2 == 0
a_med = a[(n + 1) // 2 - 1] if not is_odds else (a[n // 2 - 1] + a[n // 2]) / 2
b_med = b[(n + 1) // 2 - 1] if not is_odds else (b[n // 2 - 1] + b[n // 2]) / 2
from_a = a_med if not is_odds else int(a_med * 2)
to_b = b_med if not is_odds else int(b_med * 2)
print(to_b - from_a + 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()

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

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





def RD(): return sys.stdin.read()
def II(): return int(input())
def MI(): return map(int,input().split())
def MF(): return map(float,input().split())
def LI(): return list(map(int,input().split()))
def LF(): return list(map(float,input().split()))
def TI(): return tuple(map(int,input().split()))



def main():
	n=II()
	A=[]
	B=[]
	for _ in range(n):
		a,b=MI()
		A.append(a)
		B.append(b)
	A.sort()
	B.sort()
	

	r=n//2
	l=(n-1)//2
	

	mi=A[l]+A[r]
	ma=B[l]+B[r]

	ans=(ma-mi)-(ma-mi)*(n%2)//2+1
	print(ans)







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)
A.sort()
B.sort()
    
if(N%2 != 0):    
    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):

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

a.sort()
b.sort()

if n%2==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)