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
import pprint

sys.setrecursionlimit(10 ** 6)

class Logger:
	def __init__(self, debug):
		self.debug = debug
	def print(self, *args):
		if self.debug:
			pprint.pprint(args)


def main():
	log = Logger(0)
	n = int(sys.stdin.readline())
	a = []
	b = []
	for i in range(n):
		ai, bi = map(int, sys.stdin.readline().split())
		a.append(ai)
		b.append(bi)
	a_sort = sorted(a)
	if n % 2 == 0:
		min_center = (a_sort[int(n/2)-1] + a_sort[int(n/2)])/2
	else:
		min_center = a_sort[int((n+1)/2)-1]
	b_sort = sorted(b)
	if n % 2 == 0:
		max_center = (b_sort[int(n/2)-1] + b_sort[int(n/2)])/2
	else:
		max_center = b_sort[int((n+1)/2)-1]
	log.print(max_center, min_center)
	if n % 2 == 0:
		print(int((max_center - min_center)*2 + 1))
	else:
		print(int(max_center - min_center + 1))


	
	


main()

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

A = [0 for i in range(N)]
B = [0 for i in range(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:
    print(B[N//2]-A[N//2]+1)
else:
    print(B[N//2]+B[(N-1)//2]-A[N//2]-A[(N-1)//2]+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(reverse=True)

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

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:
    mid_min=(A[N//2-1]+A[N//2])
    mid_max=(B[N//2-1]+B[N//2])
else:
    mid_min=A[N//2]
    mid_max=B[N//2]

print(mid_max-mid_min+1)

Solution (Python):
n = int(input())
listA = []
listB = []
for i in range(n):
    a, b = map(int, input().split())
    listA.append(a)
    listB.append(b)
listA.sort()
listB.sort()

if n%2 == 0:
    ta = (listA[n//2]+listA[n//2-1])
    tb = (listB[n//2]+listB[n//2-1])
else:
    ta = listA[n//2]
    tb = listB[n//2]

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

Solution (Python):
import sys

sys.setrecursionlimit(10 ** 6)
int1 = lambda x: int(x) - 1
p2D = lambda x: print(*x, sep="\n")
def II(): return int(sys.stdin.readline())
def MI(): return map(int, sys.stdin.readline().split())
def LI(): return list(map(int, sys.stdin.readline().split()))
def LLI(rows_number): return [LI() for _ in range(rows_number)]
def SI(): return sys.stdin.readline()[:-1]

def main():
    n=II()
    ab=LLI(n)
    mxs=[]
    mns=[]
    for a,b in ab:
        if a<b:mns.append(a);mxs.append(b)
        else:mns.append(b);mxs.append(a)
    mns.sort()
    mxs.sort()
    
    

    if n%2:
        ans=mxs[n//2]-mns[n//2]+1
    else:
        l=mns[n//2]+mns[n//2-1]
        r=mxs[n//2]+mxs[n//2-1]
        ans=r-l+1

    print(ans)

main()

Solution (Python):
import sys
import numpy as np
import math
import random
from decimal import Decimal
import itertools
import re
from collections import deque, Counter
from functools import lru_cache

sys.setrecursionlimit(2147483647)
INF = 10**13
def LI(): return list(map(int, sys.stdin.buffer.readline().split()))
def I(): return int(sys.stdin.buffer.readline())
def LS(): return sys.stdin.buffer.readline().rstrip().decode('utf-8').split()
def S(): return sys.stdin.buffer.readline().rstrip().decode('utf-8')
def IR(n): return [I() for i in range(n)]
def LIR(n): return [LI() for i in range(n)]
def SR(n): return [S() for i in range(n)]
def LSR(n): return [LS() for i in range(n)]
def SRL(n): return [list(S()) for i in range(n)]
def MSRL(n): return [[int(j) for j in list(S())] for i in range(n)]
mod = 1000000007

def factorization(n):
    arr = []
    temp = n
    for i in range(2, int(-(-n**0.5//1))+1):
        if temp%i==0:
            cnt=0
            while temp%i==0:
                cnt+=1
                temp //= i
            arr.append([i, cnt])

    if temp!=1:
        arr.append([temp, 1])

    if arr==[]:
        arr.append([n, 1])

    return arr


def main():
	n = I()
	A = np.zeros(n)
	B = np.zeros(n)
	for i in range(n):
			A[i], B[i] = LI()
	if n % 2 == 0:
		print(int((np.median(B)-np.median(A))*2+1))
	else:
		print(int(np.median(B)-np.median(A)+1))



if __name__ == '__main__':
    main()

Solution (Python):
import sys
input = lambda: sys.stdin.readline().rstrip()
sys.setrecursionlimit(20000000)
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:
    ans = 0
    i = n//2-1
    j = n//2
    tmp = [[a[i], b[i]], [a[j], b[j]]]
    ans = (b[i] + b[j]) - (a[i] + a[j]) + 1
    print(ans)
else:
    mid_l = a[n//2]
    mid_r = b[n//2]
    print(mid_r - mid_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:
    mid_ind = N//2
    lower = A[mid_ind]
    upper = B[mid_ind]
    print(upper-lower+1)

else:
    mid_a = N//2
    mid_b = mid_a-1
    lower = (A[mid_a]+A[mid_b])/2
    upper = (B[mid_a]+B[mid_b])/2
    print(int((upper-lower)*2+1))

Solution (Python):
N=int(input())
A=[list(map(int, input().split())) for _ in range(N)]
L,R=zip(*A)
L=sorted(L)
R=sorted(R)[::-1]
if N%2==1:
  
  print(R[N//2]-L[N//2]+1)
else:
  r1,r2=R[N//2-1],R[N//2]
  l1,l2=L[N//2-1],L[N//2]
  
  print((r1+r2)-(l1+l2)+1)

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

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

A = sorted(A)
B = sorted(B)

m = int((N + 1) / 2 if N % 2 == 1 else N / 2)

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

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

A=[]
B=[]

for i in range(n):
    ai,bi=map(int,input().split())
    A.append(ai)
    B.append(bi)

A.sort()
B.sort()

amid=0
bmid=0
if n%2==0:
    amid=(A[round(n/2-1)]+A[round(n/2)])/2
    bmid=(B[round(n/2-1)]+B[round(n/2)])/2
else:
    amid=A[round((n-1)/2)]
    bmid=B[round((n-1)/2)]

d=bmid-amid

if n%2==0:
    print(round(2*d)+1)
else:
    print(d+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())
import statistics
X = statistics.median(a)
Y = statistics.median(b)
if N%2==1:
    print(Y-X+1)
else:
    print(int((2*(Y-X)+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==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):
    a,b=map(int, input().split())
    A.append(a)
    B.append(b)

if n%2==1:
    sortA=sorted(A)
    mA=sortA[(n-1)//2]
    sortB=sorted(B)
    mB=sortB[(n-1)//2]
    
    print(abs(mB-mA)+1)
else:
    sortA=sorted(A)
    mA1=sortA[(n-1)//2]
    mA2=sortA[n//2]
    mA=mA1+mA2
    sortB=sorted(B)
    mB1=sortB[(n-1)//2]
    mB2=sortB[n//2]
    mB=mB1+mB2
    
    print(abs(mB-mA)+1)

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


def odd():
    left = a[n//2]
    right = b[-(1 + n//2)]
    return right - left + 1


def even():
    left_x = a[(n//2) - 1]
    right_x = b[-(n//2 + 1)]
    left_y = a[n//2]
    right_y = b[-n//2]
    x_range = right_x - left_x + 1
    y_range = right_y - left_y + 1
    return x_range + y_range - 1


def solve():
    if n % 2 == 1:
        return odd()
    return even()

print(solve())

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

As.sort()
Bs.sort()

if N % 2 == 1:
  i = (N+1) // 2
  print(Bs[i-1] - As[i-1] + 1)
else:
  lower = N // 2
  upper = lower + 1
  
  lower_sum = As[lower-1] + As[upper-1]
  upper_sum = Bs[lower-1] + Bs[upper-1]
  
  print(upper_sum - lower_sum + 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 % 2 == 1:
        print(B[(N-1)//2] - A[(N-1)//2] + 1)
    else:
        print(B[N//2]-A[N//2] +B[N//2-1]-A[N//2-1] + 1)
    

if __name__ == "__main__":
    main()

Solution (Python):
n=int(input())
ab=[list(map(int,input().split())) for _ in range(n)]
ab.sort(key=lambda x:x[0])
a=[a for a,b in ab]
b=[b for a,b in ab]
a.sort()
b.sort()
l=0
if n%2==1:
  print(b[n//2]-a[n//2]+1)
  
else:
  am=(a[n//2]+a[n//2-1])
  bm=(b[n//2]+b[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()
ans=0
if(N%2==1):
  print(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):
def main():
    N = int(input())
    A = list()
    B = list()
    for _ in range(N):
        a, b = list(map(int, input().split(' ')))
        A.append(a)
        B.append(b)
    A.sort()
    B.sort()
    if N % 2 == 1:
        print(B[(N - 1)//2] - A[(N - 1)//2] + 1)
    else:
        mid_a_2 = A[N // 2] + A[(N // 2) - 1]
        mid_b_2 = B[N // 2] + B[(N // 2) - 1]
        print(mid_b_2 - mid_a_2 + 1)


if __name__ == '__main__':
    main()

Solution (Python):
import sys
input=sys.stdin.readline
sys.setrecursionlimit(10 ** 8)
from itertools import accumulate
from itertools import permutations
from itertools import combinations
from collections import defaultdict
from collections import Counter
import fractions
import math
from collections import deque
from bisect import bisect_left
from bisect import insort_left
import itertools
from heapq import heapify
from heapq import heappop
from heapq import heappush
import heapq
from copy import deepcopy
alf = list("abcdefghijklmnopqrstuvwxyz")
ALF = list("ABCDEFGHIJKLMNOPQRSTUVWXYZ")

INF = float("inf")











N = int(input())
A = []
B = []
for i in range(N):
    a,b = map(int,input().split())
    A.append(a)
    B.append(b)
AA = sorted(A)
BB = sorted(B)
if N % 2 == 1:
    MIN = AA[N//2]
    MAX = BB[N//2]
    print(MAX-MIN+1)
else:
    MIN1 = AA[N//2 -1]
    MIN2 = AA[N//2]
    MAX1 = BB[N//2-1]
    MAX2 = BB[N//2]
    MIN = MIN1+MIN2
    MAX = MAX1+MAX2
    print(MAX-MIN+1)

Solution (Python):
import sys

def IS(): return sys.stdin.readline().rstrip()
def II(): return int(IS())
def MII(): return list(map(int, IS().split()))
def MIIZ(): return list(map(lambda x: x-1, MII()))

def main():
    n = II()
    
    
    aa = []
    bb = []
    for _ in range(n):
        a, b = MII()
        aa.append(a)
        bb.append(b)
    aa.sort()
    bb.sort()
    if n%2==1:
        l1, r1 = aa[n//2], bb[n//2]
        print(r1-l1+1)
    else:
        l1, l2 = aa[n//2-1], aa[n//2]
        r1, r2 = bb[n//2-1], bb[n//2]
        print((r1+r2)-(l1+l2)+1)
    
        
        
    
        
        
        

if __name__ == '__main__':
    main()

Solution (Python):
n = int(input())
AB = [tuple(map(int, input().split())) for i in range(n)]
X = sorted(AB, key=lambda x: x[0])
Y = sorted(AB, key=lambda x: x[1])
if n % 2 == 0:
    print((Y[n // 2 - 1][1] + Y[n // 2][1]) -
          (X[n // 2 - 1][0] + X[n // 2][0]) + 1)
else:
    print(Y[n // 2][1] - X[n // 2][0] + 1)

Solution (Python):
n = int(input())
minis = []
maxis = []
for i in range(n):
    a,b = map(int, input().split())
    minis.append(a)
    maxis.append(b)

minis.sort()
maxis.sort()

if(n%2 == 0):
    bottom = (minis[n//2-1] + minis[n//2])
    top = (maxis[n//2-1] + maxis[n//2])
    if(top >= bottom):
        print(top - bottom + 1)
    else:
        print('0')
if(n%2 == 1):
    bottom = minis[(n-1)//2]
    top = maxis[(n-1)//2]
    if(top >= bottom):
        print(top - bottom + 1)
    else:
        print('0')

Solution (Python):
import bisect
import collections
import copy
import functools
import heapq
import math
import sys
from collections import deque
from collections import defaultdict
input = sys.stdin.readline
MOD = 10**9+7

N = int(input())

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

if N%2 == 1:
    a.sort()
    l = a[(N-1)//2][0]
    
    a.sort(key=lambda x:x[1])
    r = a[(N-1)//2][1]
    print(r-l+1)
else:
    a.sort()
    l1 = a[N//2-1][0]
    r1 = a[N//2][0]
    
    a.sort(key=lambda x:x[1])
    l2 = a[N//2-1][1]
    r2 = a[N//2][1]
    c = l1 + r1
    d = l2 + r2
    
    print(d-c+1)

Solution (Python):
def main():
    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()
    mi = 0
    ma = 0
    if N % 2 ==0:
        mi = (A[(N-1)//2]+A[((N-1)//2)+1])/2
        ma = (B[(N-1)//2]+B[((N-1)//2)+1])/2
        print(int(((ma-mi)*2)+1))

    else :
        mi = A[N//2]
        ma = B[N//2]
        print(int(ma-mi+1))


if __name__ == '__main__':
    main()

Solution (Python):
n=int(input())
m,M=[],[]
for i in range(n):
  a,b=map(int,input().split())
  m+=[a]
  M+=[b]
m.sort()
M.sort()
d=n//2
if n%2:
  print(M[d]-m[d]+1)
else:
  print(M[d-1]+M[d]-m[d-1]-m[d]+1)

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

if n % 2 != 0:
    left = la[n//2]
    right = lb[n//2]
    print(right-left+1)
else:
    left = (la[n//2]+la[n//2-1])/2
    right = (lb[n//2]+lb[n//2-1])/2
    print(int((right-left)*2)+1)

Solution (Python):
n = int(input())
li_a = []
li_b = []
for _ in range(n):
    a, b = map(int, input().split())
    li_a.append(a)
    li_b.append(b)
li_a.sort()
li_b.sort()
if n%2 == 1:
    min_c = li_a[(n-1)//2]
    max_c = li_b[(n-1)//2]
    print(max_c-min_c+1)
else:
    min_c = (li_a[(n//2)-1] + li_a[(n//2)])/2
    max_c = (li_b[(n//2)-1] + li_b[(n//2)])/2
    print(int((max_c-min_c)*2+1))

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)
A = np.array(A)
B = np.array(B)
p = np.median(A)
q = np.median(B)
if N % 2 == 0:
    p = int(p * 2)
    q = int(q * 2)
else:
    p = int(p)
    q = int(q)

ans = q - p + 1
print(ans)

Solution (Python):
n=int(input())
A=[list(map(int,input().split())) for i in range(n)]
B=[[A[i][1],A[i][0]] for i in range(n)]
A.sort()
B.sort(reverse=True)
if n%2==1:
  print(B[(n-1)//2][0]-A[(n-1)//2][0]+1)
else:
  print((B[n//2][0]+B[n//2-1][0])-(A[n//2][0]+A[n//2-1][0])+1)

Solution (Python):
import sys
readline = sys.stdin.buffer.readline
def even(n): return 1 if n%2==0 else 0

n = int(readline())
A = []
B = []
for i in range(n):
    a,b = map(int,readline().split())
    A.append(a)
    B.append(b)
A.sort()
B.sort()

if not even(n):
    lower = A[n//2]
    upper = B[n//2]
    print(upper-lower+1)
else:
    l1 = A[n//2-1]
    l2 = A[n//2]
    u2 = B[n//2]
    u1 = B[n//2-1]

    a = u1-l1+1
    b = abs(u2-l2)+1
    print(a+b-1)

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

if n % 2 == 1:
    i = n // 2 + 1
    md = la[i - 1]
    mu = lb[i - 1]
    answer = mu - md + 1
else:
    i = n // 2
    md2 = la[i - 1] + la[i]
    mu2 = lb[i - 1] + lb[i]
    answer = (mu2 - md2) + 1

print(answer)

Solution (Python):
import statistics
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)
a_median = statistics.median(a_list)
b_median = statistics.median(b_list)
if n % 2 == 0:
  c = int((b_median - a_median)*2) + 1
else:
  c = int(b_median - a_median) + 1
print(c)

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

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

Solution (Python):


def median2(lst):
    lst.sort()
    l = len(lst)
    if l % 2:
        return lst[(l - 1)//2]
    else:
        return lst[l // 2 - 1] + lst[l // 2]
        

def submit():
    n = int(input())
    a = list()
    b = list()
    
    for _ in range(n):
        ae, be = map(int, input().split())
        a.append(ae)
        b.append(be)

    m1 = median2(a)
    m2 = median2(b)
    print(m2 - m1 + 1)


submit()

Solution (Python):
from collections import deque

n = int(input())
ranges = []

def medium(nList):
    nList.sort()
    q = deque(nList)
    while len(q) > 2:
        q.pop()
        q.popleft()
    if len(q) == 2:
        return (q[0] + q[1]) / 2
    else:
        return q[0]

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

m_min = medium(list(map(lambda r: r[0], ranges)))
m_max = medium(list(map(lambda r: r[1], ranges)))
d = m_max - m_min
if n % 2 == 0:
    print(int(d * 2) + 1)
else:
    print(d + 1)

Solution (Python):
n = int(input())
a = []
b = []
for i in range(n):
    x, y = list(map(int, input().split()))
    a.append(x)
    b.append(y)
a_s = sorted(a)
b_s = sorted(b)
if n%2==0:
    min_05 = (a_s[n//2] + a_s[n//2-1])%2
    max_05 = (b_s[n//2] + b_s[n//2-1])%2
    m_min = (a_s[n//2] + a_s[n//2-1])//2
    m_max = (b_s[n//2] + b_s[n//2-1])//2
    c = (m_max-m_min)*2+1
    if max_05:
        c += 1
    if min_05:
        c -= 1
    print(c)
else:
    m_min = a_s[n//2]
    m_max = b_s[n//2]
    print(m_max-m_min+1)

Solution (Python):

import statistics
import sys


def solve(N: int, A: "List[int]", B: "List[int]"):
    if N % 2 == 1:
        left = statistics.median(A)
        right = statistics.median(B)
        print(right - left + 1)

    else:
        left = statistics.median(A)
        right = statistics.median(B)
        print(int((right - left) * 2 + 1))
    return



def main():
    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word
    tokens = iterate_tokens()
    N = int(next(tokens))  
    A = [int()] * (N)  
    B = [int()] * (N)  
    for i in range(N):
        A[i] = int(next(tokens))
        B[i] = int(next(tokens))
    solve(N, A, B)

if __name__ == '__main__':
    main()

Solution (Python):
import statistics as st
import math
N = int(input())
A = [0]*N
B = [0]*N
for i in range(N):
  A[i] , B[i] = map(int,input().split())
mA = st.median(A)
mB = st.median(B)
if N % 2 == 0:
  ans = (mB - mA)*2 + 1
else:
  ans = mB - mA + 1
print(int(ans))

Solution (Python):
import numpy as np


def main(N, A, B):
    min = np.median(A)
    max = np.median(B)
    if N % 2 == 1:
        return int(max-min+1)
    else:
        return int((max-min)*2+1)
    print(min, max)
    return 0


N = int(input())
A = np.zeros((N), np.int32)
B = np.zeros((N), np.int32)
for i in range(N):
    A[i], B[i] = map(int, input().split())
print(main(N, A, B))

Solution (Python):
from collections import Counter
import sys

sys.setrecursionlimit(10 ** 6)

mod = 1000000007
inf = int(1e18)

dx = [0, 1, 0, -1]
dy = [1, 0, -1, 0]


def inverse(a):
    return pow(a, mod - 2, mod)


def usearch(x, a):
    lft = 0
    rgt = len(a) + 1
    while rgt - lft > 1:
        mid = (rgt + lft) // 2
        if a[mid] <= x:
            lft = mid
        else:
            rgt = mid
    return lft


def main():
    n=int(input())
    s = [tuple(map(int, input().split())) for i in range(n)]
    a = sorted(i[0] for i in s)
    b = sorted(i[1] for i in s)
    if len(s) % 2 == 1:
        lft = a[n//2]
        rgt = b[n//2]
        print(rgt - lft + 1)
        return
    lft = a[n//2] + a[n//2-1]
    rgt = b[n//2] + b[n//2-1]
    print(rgt - lft + 1)

main()

Solution (Python):
def LI():return list(map(int,input().split()))
def yes():return print("Yes")
def no():return print("No")
from collections import deque, defaultdict, Counter








































        










    



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

for _ in range(n):
    c,d=LI()
    a.append(c)
    b.append(d)
    
    
a.sort()
b.sort()


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

else:
    l=n//2
    r=l+1
    
    aa=(a[l-1]+a[r-1])
    bb=(b[l-1]+b[r-1])
    ans=bb-aa+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:
    u=(n+1)//2-1 
    print(B[u]-A[u]+1)
else:
    u=n//2-1
    w=u+1 
    print(B[u]+B[w]-A[u]-A[w]+1)

Solution (Python):
import sys

input = sys.stdin.readline


def main():
    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:
        a = A[N // 2 - 1] + A[N // 2]
        b = B[N // 2 - 1] + B[N // 2]
        ans = (b - a) + 1
    else:
        a = A[N // 2]
        b = B[N // 2]
        ans = b - a + 1

    print(ans)


if __name__ == "__main__":
    main()

Solution (Python):
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:
  import numpy as np
  a_med = int(np.median(a))
  b_med = int(np.median(b))
  print(b_med - a_med + 1)
elif n == 2:
  print(sum(b) - sum(a) + 1)
else:
  a = sorted(a)[n//2-1:n//2+1]
  b = sorted(b)[n//2-1:n//2+1]
  print(sum(b) - sum(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 == 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())
left = []
right = []

for i in range(n):
    array = list(map(int, input().split()))
    left.append(array[0])
    right.append(array[1])

left.sort()
right.sort()

if n % 2 != 0:
    print(right[n//2] - left[n//2] + 1)
else:
    num1 = (right[n//2] + right[n//2-1])/2
    num2 = (left[n//2] + left[n//2-1])/2
    print(int((num1 - num2)*2 + 1))

Solution (Python):
n = int(input())
l1 = []
l2 = []
for i in range(n):
    a, b = map(int, input().split())
    l1.append(a)
    l2.append(b)
l1.sort()
l2.sort()
if n % 2:
    t0 = l1[n // 2]
    t1 = l2[n // 2]
    print(t1 - t0 + 1)
else:
    x1 = l1[n // 2]
    x0 = l1[(n - 1) // 2]
    y1 = l2[n // 2]
    y0 = l2[(n - 1) // 2]
    if x0 > x1: x0, x1 = x1, x0
    if y0 > y1: y0, y1 = y1, y0
    print(y1 - x1 + 1 + y0 - x0)

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:
  print(B[(n-1)//2] - A[(n-1)//2] + 1)
else:
  M = B[n//2 - 1] + B[n//2]
  m = A[n//2 - 1] + A[n//2]
  ans = M-m+1
  print(ans)

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

a=[]
b=[]

for i in range(n):
    aa,bb=list(map(int,input().split()))
    a.append(aa*2)
    b.append(bb*2)

a.sort()
b.sort()

if n%2==1:
    amed=a[(n-1)//2]
    bmed=b[(n-1)//2]

    ans=(bmed-amed)//2+1
else:
    amed=(a[n//2-1]+a[n//2])/2
    bmed = (b[n // 2 - 1] + b[n // 2]) / 2

    ans=bmed-amed+1

print(int(ans))

Solution (Python):
import statistics

N = int(input())
A = []
B = []
for i in range(N):
    ab = list(map(int, input().split()))
    A.append(ab[0])
    B.append(ab[1])
if N % 2 == 0:
    o = int((statistics.median(B) - statistics.median(A)) * 2 + 1)
else:
    o = int(statistics.median(B) - statistics.median(A) + 1)
print(o)

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:
  al=A[(N-1)//2]
  ar=A[N//2]
  bl=B[(N-1)//2]
  br=B[N//2]
  print(int(((br+bl)/2-(ar+al)/2)*2+1))
else:
  mini=A[(N-1)//2]
  maxi=B[(N-1)//2]
  print(maxi-mini+1)

Solution (Python):
n = int(input())
lst = [list(map(int, input().split())) for i in range(n)]
lst.sort()

if n%2 == 1:
  lst.sort()
  m = lst[n//2][0]
  lst.sort(key=lambda x: x[1])
  M = lst[n//2][1]
  print(M-m+1)
  
else:
  lst.sort()
  p, q  = lst[n//2-1][0], lst[n//2][0]
  m = p+q
  lst.sort(key=lambda x: x[1])
  P, Q  = lst[n//2-1][1], lst[n//2][1]
  M = P+Q
  print(M-m+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=sorted(a)
b=sorted(b,reverse=True)
if n%2==1:
    x=1+n//2
    print(b[x-1]-a[x-1]+1)
else:
    x=n//2
    print(b[x-1]+b[x]-a[x-1]-a[x]+1)

Solution (Python):
import sys

input = sys.stdin.buffer.readline

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:
    saisho = A[(n - 1) // 2]
    saidai = B[(n - 1) // 2]
    print(saidai - saisho + 1)
else:
    saisho1 = A[n // 2 - 1]
    saisho2 = A[n // 2]
    saidai1 = B[n // 2 - 1]
    saidai2 = B[n // 2]
    saidai = saidai2 + saidai1
    saisho = saisho2 + saisho1
    delta = saidai - saisho
    print(delta + 1)

Solution (Python):
n = int(input())
p = []
q = []
for i in range(n):
    a,b = map(int,input().split())
    p.append(a)
    q.append(b)

sop = sorted(p)
soq = sorted(q)
ans = 0
if n % 2 == 1:
    ans = soq[(n+1)//2-1] - sop[(n+1)//2-1] + 1
elif n % 2 == 0:
    s = soq[n//2-1]+soq[n//2]
    t = sop[n//2-1]+sop[n//2]
    ans = (s*0.5-t*0.5+1)*2 - 1
print(int(ans))

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

def main():
    N = int(input())
    a = [];b = []
    for _ in range(N):
        x,y = map(int,input().split())
        a.append(x)
        b.append(y)
    
    a.sort()
    b.sort()
    if N%2 == 0:
        l = (a[N//2]+a[N//2-1])*2
        r = (b[N//2]+b[N//2-1])*2
        print((r-l)//2+1)
    else:
        l = a[N//2]
        r = b[N//2]
        print(r-l+1)

if __name__ == "__main__":
    main()

Solution (Python):
n = int(input())
t = []
for i in range(n):
    ai,bi = map(int,input().split())
    t.append([ai,bi])

t.sort(key=lambda x:x[0])
if n % 2 == 1:
    a = t[n//2][0]
    t.sort(key=lambda x:x[1])
    b = t[n//2][1]
    print(b-a+1)
    exit()
if n % 2 == 0:
    a1 = t[n//2-1][0]
    a2 = t[n//2][0]
    t.sort(key=lambda x:x[1])
    b1 = t[n//2-1][1]
    b2 = t[n//2][1]
    print(b1+b2-a1-a2+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 = sorted(A)
B = sorted(B)

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

Solution (Python):
def e_count_median():
    N = int(input())
    
    Min, Max = [], []
    for _ in range(N):
        a, b = [int(i) for i in input().split()]
        Min.append(a)
        Max.append(b)

    Min.sort()
    Max.sort()
    if N % 2 == 0:
        median_min, median_max = Min[N // 2] + Min[N // 2 - 1], Max[N // 2] + Max[N // 2 - 1]
    else:
        median_min, median_max = Min[N // 2], Max[N // 2]
    return median_max - median_min + 1

print(e_count_median())

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

E = sorted(E,key=lambda x:x[0])

A=[v[0] for v in E]
B=[v[1] for v in E]

A = sorted(A)
B = sorted(B)


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

Solution (Python):
n = int(input())
a, b = [], []
for _ in range(n):
    tmp = list(map(int, input().split()))
    a.append(tmp[0])
    b.append(tmp[1])

a.sort()
b.sort()

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

Solution (Python):
from bisect import *
from collections import *

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

Solution (Python):
import sys

def input(): return sys.stdin.readline().strip()
def list2d(a, b, c): return [[c] * b for i in range(a)]
def list3d(a, b, c, d): return [[[d] * c for j in range(b)] for i in range(a)]
def list4d(a, b, c, d, e): return [[[[e] * d for j in range(c)] for j in range(b)] for i in range(a)]
def ceil(x, y=1): return int(-(-x // y))
def INT(): return int(input())
def MAP(): return map(int, input().split())
def LIST(N=None): return list(MAP()) if N is None else [INT() for i in range(N)]
def Yes(): print('Yes')
def No(): print('No')
def YES(): print('YES')
def NO(): print('NO')
sys.setrecursionlimit(10 ** 9)
INF = 10 ** 19
MOD = 10 ** 9 + 7

N = INT()
A = [0] * N
B = [0] * N
for i in range(N):
    A[i], B[i] = MAP()

A.sort()
B.sort()
if N % 2 == 0:
    mn = (A[N//2-1]+A[N//2]) / 2
    mx = (B[N//2-1]+B[N//2]) / 2
    ans = int((mx-mn)*2) + 1
else:
    mn = A[N//2]
    mx = B[N//2]
    ans = (mx-mn) + 1
print(ans)

Solution (Python):
import statistics

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

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

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

print(ans)

Solution (Python):
import sys
input = sys.stdin.readline
import numpy as np
from decimal import *

n = int(input())

Li = [[int(e) for e in input().split()] for _ in range(n)]

Li = np.array(Li)
LA = Li[:,0]
LB = Li[:,1]

LA.sort()
LB.sort()


if n %2 == 0: 
    idx =n //2 -1
    min = (LA[idx] + LA[idx+1])
    max = (LB[idx] + LB[idx+1])

else: 
    idx =(n+1) //2 -1
    min = LA[idx]
    max = LB[idx]

print(max - min +1 )

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