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):
N = int(input())
array1 = []
array2 = []
for i in range(N):
    a,b = map(int,input().split())
    array1.append(a)
    array2.append(b)

array1.sort()
array2.sort()

if N % 2 == 0:
    min = array1[N//2]+array1[N//2-1]
    max = array2[N//2]+array2[N//2-1]
    print(max-min+1)
else:
    min = array1[N//2]
    max = array2[N//2]
    print(max-min+1)

Solution (Python):
def getN():
    return int(input())
def getNM():
    return map(int, input().split())
def getList():
    return list(map(int, input().split()))
def getArray(intn):
    return [int(input()) for i in range(intn)]
def input():
    return sys.stdin.readline().rstrip()
def rand_N(ran1, ran2):
    return random.randint(ran1, ran2)
def rand_List(ran1, ran2, rantime):
    return [random.randint(ran1, ran2) for i in range(rantime)]
def rand_ints_nodup(ran1, ran2, rantime):
  ns = []
  while len(ns) < rantime:
    n = random.randint(ran1, ran2)
    if not n in ns:
      ns.append(n)
  return sorted(ns)

def rand_query(ran1, ran2, rantime):
  r_query = []
  while len(r_query) < rantime:
    n_q = rand_ints_nodup(ran1, ran2, 2)
    if not n_q in r_query:
      r_query.append(n_q)
  return sorted(r_query)

from collections import defaultdict, deque, Counter
from sys import exit
from decimal import *
from heapq import heapify, heappop, heappush
import math
import random
import string
from copy import deepcopy
from itertools import combinations, permutations, product
from operator import mul, itemgetter
from functools import reduce
from bisect import bisect_left, bisect_right

import sys
sys.setrecursionlimit(1000000000)
mod = 998244353





N = getN()
A = []
B = []
for i in range(N):
    a, b = getNM()
    A.append(a)
    B.append(b)
A.sort()
B.sort()













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

Solution (Python):
import sys
from collections import deque, defaultdict, Counter
from itertools import accumulate, product, permutations, combinations
from operator import itemgetter
from bisect import bisect_left, bisect_right
from heapq import heappop, heappush
from math import ceil, floor, sqrt, gcd, inf
from copy import deepcopy
import numpy as np
import scipy as sp

INF = inf
MOD = 1000000007

n = int(input())
A = [[int(i) for i in input().split()]for j in range(n)]    

tmp = 0
res = 0

x = np.median(np.array(A), axis=0)
if n % 2 == 0:
    res = int((x[1] - x[0]) * 2 + 1)
else:
    res = int(x[1] - x[0] + 1)

print(res)

Solution (Python):

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


if __name__ == "__main__":
    main()

Solution (Python):

N = int(input())
L, H = [0] * N, [0] * N

for i in range(N):
    L[i], H[i] = list(map(int, input().split()))

L.sort()
H.sort(reverse=True)
if N%2 == 1:
    i = (N-1)//2
    l, h = L[i], H[i]
    print(h-l+1)
else:
    i = N//2
    ll, lh = L[i-1], L[i]
    hl, hh = H[i-1], H[i]
    print((hh+hl) - (lh+ll) + 1)

Solution (Python):
import statistics
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:
  med_min = A[N // 2]
  med_max = B[N // 2]
  print(med_max - med_min + 1)  
else:
  med_min_db = A[N // 2] + A[N // 2 - 1]
  med_max_db = B[N // 2] + B[N // 2 - 1]
  print(med_max_db - med_min_db + 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:
  Amed=A[N//2]
  Bmed=B[N//2]
  print(Bmed-Amed+1)
else:
  Amed=(A[N//2]+A[N//2-1])/2
  Bmed=(B[N//2]+B[N//2-1])/2
  print(round((Bmed-Amed)*2+1))

Solution (Python):
from statistics import median


def main():
    n = int(input())
    a = [0] * n
    b = [0] * n
    for i in range(n):
        a[i], b[i] = map(int, input().split())
    ans = median(b) - median(a)
    if n % 2 == 0:
        ans *= 2
    ans = int(ans)
    ans += 1
    print(ans)


if __name__ == '__main__':
    main()

Solution (Python):
n = int(input())
A, B = map(list,zip(*[map(int,input().split()) for i in range(n)]))
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 statistics
N = int(input())
AB = [map(int, input().split()) for _ in range(N)]
A,B = [list(i) for i in zip(*AB)]
if N%2 == 1:
    low_med = statistics.median(A)
    high_med = statistics.median(B)
    print(high_med - low_med +1)
else:
    low_med = statistics.median(A)
    high_med = statistics.median(B)
    print(int(2 * (high_med - low_med) +1))

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

Solution (Python):
n = int(input())
x = []
med = []
a = []
b = []
for i in range(n):
    ai, bi = map(int, input().split())
    x.append((ai, bi))
    a.append(ai)
    b.append(bi)
a.sort()
b.sort()

if n % 2 == 1:
    min_med = a[(n+1)//2 - 1]
    max_med = b[(n+1)//2 - 1]
    print(max_med - min_med + 1)
else:
    min_med = (a[n//2 - 1] + a[n//2]) / 2
    max_med = (b[n//2 - 1] + b[n//2]) / 2
    ans = (max_med - min_med) / 0.5
    ans += 1
    ans = int(ans)
    print(ans)

Solution (Python):


N=int(input())
AB=[tuple(map(int,input().split())) for _ in [0]*N]

def med(A):
    N=len(A)
    if N%2:
        return A[(N+1)//2-1]
    else:
        return (A[N//2-1]+A[N//2])/2
    
A=[i[0] for i in AB]  
B=[i[1] for i in AB]
medA=med(sorted(A))
medB=med(sorted(B))

if N%2:
    print(medB-medA+1)
else:
    print(int(2*medB-2*medA+1))

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:
  ma = As[N//2]
  mb = Bs[N//2]
  print(mb-ma+1)
else:
  ma = (As[N//2-1] + As[N//2])/2
  mb = (Bs[N//2-1] + Bs[N//2])/2
  print(int((mb-ma)*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==1:
    print(B[n//2]-A[n//2]+1)
else:
    print(int(((B[n//2]+B[n//2-1])/2-(A[n//2]+A[n//2-1])/2)*2+1))

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

AB = []

for _ in range(N):
    AB.append(list(map(int, input().split())))

A_idx = [(AB[i][0], i) for i in range(N)]
B_idx = [(AB[i][1], i) for i in range(N)]

A_idx.sort(key=lambda e:e[0])
B_idx.sort(key=lambda e:e[0])

if N % 2 == 1:
    diff = B_idx[N//2][0]-A_idx[N//2][0]
    print(diff+1)
else:
    l = N//2-1
    u = N//2
    diff = (B_idx[l][0]+B_idx[u][0])-(A_idx[l][0]+A_idx[u][0])
    print(diff+1)

Solution (Python):
import sys
import itertools


def resolve(in_):
    N = int(next(in_))
    AB = (map(int, line.split()) for line in itertools.islice(in_, N))
    A = []
    B = []
    for a, b in AB:
        A.append(a)
        B.append(b)

    A.sort()
    B.sort()


    i = N // 2
    if N % 2:
        a_median = A[i]
        b_median = B[i]
        if a_median > b_median:
            a_median, b_median = b_median, a_median
        answer = len(range(a_median, b_median + 1))
    else:
        a_median2 = (A[i - 1] + A[i])  
        b_median2 = (B[i - 1] + B[i])  
        if a_median2 > b_median2:
            a_median2, b_median2 = b_median2, a_median2
        answer = len(range(a_median2, b_median2 + 1))
            
    return answer


def main():
    answer = resolve(sys.stdin.buffer)
    print(answer)


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

Solution (Python):

import sys
from itertools import chain
import numpy as np






def solve(N: int, A: "List[int]", B: "List[int]"):
    A = np.sort(A)
    B = np.sort(B)
    if N % 2 == 1:
        l = A[N // 2]
        r = B[N // 2]
        return r - l + 1
    else:
        l2 = A[N // 2 - 1] + A[N // 2]
        r2 = B[N // 2 - 1] + B[N // 2]
        return r2 - l2 + 1


def main():
    tokens = chain(*(line.split() for line in sys.stdin))
    
    N = int(next(tokens))  
    AB = np.array(list(map(int, tokens)), dtype=np.int32)
    A = AB[0::2]
    B = AB[1::2]
    answer = solve(N, A, B)
    print(answer)


if __name__ == "__main__":
    main()

Solution (Python):

import sys
from itertools import chain
import numpy as np






def solve(N: int, A: "List[int]", B: "List[int]"):
    A = sorted(A)
    B = sorted(B)
    if N % 2 == 1:
        l = A[N // 2]
        r = B[N // 2]
        return r - l + 1
    else:
        l2 = A[N // 2 - 1] + A[N // 2]
        r2 = B[N // 2 - 1] + B[N // 2]
        return r2 - l2 + 1


def main():
    tokens = chain(*(line.split() for line in sys.stdin))
    
    N = int(next(tokens))  
    AB = np.array(list(map(int, tokens)), dtype=np.int32)
    A = AB[0::2]
    B = AB[1::2]
    answer = solve(N, A, B)
    print(answer)


if __name__ == "__main__":
    main()

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

Alist = []
Blist = []

for _ in range(N):
    a, b = map(int, input().split())
    Alist.append(a)
    Blist.append(b)

Alist.sort()
Blist.sort()

if N%2==1:
    center_A = Alist[(N-1)//2]
    center_B = Blist[(N-1)//2]
    print(int(center_B - center_A + 1))

else:
    center_A = (Alist[N//2 - 1] + Alist[N//2]) / 2
    center_B = (Blist[N//2 - 1] + Blist[N//2]) / 2
    print(int(center_B * 2 - center_A * 2 + 1))

Solution (Python):
import numpy as np

N = int(input())
A = []
B = []

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

C = np.array(A)
D = np.array(B)

m_inf = np.median(C)
m_sup = np.median(D)

if N % 2 == 0:
    ans = 2 * m_sup - 2 * m_inf + 1
else:
    ans = m_sup - m_inf + 1

print(int(ans))

Solution (Python):
from operator import itemgetter

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

sortA = sorted(AB, key=itemgetter(0))
sortB = sorted(AB, key=itemgetter(1))

if n%2==1:
    print(sortB[n//2][1] - sortA[-n//2][0] + 1)

else:
    print(int(((sortB[n//2][1]+sortB[n//2-1][1])/2 - (sortA[n//2][0]+sortA[n//2-1][0])/2) / (1/2) + 1))

Solution (Python):


def solve():
    N = int(input())
    Ls, Rs = [], []
    for i in range(N):
        a, b = list(map(int, input().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)


if __name__ == "__main__":
    solve()

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 = sorted(A)
B = sorted(B)

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

Solution (Python):
import statistics
N= int(input())
min_all=[]
max_all = []
for _ in range(N):
    a,b=map(int,input().split())
    min_all.append(a)
    max_all.append(b)
min_median = statistics.median(min_all)
max_median = statistics.median(max_all)
if N%2:
    ans = max_median - min_median+1
else:
    ans = int((max_median - min_median +0.5)*2)
print(ans)

Solution (Python):
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==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)
A.sort()
B.sort()
def median(x):
  l=len(x)
  if l%2==0:
    return (x[l//2-1]+x[l//2])/2
  else:
    return x[l//2]
if N%2==1:
  print(median(B)-median(A)+1)
else:
  print(int((median(B)-median(A))*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()


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


if N % 2 == 0:
    
    min_med = A[N // 2 - 1] + A[N // 2]
    max_med = B[N // 2 - 1] + B[N // 2]
    ans = max_med - min_med + 1

print(ans)

Solution (Python):
import numpy as np

N, *AB = map(int, open(0).read().split())
min_med = np.median([a for a in AB[::2]])
max_med = np.median([b for b in AB[1::2]])
if N % 2:
    print(int(max_med - min_med) + 1)
else:
    print(int(max_med * 2 - min_med * 2) + 1)

Solution (Python):
N, *AB = map(int, open(0).read().split())
A = sorted(a for a in AB[::2])
B = sorted(b for b in AB[1::2])
if N % 2:
    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)

Solution (Python):
import sys

input_methods=['clipboard','file','key']
using_method=0
input_method=input_methods[using_method]

tin=lambda : map(int, input().split())
lin=lambda : list(IN())
mod=1000000007



def is_median(k, xl, is_odd):
	over = 0
	under = 0
	inner = 0
	same = 0
	for a,b in xl:
		if b < k:
			under+=1
		elif k<a:
			over+=1
		elif a==k and b == k:
			same+=1
		else:
			inner+=1
	
	if abs(under-over) < same+inner:
		return 0
	else:
		return 1 if under > over else -1

def main2():
	n = int(input())
	
	xl=[]
	for _ in range(n):
		a,b = tin()
		xl.append((a,b))
	
	min_v=0
	max_v=mod
	for a,b in xl:
		min_v=min(min_v, a)
		max_v=max(max_v, b)
	
	d = 1 if n % 2 == 0 else 1/2
	
	k_max_ok = min_v
	k_max_ng = max_v
	while k_max_ng - k_max_ok > d:
		pass
	
	k_min_ok = min_v
	
def main():
	n = int(input())
	al=[]
	bl=[]
	for i in range(n):
		a,b = tin()
		al.append(a)
		bl.append(b)
		
	al.sort()
	bl.sort()
	
	if n % 2 == 1:
		pos = ((n + 1) // 2) - 1
		d = bl[pos] - al[pos] + 1
		return d
	else:
		pos_l = ((n) // 2) - 1
		pos_r = pos_l + 1
		
		if al[pos_r] < bl[pos_l]:
			r = bl[pos_l] - al[pos_l] + bl[pos_r] - al[pos_r] + 1 - max(0, al[pos_r]-bl[pos_l])
		else:
			
			median_min = al[pos_l] + al[pos_r]
			median_max = bl[pos_l] + bl[pos_r]
			r = median_max - median_min + 1
			
		return r
		
			
		
	

isTest=False

def pa(v):
	if isTest:
		print(v)
		
def input_clipboard():
	import clipboard
	input_text=clipboard.get()
	input_l=input_text.splitlines()
	for l in input_l:
		yield l

if __name__ == "__main__":
	if sys.platform =='ios':
		if input_method==input_methods[0]:
			ic=input_clipboard()
			input = lambda : ic.__next__()
		elif input_method==input_methods[1]:
			sys.stdin=open('inputFile.txt')
		else:
			pass
		isTest=True
	else:
		pass
		
			
	ret = main()
	if ret is not None:
		print(ret)

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,B=map(sorted,(A,B))

if N % 2 == 1:
  mA, mB = A[N//2],B[N//2]
  print(mB-mA+1)
else:
  mA, mB = (A[N//2-1]+A[N//2])/2,(B[N//2-1]+B[N//2])/2
  print(int((mB-mA)/0.5+0.5)+1)

Solution (Python):
N = int(input())
X = [list(map(int,input().split())) for _ in range(N)]
A = sorted([X[i][0] for i in range(N)])
B = sorted([X[i][1] for i in range(N)])
if N%2==1:
    a = A[N//2]
    b = B[N//2]
    print(b-a+1)
else:
    a = (A[N//2]+A[N//2-1])
    b = (B[N//2]+B[N//2-1])
    print(b-a+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:
    minv = al[n//2]
    maxv = bl[n//2]
    print(maxv-minv+1)

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

Solution (Python):
from math import ceil,floor,factorial,gcd,sqrt,log2,cos,sin,tan,acos,asin,atan,degrees,radians,pi,inf
from itertools import accumulate,groupby,permutations,combinations,product,combinations_with_replacement
from collections import deque,defaultdict,Counter
from bisect import bisect_left,bisect_right
from operator import itemgetter
from heapq import heapify,heappop,heappush
from queue import Queue,LifoQueue,PriorityQueue
from copy import deepcopy
from time import time
from functools import reduce
import string
import sys
sys.setrecursionlimit(10 ** 7)
def input() : return sys.stdin.readline().strip()
def INT()   : return int(input())
def MAP()   : return map(int,input().split())
def MAP1()  : return map(lambda x:int(x)-1,input().split())
def LIST()  : return list(MAP())
def LIST1() : return list(MAP1())

def solve():
    N = INT()
    a = []
    b = []
    for i in range(N):
        A, B = MAP()
        a.append(A)
        b.append(B)
    a.sort()
    b.sort()

    if N % 2 == 1:
        am = a[(N+1)//2-1]
        bm = b[(N+1)//2-1]
        ans = bm - am + 1
    else:
        am = ( a[N//2-1]+a[N//2] ) / 2
        bm = ( b[N//2-1]+b[N//2] ) / 2
        ans = int( ( bm - am ) * 2 + 1 )
    print(ans)

if __name__ == '__main__':
    solve()

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(reverse=True)
b.sort()
if n%2:
  a_med = a[n//2]
  b_med = b[n//2]
  print(b_med - a_med + 1)
else:
  a_med = (a[n//2-1] + a[n//2])/2
  b_med = (b[n//2-1] + b[n//2])/2
  print(int((b_med - a_med)*2)+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(reverse=True)
b.sort()
if n%2:
  a_med = a[n//2]
  b_med = b[n//2]
  print(b_med - a_med + 1)
else:
  a_med = (a[n//2-1] + a[n//2])/2
  b_med = (b[n//2-1] + b[n//2])/2
  print(int((b_med - a_med)*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 == 1:
    print(B[N//2]-A[N//2]+1)
else:
    x = A[N//2-1]+A[N//2]
    y = B[N//2-1]+B[N//2]
    print(y-x+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==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):
def main():
    n = int(input())
    A,B = [],[]
    for _ in range(n):
        a,b = map(int,input().split())
        A.append(a)
        B.append(b)
    A,B = sorted(A),sorted(B)
    if n%2==0:
        a_m,b_m = (A[n//2]+A[n//2-1]),(B[n//2]+B[n//2-1])
        print(b_m-a_m+1)
    else:
        a_m,b_m = A[n//2],B[n//2]
        print(b_m-a_m+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:ans=b[n//2]-a[n//2]+1
else:ans=b[(n-1)//2+1]-a[(n-1)//2+1]+b[(n-1)//2]-a[(n-1)//2]+1
print(ans)

Solution (Python):
n=int(input())
m=[]
M=[]
for _ in range(n):
    x,y=map(int,input().split())
    m.append(x)
    M.append(y)
m=sorted(m)
M=sorted(M)

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

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

A.sort()
B.sort()

def median(a):
    n = N
    return a[(n+1)//2-1] if n%2 else (a[n//2-1]+a[n//2])/2

A_mid = median(A)
B_mid = median(B)

r = int((B_mid-A_mid) * [2, 1][N%2]) + 1

print(r)

Solution (Python):
from statistics import median
N = int(input())
A = []
B = []
for n in range(N):
    a, b = map(int, input().split())
    A.append(a)
    B.append(b)


cenA = median(A)
cenB = median(B)


if N % 2 == 1:
    print(int(cenB - cenA + 1))

elif N % 2 == 0:
    print(int((cenB - cenA)*2 + 1))
    
else:
    print('RE')

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)
mid = N // 2
if N % 2 == 1:
    print(ub[mid] - lb[mid] + 1)
else:
    ans = (ub[mid - 1] + ub[mid]) - (lb[mid - 1] + lb[mid]) + 1
    print(ans)

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

a=[0]*n
b=[0]*n

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

cen_a=statistics.median(a)
cen_b=statistics.median(b)

if n%2==1:
    print(cen_b-cen_a+1)
else:
    print(int((cen_b-cen_a)*2+1))

Solution (Python):
n=int(input())
import bisect as bi
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:
    a=A[(n-1)//2] ; b=B[(n-1)//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)/0.5)+1)

Solution (Python):
import sys
input = sys.stdin.readline
N = int(input())
AB = [tuple(map(int,input().split())) for i in range(N)]
A = []
B = []
for a,b in AB:
    A.append(a)
    B.append(b)
A.sort()
B.sort()

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

Solution (Python):
N = int(input())
X = [list(map(int,input().split())) for _ in range(N)]
A = sorted([X[i][0] for i in range(N)])
B = sorted([X[i][1] for i in range(N)])
if N%2==1:
    a = A[N//2]
    b = B[N//2]
    print(b-a+1)
else:
    a = (A[(N-1)//2]+A[N//2])/2
    b = (B[(N-1)//2]+B[N//2])/2
    print(int((b-a)/0.5)+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:
    mmin = al[n//2]
    mmax = bl[n//2]
    print(mmax-mmin+1)
else:
    mmin = (al[n//2]+al[n//2-1])/2
    mmax = (bl[n//2]+bl[n//2-1])/2
    ans = (mmax-mmin)*2+1
    ans = round(ans+0.1)
    print(ans)

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

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

N = int(input())
A, B = [], []

for _ in range(N):
    Ai, Bi = map(int, input().split())
    A.append(Ai)
    B.append(Bi)
    
l, h = m(A), m(B)

if N%2==0:
    print(int((h-l)*2+1))
else:
    print(h-l+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:
    x = A[n//2-1]+A[n//2]
    y = B[n//2-1]+B[n//2]
    ans = y-x+1
else:
    x = A[n//2]
    y = B[n//2]
    ans = y-x+1
print(ans)

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

Solution (Python):
n = int(input())
a = []
b = []
for i in range(n):
    s,t = map(int,input().split())
    a.append(s)
    b.append(t)
a.sort()
b.sort()
if n%2 == 0:
    am = (a[n//2-1]+a[n//2])/2
    bm = (b[n//2-1]+b[n//2])/2
    print(int((bm-am)*2+1))
else:
    am = a[(n-1)//2]
    bm = b[(n-1)//2]
    print(bm-am+1)

Solution (Python):
import statistics
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(statistics.median(B)-statistics.median(A)+1)
else:
  print(int(statistics.median(B)*2-statistics.median(A)*2+1))

Solution (Python):
ni = lambda: int(input())
nm = lambda: map(int, input().split())
nl = lambda: list(map(int, input().split()))

n=ni()
mins=[]
maxs=[]
for i in range(n):
  a,b=nm()
  mins.append(a)
  maxs.append(b)

smn = sorted(mins)
smx = sorted(maxs)

if n%2==1:
  mn = smn[(n+1)//2-1]
  mx = smx[(n+1)//2-1]
  print(round((mx-mn)+1))
else:
  mn = (smn[n//2-1]+smn[n//2])/2.0
  mx = (smx[n//2-1]+smx[n//2])/2.0
  print(round((mx-mn)*2+1))

Solution (Python):
from sys import stdin
import sys
import math
from functools import reduce
import functools
import itertools
from collections import deque,Counter
from operator import mul
import copy



import heapq

n = int(input())

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

    aa.append(a)
    bb.append(b)

aa.sort()
bb.sort()

if n % 2 == 0:
    m_a = (aa[n // 2 - 1] + aa[n // 2])
    m_b = (bb[n // 2 - 1] + bb[n // 2])

    print(m_b - m_a+1)
    sys.exit()

else:
    median_a = aa[n // 2]
    median_b = bb[n // 2]

    print(median_b-median_a+1)
    sys.exit()

Solution (Python):
import collections
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()
N_q, N_mod = divmod(N, 2)
if N_mod == 1:
    ans = B[N_q] - A[N_q] + 1
else:
    ans = B[N_q - 1] - A[N_q - 1] + B[N_q] - A[N_q] + 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:
    l = A[N // 2 - 1] + A[N // 2]
    u = B[N // 2 - 1] + B[N // 2]
    print(u - l + 1)
else:
    l = A[N // 2]
    u = B[N // 2]
    print(u - l + 1)

Solution (Python):
N=int(input())
L=[]
for i in range(N):
    A, B=list(map(int,input().split()))
    L.append((A,B))
L1=sorted(L,key=lambda x: x[0])
L2=sorted(L,key=lambda x: x[1])
if N%2==1:
    n=N//2
    print(L2[n][1] -L1[n][0]+1)
else:
    n=N//2
    m=(L1[n-1][1]+L1[n][1])/2
    print(L2[n-1][1]+L2[n][1]-L1[n-1][0]-L1[n][0]+1)

Solution (Python):
from sys import stdin
nii=lambda:map(int,stdin.readline().split())
lnii=lambda:list(map(int,stdin.readline().split()))
from statistics import median

n=int(input())
l1=[]
l2=[]
for i in range(n):
  a,b=nii()
  l1.append(a)
  l2.append(b)

m1=median(l1)
m2=median(l2)
ans=m2-m1

if n%2==0:
  ans*=2

print(int(ans+1))

Solution (Python):
from sys import stdin
nii=lambda:map(int,stdin.readline().split())
lnii=lambda:list(map(int,stdin.readline().split()))
from statistics import median

n=int(input())
l1=[]
l2=[]
for i in range(n):
  a,b=nii()
  l1.append(a)
  l2.append(b)

l1.sort()
l2.sort()

m1=median(l1)
m2=median(l2)

if n%2==1:
  ans=m2-m1
else:
  ans=(m2-m1)*2

print(int(ans+1))

Solution (Python):
from sys import stdin
nii=lambda:map(int,stdin.readline().split())
lnii=lambda:list(map(int,stdin.readline().split()))

n=int(input())
l1=[]
l2=[]
for i in range(n):
  a,b=nii()
  l1.append(a)
  l2.append(b)

l1.sort()
l2.sort()

if n%2==1:
  ans=l2[n//2]-l1[n//2]
else:
  m1=(l2[n//2]+l2[n//2-1])
  m2=(l1[n//2]+l1[n//2-1])
  ans=m1-m2

print(ans+1)

Solution (Python):
n,*t=map(int,open(0).read().split())
A=sorted(t[0::2])
B=sorted(t[1::2])
if n%2==0:
    kl=n//2-1
    kr=n//2
else:
    kl=n//2
    kr=n//2
lm,lM=A[kl],A[kr]
rm,rM=B[kl],B[kr]
L,R=0,0
if n%2==0:
    L=lm+lM
    R=rm+rM
    a=R-L+1
else:
    a=rm-lm+1
print(a)

Solution (Python):
N = int(input())
X = [list(map(int,input().split())) for _ in range(N)]
A = sorted([X[i][0] for i in range(N)])
B = sorted([X[i][1] for i in range(N)])
if N%2==1:
    k = (N+1)//2
    a = A[k-1]
    b = B[k-1]
    print(b-a+1)
else:
    a2 = A[N//2-1]+A[N//2]
    b2 = B[N//2-1]+B[N//2]
    print(b2-a2+1)

Solution (Python):
import sys
def input(): return sys.stdin.readline().strip()
def mapint(): return map(int, input().split())
sys.setrecursionlimit(10**9)

N = int(input())
As = []
Bs = []
for _ in range(N):
    A, B = mapint()
    As.append(A)
    Bs.append(B)
As.sort()
Bs.sort()

if N%2==1:
    left = As[N//2]
    right = Bs[N//2]
else:
    left = (As[N//2]+As[N//2-1])
    right = (Bs[N//2]+Bs[N//2-1])

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

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

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

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

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

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):
import sys
import numpy as np
input = sys.stdin.readline
read = sys.stdin.read


def log(*args):
    print(*args, file=sys.stderr)


def main():
    np.set_printoptions(threshold=20)
    N = int(input())
    AB = np.array(read().split(), dtype=np.int)
    A = AB[0::2]
    B = AB[1::2]
    A.sort()
    B.sort()
    if N % 2 == 1:
        n = N // 2
        print(B[n] - A[n] + 1)
    else:
        n = N // 2
        print((B[n] + B[n - 1]) - (A[n] + A[n - 1]) + 1)



if __name__ == '__main__':
    main()

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

from statistics import median

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

Solution (Python):
import sys

import bisect


def input():
    return sys.stdin.readline().rstrip()


def main():
    N = int(input())
    A = []
    B = []
    for i in range(N):
        a, b = map(int, input().split())
        A.append(a)
        B.append(b)
    pass
    A.sort()
    B.sort()
    if N % 2 == 0:
        n = N // 2
        mini = (A[n]+A[n-1]) /2
        maxi = (B[n]+B[n-1]) /2
        print(int((maxi-mini)*2)+1)
    else:
        n = N//2
        mini = A[n]
        maxi = B[n]
        print(maxi-mini+1)



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)

A.sort()
B.sort()

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