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())
AB = [tuple(map(int, input().split())) for i in range(n)]
A = [AB[i][0] for i in range(n)]
B = [AB[i][1] for i in range(n)]



A.sort()
B.sort()

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


if n % 2 == 0:
    
    
    
    

    
    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())
ab = [list(map(int, input().split())) for _ in range(n)]
a = [i for i, j in ab]
b = [j for i, j in ab]
a.sort()
b.sort()

if n % 2 == 1:
    print(abs(b[n//2] - a[n//2]) + 1)
else:
    t = [a[n // 2], a[n // 2 - 1], b[n // 2], b[n // 2 - 1]]
    print(int(abs((t[0] + t[1]) / 2 - (t[2] + t[3]) / 2) / 0.5) + 1)

Solution (Python):
def read_int():
    return int(input())


def read_ints():
    return map(int, input().split(' '))


n = read_int()
a = []
b = []
for i in range(n):
    ai, bi = read_ints()
    a.append(ai)
    b.append(bi)
a.sort()
b.sort()
if n % 2 == 0:
    ma = a[n // 2 - 1] + a[n // 2]
    mb = b[n // 2 - 1] + b[n // 2]
    print(mb - ma + 1)
else:
    ma = a[n // 2]
    mb = b[n // 2]
    print(mb - ma + 1)

Solution (Python):
import sys
sys.setrecursionlimit(10000000)
import numpy as np
from heapq import heapify, heappop, heappush
import copy
from math import gcd, ceil
from collections import deque

from bisect import bisect_left, bisect_right









def main():
    N = int(input())
    Bs = []
    As = []
    for i in range(N):
        a, b = map(int, input().split())
        As.append(a)
        Bs.append(b)
    min_med = np.median(As)
    max_med = np.median(Bs)
    if N % 2 == 0:
        print(int(2 * (max_med - min_med) + 1))
    else:
        print(int((max_med - min_med) + 1))
    


if __name__ == '__main__':
    main()

Solution (Python):
import sys
import copy
from collections import deque
stdin = sys.stdin

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

n = ni()

li = []
for _ in range(n):
    li.append(na())

li.sort()

def solve_odd():
    mid = int((n-1)/2)
    li.sort()
    left = li[mid][0]
    li.sort(key=lambda x: x[1])
    right = li[mid][1]
    print(right-left+1)

def solve_even():
    mid = int(n/2)
    li.sort()
    left1 = li[mid-1][0]
    left2 = li[mid][0]
    li.sort(key=lambda x: x[1])
    right1 = li[mid-1][1]
    right2 = li[mid][1]
    st = (left1+left2)/2
    en = (right1+right2)/2
    print(int((en-st)*2+1))


if n%2:
    solve_odd()
else:
    solve_even()

Solution (Python):
n = int(input())
a = [-1]
b = [-1]
for _ in range(n):
	ai,bi = map(int,input().split())
	a.append(ai)
	b.append(bi)
a = sorted(a)
b = sorted(b)
count = 0
if n%2 == 1:
	count = b[(n+1)//2] - a[(n+1)//2] + 1
else:
	a1 = a[n//2]
	b1 = b[n//2]
	a2 = a[n//2+1]
	b2 = b[n//2+1]
	count += 2*(b1-a2)+1
	count += (a2-a1)
	count += (b2-b1)
print(count)

Solution (Python):
def main():
    import sys
    input = sys.stdin.readline
    sys.setrecursionlimit(10**6)
    N = int(input())
    An = [0] * N
    Bn = [0] * N
    for n in range(N):
        An[n], Bn[n] = [int(x) for x in input().strip().split()]
    An.sort()
    Bn.sort(reverse=True)
    if N % 2:
        A = An[(N+1)//2-1]
        B = Bn[(N+1)//2-1]
        print(B - A + 1)
    else:
        Amin = An[N//2-1]
        Amax = Bn[N//2]
        Bmax = Bn[N//2-1]
        Bmin = An[N//2]
        
        print(int(((Bmax+Amax)/2-(Bmin+Amin)/2)//0.5+1))

if __name__ == '__main__':
    main()

Solution (Python):
import sys

import math





input=sys.stdin.readline
n=int(input())
ab=[list(map(int,input().split())) for _ in range(n)]
a, b = [list(i) for i in zip(*ab)]
a.sort()
b.sort()
if n%2==1:
    ma=a[(n-1)//2]
    mb=b[(n-1)//2]
    print(mb-ma+1)
else:
    ma=a[n//2]+a[n//2-1]
    mb=b[n//2]+b[n//2-1]
    print(mb-ma+1)

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)

medA = statistics.median(A)
medB = statistics.median(B)

if N % 2 == 1:
    print(medB - medA+1)
else:
    print(int((medB - medA)*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.sort()
    B.sort()
    if N%2==0:
        a_t=(A[N//2]+A[N//2-1])/2
        b_t=(B[N//2]+B[N//2-1])/2
        print(int((b_t-a_t)//0.5+1))
    else:
        a_t=A[N//2]
        b_t=B[N//2]
        print(int((b_t-a_t)//1+1))
main()

Solution (Python):
N = int(input())
A = dict()
B = dict()
for i in range(N):
    a, b = map(int, input().split())
    A[i] = a
    B[i] = b
A_sort = sorted(A.items(), key=lambda x:x[1])
B_sort = sorted(B.items(), key=lambda x:x[1])

if N % 2 == 1:
    print(B_sort[(N+1)//2-1][1]-A_sort[(N+1)//2-1][1]+1)
else:
    B_min = B_sort[N//2-1][1]
    A_min = A_sort[N//2-1][1]
    A_max = A_sort[N//2][1]
    B_max = B_sort[N//2][1]
    print(-A_max+B_max-A_min+B_min+1)

Solution (Python):
def main():
    n = int(input())
    AB = [[int(e) for e in input().split()] for i in range(n)]

    Ma = sorted([ab[0] for ab in AB])
    Mb = sorted([ab[1] for ab in AB])
    if n % 2 == 1:
        mi = Ma[((n + 1) // 2) - 1]
        ma = Mb[((n + 1) // 2) - 1]
        print(ma - mi + 1)

    else:
        mi = (Ma[n // 2 - 1] + Ma[n // 2])
        ma = (Mb[n // 2 - 1] + Mb[n // 2])
        print(ma - mi + 1)


if __name__ == '__main__':
    main()

Solution (Python):
from operator import itemgetter
import copy

n = int(input())
ab = sorted([list(map(int, input().split())) for i in range(n)])
abr = copy.copy(ab)
abr.sort(key=itemgetter(1))
if n % 2:
    a1,b1 = ab[n//2]
    a2,b2 = abr[n//2]
    ans = b2 - a1 + 1
else:
    a1,b1 = ab[n//2-1]
    a2,b2 = abr[n//2-1]
    a3,b3 = ab[n//2]
    a4,b4 = abr[n//2]
    ans = b4 - a3 + b2 - a1 + 1
print(ans)

Solution (Python):
import sys
sys.setrecursionlimit(10000000)
import numpy as np
from heapq import heapify, heappop, heappush
import copy
from math import gcd, ceil
from collections import deque

from bisect import bisect_left, bisect_right









def main():
    N = int(input())
    Bs = []
    As = []
    for i in range(N):
        a, b = map(int, input().split())
        As.append(a)
        Bs.append(b)
    min_med = np.median(As)
    max_med = np.median(Bs)
    if N % 2 == 0:
        print(int(2 * (max_med - min_med) + 1))
    else:
        print(int((max_med - min_med) + 1))
    


if __name__ == '__main__':
    main()

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

    lowerlist = []
    upperlist = []

    for ab in AB:
        lowerlist.append(ab[0])
        upperlist.append(ab[1])

    lowerlist.sort()
    upperlist.sort(reverse=True)

    if N % 2 == 0:
        
        lowermid = (lowerlist[N//2-1] + lowerlist[N//2]) / 2
        
        uppermid = (upperlist[N//2-1] + upperlist[N//2]) / 2
        print(int((uppermid - lowermid) * 2) + 1)
    else:
        
        lowermid = lowerlist[N//2]
        uppermid = upperlist[N//2]
        print(uppermid-lowermid+1)


if __name__ == "__main__":
    main()

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

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)
ma=statistics.median(A)
mb=statistics.median(B)
if N%2==0:
    print(int((mb-ma)*2+1))
else:
    print(int((mb-ma)+1))

Solution (Python):
N = int(input())
I = [tuple(map(int, input().split())) for _ in range(N)]
As = []
Bs = []
for a, b in I:
	As.append(a)
	Bs.append(b)
As.sort()
Bs.sort()

if N % 2 == 0:
	lows = As[N//2] + As[N//2-1]
	his = Bs[N//2] + Bs[N//2-1]
else:
	lows = As[N//2]
	his = Bs[N//2]

print(his - lows + 1)

Solution (Python):
import os

import itertools
import sys
import numpy as np

if os.getenv("LOCAL"):
    sys.stdin = open("_in.txt", "r")

sys.setrecursionlimit(10 ** 9)
INF = float("inf")
IINF = 10 ** 18
MOD = 10 ** 9 + 7


N = int(sys.stdin.buffer.readline())
A, B = list(zip(*[map(int, sys.stdin.buffer.readline().split()) for _ in range(N)]))
A = list(A)
B = list(B)
AB = list(zip(A, B))


def test():
    ranges = (range(a, b + 1) for a, b in AB)
    s = set()
    for X in itertools.product(*ranges):
        s.add(np.median(np.array(X, dtype=float)))
    print(len(s))
    print(list(sorted(s)))


A.sort()
B.sort()


def solve_odd():
    mid = N // 2
    l, r = A[mid], B[mid]
    return r - l + 1


def solve_even():
    mid = N // 2 - 1
    l1, l2 = A[mid:mid + 2]
    r1, r2 = B[mid:mid + 2]
    return r1 + r2 - l1 - l2 + 1
    
    
    
    
    
    


if N % 2 == 1:
    ans = solve_odd()
else:
    ans = solve_even()
print(ans)

Solution (Python):
inpl = lambda: list(map(int,input().split()))
N = int(input())
AB = [ inpl() for _ in range(N) ]
AB.sort()
if N % 2:
    med1 = AB[(N+1)//2-1][0]
else:
    med1 = AB[N//2-1][0] + AB[N//2][0]

AB.sort(key=lambda x: x[1])
if N % 2:
    med2 = AB[(N+1)//2-1][1]
else:
    med2 = AB[N//2-1][1] + AB[N//2][1]

print(med2 - med1 + 1)

Solution (Python):
from sys import stdin
from copy import deepcopy
from functools import reduce
from fractions import gcd
import math
import itertools
from collections import Counter
from itertools import chain  
from heapq import heappush, heappop
import bisect

"""
N = int(input())
A, B = map(int,input().split())
A = list(map(int,input().split())) 
A = [int(input()) for _ in range(N)] 
lst = [list(map(int,input().split())) for i in range(M)] 
"""

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

lst_min = []
lst_max = []
for i in range(N):
  lst_min.append(lst[i][0])
  lst_max.append(lst[i][1])
lst_min.sort()
lst_max.sort()

if N % 2 == 1: 
  median_min = lst_min[(N+1)//2 -1]
  median_max = lst_max[(N+1)//2 -1]
else: 
  median_min = (lst_min[N//2 -1] + lst_min[N//2]) / 2.0
  median_max = (lst_max[N//2 -1] + lst_max[N//2]) / 2.0
  
if N % 2 == 1: 
  ans = median_max - median_min + 1
else: 
  ans = int(2*median_max - 2*median_min + 1)
  
print(ans)

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

Solution (Python):
N = int(input())
A = []
B = []
for i in range(N):
  temp = list(map(int, input().split()))
  A.append(temp[0])
  B.append(temp[1])
As = sorted(A)
Bs = sorted(B)

if(N%2==1):
  print(Bs[N//2] - As[N//2] + 1)
else:
  ans = ( (Bs[N//2-1]+Bs[N//2])/2 - (As[N//2-1]+As[N//2])/2 ) * 2 + 1
  print(int(ans))

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

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

for i in range(n):
    a[i] = cnd[i][0]
    b[i] = cnd[i][1]
    
a.sort()
b.sort()

if n%2 == 1:
    a_cen = a[n//2]
    b_cen = b[n//2]
else:
    a_cen1 = a[n//2 - 1]
    a_cen2 = a[n//2]
    b_cen1 = b[n//2 - 1]
    b_cen2 = b[n//2]
    a_cen = a_cen1 + a_cen2
    b_cen = b_cen1 + b_cen2
    
ans = b_cen - a_cen + 1
print(ans)

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

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

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

Solution (Python):
N = int(input())
I = []

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

L = sorted(I)
R = sorted(I, key = lambda x: x[1])

if N%2 == 1:
  x = N//2
  print(R[x][1] - L[x][0] + 1)
else:
  x = N//2
  M = R[x][1] - L[x][0] + 1
  m = R[x-1][1] - L[x-1][0] + 1
  print(M + m - 1)

Solution (Python):
import itertools
import copy
from collections import deque
import heapq
n = int(input())
ma = []
mi = []
for i in range(n):
    a,b = map(int,input().split())
    mi.append(a)
    ma.append(b)
mi.sort()
ma.sort()
if n % 2 == 1:
    ans = ma[(n+1)//2-1]-mi[(n+1)//2-1] + 1
else:
    ans = (ma[n//2]+ma[n//2-1]-mi[n//2]-mi[n//2-1])+1
print(ans)

Solution (Python):

from collections import defaultdict,deque
from heapq import heappush, heappop
from bisect import bisect_left, bisect_right
import sys, random, itertools, math
sys.setrecursionlimit(10**5)
input = sys.stdin.readline
sqrt = math.sqrt
def LI(): return list(map(int, input().split()))
def LF(): return list(map(float, input().split()))
def LI_(): return list(map(lambda x: int(x)-1, input().split()))
def II(): return int(input())
def IF(): return float(input())
def S(): return input().rstrip()
def LS(): return S().split()
def IR(n): return [II() for _ in range(n)]
def LIR(n): return [LI() for _ in range(n)]
def FR(n): return [IF() for _ in range(n)]
def LFR(n): return [LI() for _ in range(n)]
def LIR_(n): return [LI_() for _ in range(n)]
def SR(n): return [S() for _ in range(n)]
def LSR(n): return [LS() for _ in range(n)]
mod = 1000000007
inf = float("INF")


def solve():
    n = II()
    ab = LIR(n)
    ab.sort()
    if n & 1:
        ans = ab[n // 2][0]
    else:
        ans = ab[n // 2 - 1][0] + ab[n // 2][0]
        ans /= 2
    ab = list(map(lambda x: x[1], ab))
    ab.sort()
    if n & 1:
        print((ab[n // 2] - ans) + 1)
    else:
        print(int(((ab[n // 2 - 1] + ab[n // 2]) / 2 - ans) * 2 + 1))
    return



if __name__ == '__main__':
    solve()

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

A=[]
B=[]
for i in range(N):
    A.append(C[i][0])
    B.append(C[i][1])

A.sort()
B.sort()

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

print(mB-mA+1)

Solution (Python):
import sys
from statistics import median

sys.setrecursionlimit(10 ** 7)
input = sys.stdin.readline
f_inf = float('inf')
mod = 10 ** 9 + 7


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

    if n % 2:
        am = median(A)
        bm = median(B)
        print(int(abs(bm - am) + 1))
    else:
        A.sort()
        B.sort()
        am = (A[n // 2 - 1] + A[n // 2]) / 2
        bm = (B[n // 2 - 1] + B[n // 2]) / 2
        print(int(abs((bm - am) * 2) + 1))


if __name__ == '__main__':
    resolve()

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

print(ans)

Solution (Python):
import sys

def main():
    N = int(input())
    lines = sys.stdin.read().strip().split('\n')
    AB = list(map(lambda l: list(tuple(map(int, l))), map(str.split, lines)))
    AB_by_A = sorted(AB)
    AB_by_B = sorted(AB, key=lambda t: (t[1], t[0]))
    if N % 2 == 1:
        mn = AB_by_A[N//2][0]
        mx = AB_by_B[N//2][1]
        print(mx - mn + 1)
        return
    mn1 = AB_by_A[N//2 - 1][0]
    mn2 = AB_by_A[N//2][0]
    mx1 = AB_by_B[N//2 - 1][1]
    mx2 = AB_by_B[N//2][1]
    mn = mn1 + mn2
    mx = mx1 + mx2
    print(mx - mn + 1)
    return

if __name__ == '__main__':
    main()

Solution (Python):
n = int(input())
a_list = []
b_list = []

for _ in range(n):
    a, b = map(int,input().split())
    a_list.append(a)
    b_list.append(b)

a_list.sort()
b_list.sort()

if n%2==0:
    half = int(n/2)
    first = (a_list[half-1]+a_list[half])/2
    last = (b_list[half-1]+b_list[half])/2
    print(int((last-first)/0.5)+1)
else:
    half = int((n+1)/2)
    print(b_list[half-1]-a_list[half-1]+1)

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


if n % 2 == 1:
  man = n // 2 + 1
  ab.sort(key=lambda x:x[0])
  ansmin1 = ab[man-1][0]
  ab.sort(key=lambda x:x[1])
  ansmax2 = ab[man-1][1]
  print(ansmax2-ansmin1+1)
else:
  man = n // 2 
  man2 = n // 2 + 1
  ab.sort(key=lambda x:x[0])
  ansmin1 = ab[man-1][0]
  ansmin2 = ab[man2-1][0]
  ab.sort(key=lambda x:x[1])
  ansmax1 = ab[man-1][1]
  ansmax2 = ab[man2-1][1]
  print(ansmax1+ansmax2-ansmin1-ansmin2+1)

Solution (Python):
import statistics

N = int(input())
P = [[int(i) for i in input().split()] for _ in range(N)]


left = []
right = []

for i in range(N):
    left.append(P[i][0])
    right.append(P[i][1])

lmed = statistics.median(left)
rmed = statistics.median(right)

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

Solution (Python):
import sys
import math
import itertools
import collections
import heapq
import numpy as np

rl = sys.stdin.readline
n = int(rl())
a = []
b = []
for _ in range(n):
    aa, bb = map(int, rl().split())
    a.append(aa)
    b.append(bb)

def heapsort(iterable):
    h = []
    for value in iterable:
        heapq.heappush(h, value)
    return [heapq.heappop(h) for i in range(len(h))]
a = heapsort(a)
b = heapsort(b)
if n&1:
    ans = b[n//2] - a[n//2] + 1
else:
    c = a[n//2] + a[n//2 - 1]
    d = b[n//2] + b[n//2 - 1]
    ans = (d/2 - c/2) / 0.5 + 1
print(int(ans))

Solution (Python):
TEST = False

if not TEST:
    N = int(input())
    AS = []
    BS = []
    for i in range(N):
        A, B = [int(x) for x in input().split()]
        AS.append(A)
        BS.append(B)


def getBound(AS, BS):
    """
    >>> getBound([0, 1], [1, 2])
    1 3 3
    >>> getBound([0, 0], [1, 2])
    1 3 3
    >>> getBound([0, 1, 2], [1, 2, 3])
    1 2 2
    >>> getBound([0, 1, 2], [1, 3, 3])
    1 3 3
    >>> getBound([0, 0, 1], [2, 3, 3])
    0 3 4
    """
    N = len(AS)
    AS2 = AS[:]
    AS2.sort()

    BS2 = BS[:]
    BS2.sort()
    if N % 2 == 0:
        lower = AS2[N // 2 - 1] + AS2[N // 2]
        upper = BS2[N // 2 - 1] + BS2[N // 2]
        result = upper - lower + 1
    else:
        lower = AS2[N // 2]
        upper = BS2[N // 2]
        result = upper - lower + 1
    if TEST:
        print(lower, upper, result)
    else:
        return result


def _test():
    import doctest
    doctest.testmod()


if TEST:
    _test()
else:
    print(getBound(AS, BS))

Solution (Python):

def Z(): return int(input())
def ZZ(): return [int(_) for _ in input().split()]

def main():
    N = Z()
    A, B = [], []
    for _ in range(N):
        a, b = ZZ()
        A.append(a)
        B.append(b)
    A.sort()
    B.sort()
    midA = A[N//2] if N%2 == 1 else (A[N//2-1] + A[N//2])
    midB = B[N//2] if N%2 == 1 else (B[N//2-1] + B[N//2])
    print(midB-midA+1)

    return

if __name__ == '__main__':
    main()

Solution (Python):




if(__name__ == '__main__'):
    
    n = int(input())

    min_list = []
    max_list = []
    for _ in range(n):
        a, b = map(int, input().split(" "))

        min_list.append(a)
        max_list.append(b)

    min_list.sort()
    max_list.sort()

    min_val2 = 1
    max_val2 = 1
    if n%2 == 0:
        cent1 = n//2-1
        cent2 = n//2
        min_val2 = min_list[cent1] + min_list[cent2]
        max_val2 = max_list[cent1] + max_list[cent2]
    else:
        cent = (n+1)//2-1
        min_val2 = min_list[cent]
        max_val2 = max_list[cent]

    ans = max_val2 - min_val2 + 1
    print(ans)

Solution (Python):
import sys
from itertools import accumulate


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


sys.setrecursionlimit(20000000)

MOD = 10 ** 9 + 7
INF = float("inf")


def main():
    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:
        start = A[((N + 1) // 2) - 1]
        last = B[((N + 1) // 2) - 1]
        print(last - start + 1)
    else:
        start = (A[(N // 2) - 1] + A[(N // 2 + 1) - 1]) / 2
        last = (B[(N // 2) - 1] + B[(N // 2 + 1) - 1]) / 2
        print(int((last - start) * 2 + 1))


if __name__ == "__main__":
    main()

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

d = sorted(d)
u = sorted(u, reverse=True)
if n % 2 == 0:
    dl = (d[n//2] + d[n//2-1]) / 2
    ul = (u[n//2] + u[n//2-1]) / 2
    ans = int((ul-dl) / 0.5 + 1)
else:
    dl = d[n//2]
    ul = u[n//2]
    ans = ul-dl+1
print(ans)

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

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

listXmin = []
listXmax = []
maxXi = 0
minXi = 10 ** 10
for i in range(N):
    listXmin.append(A[i])
    listXmax.append(B[i])

listXmin.sort()
listXmax.sort()
if N % 2 == 0:
    centrali = int(N / 2) - 1
    centralinext = int(N / 2)
    print(((listXmax[centrali] + listXmax[centralinext]) - (listXmin[centrali] + listXmin[centralinext])) + 1)
else:
    centrali = int((N + 1) / 2) - 1
    print(listXmax[centrali] - listXmin[centrali] + 1)

Solution (Python):
n = int(input())
aa = []
bb = []

for _ in range(n):
  a,b = map(int,input().split())
  aa.append(a)
  bb.append(b)

aa= sorted(aa)[(n-1)//2:]
bb= sorted(bb,reverse=True)[(n-1)//2:]
if n%2==1:
  print(abs(bb[0]-aa[0])+1)
else:
  print((bb[0]+bb[1])-(aa[0]+aa[1])+1)

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

rs = []
aes = []
bs = []

for _ in range(n):
  a, b = map(int, input().split())
  rs.append([a,b])
  aes.append(a)
  bs.append(b)


aes.sort()
bs.sort(reverse=True)

if n % 2 == 1:
  p = aes[(n - 1) // 2]
  q = bs[(n - 1) // 2]
  ans = q - p + 1
else:
  p1 = aes[n // 2 - 1]
  p2 = bs[n // 2]
  q1 = aes[n // 2]
  q2 = bs[n // 2 - 1]
  ans = (p2 - p1 + 1) + (q2- q1 + 1) - 1
 

print(ans)

Solution (Python):

import sys


def solve(N: int, A: "List[int]", B: "List[int]"):
    A.sort()
    B.sort(reverse=True)
    if N % 2 == 0:
        Xa1 = A[N // 2 - 1]
        Xa2 = A[N // 2]
        Xb1 = B[N // 2 - 1]
        Xb2 = B[N // 2]
        print(Xb2 + Xb1 - (Xa2 + Xa1) + 1)
    else:
        Xa = A[(N + 1) // 2 - 1]
        Xb = B[(N + 1) // 2 - 1]
        print(Xb - Xa + 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):
N = int(input())
A = []
B = []
for n 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:
    b = B[N//2]+B[N//2-1]
    a = A[N//2]+A[N//2-1]
    print (b-a+1)

Solution (Python):
N=int(input())
ls=[list(map(int,input().split())) for i in range(N)]
ls_a=sorted([ls[i][0] for i in range(N)])
ls_b=sorted([ls[i][1] for i in range(N)])
ls_b.reverse()

if N%2==1:
  print(ls_b[(N-1)//2]-ls_a[(N-1)//2]+1)
else:
  p=(ls_a[N//2-1]+ls_a[N//2])/2
  q=(ls_b[N//2-1]+ls_b[N//2])/2
  print(int((q-p)*2+1))

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

a_list.sort()
b_list.sort()

if n % 2 == 1:
    mid = (n+1)//2-1
    res = b_list[mid] - a_list[mid] + 1
else:
    mid_f = n//2-1
    mid_s = n//2
    max_sum = b_list[mid_s] + b_list[mid_f]
    min_sum = a_list[mid_s] + a_list[mid_f]
    res = max_sum - min_sum + 1

print(res)

Solution (Python):
n = int(input())
num = []


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

a = []
b = []
for i in range(n):
    a.append(num[i][0])
    b.append(num[i][1])

a.sort()
b.sort()

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

else:
    right = b[n//2]
    left = a[n//2]
    print(right - left + 1)

Solution (Python):
import sys
import math
from collections import deque

sys.setrecursionlimit(1000000)
MOD = 10 ** 9 + 7
input = lambda: sys.stdin.readline().strip()
NI = lambda: int(input())
NMI = lambda: map(int, input().split())
NLI = lambda: list(NMI())
SI = lambda: input()


def make_grid(h, w, num): return [[int(num)] * w for _ in range(h)]



def make_adjlist_d(n, edges):
    res = [[] for _ in range(n + 1)]
    for edge in edges:
        res[edge[0]].append(edge[1])
        res[edge[1]].append(edge[0])
    return res


def make_adjlist_nond(n, edges):
    res = [[] for _ in range(n + 1)]
    for edge in edges:
        res[edge[0]].append(edge[1])
    return res



def cmb(n, r):
    return math.factorial(n) // math.factorial(r) // math.factorial(n - r)


def main():
    N = NI()
    A = []
    B = []
    for i in range(N):
        a, b = NMI()
        A.append(a)
        B.append(b)
    A.sort()
    B.sort()

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

    ll = A[N//2-1]
    lr = A[N//2]
    rl = B[N//2-1]
    rr = B[N//2]
    l = (ll+lr)/2
    r = (rl+rr)/2
    gap = r-l
    print(int(gap*2+1))



if __name__ == "__main__":
    main()

Solution (Python):
n=int(input())
a=[0]*n
b=[0]*n
for i in range(n):
    a[i],b[i]=map(int,input().split())
    
a.sort()
b.sort()
if n%2==1:
    a_m = a[n//2]
    b_m = b[n//2]
    ans=max(b_m-a_m+1,0)
    print(ans)
else:
    a_m = (a[n//2]+a[n//2-1])
    b_m = (b[n//2]+b[n//2-1])
    ans = max(b_m-a_m+1,0)
    print(ans)

Solution (Python):
import sys

def input():
    return sys.stdin.readline()[:-1]
def main():
    N = int(input())
    L = [list(map(int,input().split())) for _ in range(N)]
    L = sorted(L)
    M = sorted(L,key=lambda x: x[1])
    if N%2 == 1:
        print(max(0,M[N//2][1]-L[N//2][0]+1))
    else:
        a = (L[N//2-1][0]+L[N//2][0])
        b = (M[N//2-1][1]+M[N//2][1])
        print(b-a+1)
if __name__ == '__main__':
    main()

Solution (Python):
import sys

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

def main():
    n = int(read())
    k = (n - 1) // 2
    ab = [[int(i) for i in read().split()] for _ in range(n)]
    a = sorted(a for a, _ in ab)
    b = sorted(b for _, b in ab)
    if n % 2:
        print(b[-1 - k] - a[k] + 1)
    else:
        i = a[k] + a[k + 1]
        j = b[-1 - k - 1] + b[-1 - k]
        print(j - i + 1)

if __name__ == '__main__':
    main()

Solution (Python):
import statistics as s

n = int(input())

minn = []
maxx = []

for i in range(0,n):
    temp = [int(x) for x in input().split()]

    minn.append(temp[0])
    maxx.append(temp[1])

a = s.median(minn)
b = s.median(maxx)

if n%2 == 1:
    print(int(b-a+1))
else:
    print(int(((b-a)/0.5)+1))

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

def main():
    n = int(input())
    low = []
    high = []

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

    low.sort()
    high.sort()

    if n%2 == 1:
        l = low[n//2]
        h = high[n//2]
    else:
        l = low[n//2 - 1] + low[n//2]
        h = high[n//2 - 1] + high[n//2]

    ans = h - l + 1

    print(ans)

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

Solution (Python):
n = int(input())
points = set()
A = []
B = []
for _ in range(n):
    a, b = map(int, input().split())
    if n % 2 == 0:
        a *= 2
        b *= 2
    A.append(a)
    B.append(b)


A.sort()
B.sort()

if n % 2 == 0:
    src = (A[n // 2 - 1] + A[n // 2]) // 2
    dst = (B[n // 2 - 1] + B[n // 2]) // 2
else:
    src = A[n // 2]
    dst = B[n // 2]

print(dst - src + 1)

Solution (Python):
n = int(input())
a_list = []
b_list = []
c_list = []
for _ in range(n):
    a, b = map(int, input().split())
    c_list.append([a, b])
    a_list.append(a)
    b_list.append(b)
a_list.sort()
b_list.sort()
if n % 2 == 1:
    ans = b_list[n // 2] - a_list[n // 2] + 1
else:
    ans_first_max = b_list[(n // 2) - 1]
    ans_first_min = a_list[(n // 2) - 1]
    ans_second_max = b_list[(n // 2)]
    ans_second_min = a_list[(n // 2)]
    ans = (ans_second_max + ans_first_max) - ((ans_second_min + ans_first_min)) + 1
print(ans)

Solution (Python):
n=int(input())
L=[list(map(int,input().split())) for i in range(n)]
minl=sorted([L[i][0] for i in range(n)])
maxl=sorted([L[i][1] for i in range(n)])
if n%2==1:
    mi=minl[n//2]
    ma=maxl[n//2]
    print(ma-mi+1)
else:
    mi=(minl[(n-1)//2]+minl[n//2])/2
    ma=(maxl[(n-1)//2]+maxl[n//2])/2
    print(int((ma-mi)//0.5+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:
    M = B[N // 2]
    m = A[N // 2]
    print(M - m + 1)

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

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

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

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

from decimal import Decimal
A = []
B = []
for _ in range(n):
    a, b = map(Decimal, input().split())
    A.append(a)
    B.append(b)



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



if n % 2 == 1:
    am = A[n // 2]
    bm = B[n // 2]
else:
    am = (A[n//2] + A[n//2-1]) / 2
    bm = (B[n//2] + B[n//2-1]) / 2



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