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):
from heapq import heappush, heappop, heapify
from collections import deque, defaultdict, Counter
import itertools
from itertools import permutations, combinations, accumulate, product, combinations_with_replacement
import sys
import bisect
import string
import math
import time


def I(): return int(input())
def S(): return input()
def MI(): return map(int, input().split())
def MS(): return map(str, input().split())
def LI(): return [int(i) for i in input().split()]
def LI_(): return [int(i)-1 for i in input().split()]
def StoI(): return [ord(i)-97 for i in input()]
def ItoS(nn): return chr(nn+97)
def input(): return sys.stdin.readline().rstrip()
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 print_matrix(mat):
    for i in range(len(mat)):
        print(*['IINF' if v == IINF else "{:0=4}".format(v) for v in mat[i]])


yn = {False: 'No', True: 'Yes'}
YN = {False: 'NO', True: 'YES'}
MOD = 10**9+7
inf = float('inf')
IINF = 10**19
l_alp = string.ascii_lowercase
u_alp = string.ascii_uppercase
ts = time.time()
sys.setrecursionlimit(10**6)
nums = ['1', '2', '3', '4', '5', '6', '7', '8', '9', '10']
show_flg = False


def gcd(a, b):
    if b == 0:
        return a
    return gcd(b, a % b)


def main():
    N = I()
    A = []
    B = []
    ans = 0

    for i in range(N):
        a, b = MI()
        A.append(a)
        B.append(b)

    A.sort()
    B.sort()

    if N % 2 == 1:
        mid = N // 2
        print(B[mid] - A[mid] + 1)
    else:
        mid1 = N // 2
        mid2 = mid1 - 1
        r = B[mid1] + B[mid2]
        l = A[mid1] + A[mid2]
        print(r - l + 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()

i = N//2
if N%2 == 0:
    print(B[i]+B[i-1]-A[i]-A[i-1]+1)
else:
    print(B[i]-A[i]+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(abs(A[N//2]-B[N//2])+1)
else:
    a_median = (A[N//2] + A[(N//2)-1])/2
    b_median = (B[N//2] + B[(N//2)-1])/2
    print(int(abs(a_median-b_median)*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:
    r = (B[N//2-1]+B[N//2])
    l = (A[N//2-1]+A[N//2])
    print(r-l+1)

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

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

if n%2==1:
    sa = A[n//2]
    lb = B[n//2]
    print(lb - sa + 1)
else:
    sal = A[n//2-1]
    sar = A[n//2]

    lbl = B[n//2-1]
    lbr = B[n//2]
    print((lbl + lbr) - (sal + sar) +1)

Solution (Python):
import numpy as np
def LI():
    return list(map(int, input().split()))

n = int(input())
ab = [LI() for _ in range(n)]
ab = np.array(ab)

def main():
    if n % 2 == 0:
        mi = np.median(ab[:, 0])
        ma = np.median(ab[:, 1]) + 0.5
        ans = (ma - mi) // 0.5
    else:
        mi = np.median(ab[:, 0])
        ma = np.median(ab[:, 1]) + 1
        ans = ma - mi
    print(int(ans))

if __name__ == "__main__":
    main()

Solution (Python):
n = int( input() )
A = []
B = []

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

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

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

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

Solution (Python):
N = int(input())
AB = [list(map(int, input().split())) for _ in range(N)]
A = sorted([ab[0]*(2-N%2) for ab in AB])
B = sorted([ab[1]*(2-N%2) for ab in AB])
if N%2 == 1:
  print(B[N//2]-A[N//2]+1)
else:
  print((B[N//2]+B[N//2-1])//2-(A[N//2]+A[N//2-1])//2+1)

Solution (Python):
from statistics import median

N=int(input())
A=[]
B=[]
for _ in range(N):
    a,b=map(int,input().split())
    A.append(a)
    B.append(b)
median_a=median(A)
median_b=median(B)
if N%2==0:
    print(int((median_b-median_a)*2)+1)
else:
    print(int(median_b-median_a)+1)

Solution (Python):
N=int(input())
A=[0 for _ in range(N)]
B=[0 for _ in range(N)]
for i in range(N):
  a,b=[int(s) for s in input().split()]
  A[i]=a
  B[i]=b
A.sort()
B.sort()
def doublemed(ls,num):
  if num%2==0:
    return(ls[num//2-1]+ls[num//2])
  else:
    return(ls[num//2])
meda=doublemed(A,N)
medb=doublemed(B,N)
print(medb-meda+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:
    ans = B[N//2] - A[N//2]+1
    print(ans)
else:
    vmin = A[N//2]+A[N//2-1]
    vmax = B[N//2]+B[N//2-1]
    ans = vmax-vmin+1
    print(ans)

Solution (Python):
import statistics

N = int(input())
AList = []
BList = []
for i in range(N):
    A, B = map(int, input().split())
    AList.append(A)
    BList.append(B)
    
Amid = statistics.median(AList)
Bmid = statistics.median(BList)

if N % 2 != 0:
    result = int(Bmid - Amid + 1)
else:
    result = int((Bmid - Amid) * 2 + 1)

print(result)

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

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

ans = 0
if n % 2 == 0:
    l = a[n//2-1] + a[n//2]
    h = b[n//2-1] + b[n//2]

    ans += h - l + 1
else:
    l = a[n//2]
    h = b[n//2]

    ans += h - l + 1



print(ans)

Solution (Python):
from functools import reduce
from fractions import gcd
import math
import bisect
import itertools
import sys
sys.setrecursionlimit(10**7)
input = sys.stdin.readline
INF = float("inf")



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


if __name__ == '__main__':
    main()

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

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

aList.sort()
bList.sort()


if not n % 2 == 0:
    half = (n+1) // 2 - 1
    print(bList[half] - aList[half] + 1)
else:
    half = (n) // 2 - 1
    print(bList[half] + bList[half+1] - (aList[half] + aList[half+1]) + 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_a = A[(N + 1) // 2 - 1]
    mid_b = B[(N + 1) // 2 - 1]
    print(mid_b - mid_a + 1)
else:
    mid_a = (A[N // 2 - 1] + A[N // 2]) / 2
    mid_b = (B[N // 2 - 1] + B[N // 2]) / 2
    print(int((mid_b - mid_a) * 2) + 1)

Solution (Python):
import sys
INF = 1 << 60
MOD = 10**9 + 7 
sys.setrecursionlimit(2147483647)
input = lambda:sys.stdin.readline().rstrip()
def resolve():
    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()
    k = n // 2

    if n & 1:
        print(B[k] - A[k] + 1)
    else:
        print((B[k] + B[k - 1]) - (A[k] + A[k - 1]) + 1)
resolve()

Solution (Python):
import math

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

mid_a = A[(N + 1) // 2 - 1] if N % 2 == 1 else (A[N // 2 - 1] + A[N // 2]) / 2
mid_b = B[(N + 1) // 2 - 1] if N % 2 == 1 else (B[N // 2 - 1] + B[N // 2]) / 2











ans = (mid_b - mid_a + 1) if N % 2 == 1 else int((mid_b - mid_a) * 2) + 1
print(ans)

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

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

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

Solution (Python):
from statistics import median
N=int(input())
A,B=[],[]
for i in range(N):
    a,b=map(int,input().split())
    A.append(a);B.append(b)
mA=median(A);mB=median(B)
if N%2:
    ans=int(mB-mA)+1
else:
    if mA//1==mA and mB//1==mB:
        ans=int(mB-mA)*2+1
    elif mA//1!=mA and mB//1==mB:
        ans=(mB-(mA//1))*2
    elif mA//1==mA and mB//1!=mB:
        ans=((mB//1+1)-mA)*2
    else:
        ans=int(mB-mA)*2+1
print(int(ans))

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

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

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

Solution (Python):
from sys import stdin
from decimal import Decimal
N = int(stdin.readline().rstrip())
A = []
B = []
for i in range(N):
    a,b = [int(x) for x in stdin.readline().rstrip().split()]
    A.append(a)
    B.append(b)
    
A.sort()
B.sort()

if N % 2 == 0:
    n = N // 2
    med1 = A[n-1] + A[n]
    med2 = B[n-1] + B[n]
    print(med2-med1+1)
else:
    ans = B[N//2] - A[N//2] + 1
    print(ans)

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

nums = [[0, 0] for _ in range(n)]

for i in range(n):
  nums[i][0], nums[i][1] = map(int, input().split())
  
if n % 2 == 0:
  
  nums.sort(key=lambda x: x[0])
  a = (nums[(n+1)//2 - 1][0] + nums[(n+1)//2][0]) / 2
  nums.sort(key=lambda x: x[1])
  b = (nums[(n+1)//2 - 1][1] + nums[(n+1)//2][1]) / 2
  print(int((b-a) * 2 + 1))
  
else:
  
  nums.sort(key=lambda x: x[0])
  a = nums[(n+1)//2 - 1][0]
  nums.sort(key=lambda x: x[1])
  b = nums[(n+1)//2 - 1][1]
  print(b-a + 1)

Solution (Python):
n=int(input())
a=[];b=[]
for _ in range(n):
    ai,bi=map(int, input().split())
    a.append(ai);b.append(bi)
a.sort()
b.sort()
ma=0;mb=0
if n%2:
    ma=a[n//2]
    mb=b[n//2]
    
else:
    ma=a[n//2]+a[n//2-1]
    mb=b[n//2]+b[n//2-1]
print(mb-ma+1)

Solution (Python):
import sys

sys.setrecursionlimit(10 ** 7)
rl = sys.stdin.readline


def solve():
    N = int(rl())
    A, B = [0] * N, [0] * N
    for i in range(N):
        A[i], B[i] = map(int, rl().split())
    
    A.sort()
    B.sort()
    
    if N % 2 == 0:
        med_a = (A[N // 2 - 1] + A[N // 2]) / 2
        med_b = (B[N // 2 - 1] + B[N // 2]) / 2
        ans = int((med_b - med_a) // 0.5 + 1)
    else:
        med_a = A[N // 2]
        med_b = B[N // 2]
        ans = med_b - med_a + 1
    print(ans)


if __name__ == '__main__':
    solve()

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:
        u = a[N//2-1] + a[N//2]
        v = b[N//2-1] + b[N//2]
        return max((v-u)+1, 0)
    else:
        u = a[(N)//2]
        v = b[(N)//2]
        return max(v-u+1, 0)

if __name__ == '__main__':
    print(main())

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

import numpy as np

n = int(readline())
ab = np.array(read().split(), np.int64)
a = ab[::2]
b = ab[1::2]

a.sort()
b.sort()

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

else:
    i1, i2 = n // 2 - 1, n // 2
    a *= 2
    b *= 2
    mn = (a[i1] + a[i2]) // 2
    mx = (b[i1] + b[i2]) // 2
    ans = mx - mn + 1

print(ans)

Solution (Python):
ma = lambda :map(int,input().split())
ni = lambda:int(input())
import collections
import math
import itertools
gcd = math.gcd
n = ni()
A = []
B = []
for i in range(n):
    a,b = ma()
    A.append(a)
    B.append(b)
A.sort()
B.sort(reverse=True)
if n%2==1:
    mi = A[n//2]
    ma = B[n//2]
    print(ma-mi+1)
else:
    mi = A[(n-1)//2] + A[n//2]
    ma = B[(n-1)//2] + B[n//2]
    print(ma-mi+1)

Solution (Python):
import sys
input = lambda:sys.stdin.readline().strip()
n = int(input())
a = [0]
b = [0]
for i in range(n):
    ai,bi = map(int,input().split())
    a.append(ai)
    b.append(bi)
a.sort()
b.sort()
if n&1:
    print(b[(n+1)//2]-a[(n+1)//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 _ in range(n):
    x, y = map(int, input().split())
    a.append(x)
    b.append(y)

a.sort()
b.sort()

x, y = 0, 0

if n % 2 == 1:
    x = b[n//2]
    y = a[n//2]
else:
    x = b[n//2] + b[n//2-1]
    y = a[n//2] + a[n//2-1]

print(x-y+1)

Solution (Python):

import sys

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


def main():
    n = ni()
    bo = []
    up = []
    for _ in range(n):
        a,b = na()
        bo += [a]
        up += [b]
    bo.sort()
    up.sort()
    
    if n%2 == 1:
        print(up[n//2] - bo[n//2] + 1)
    else:
        pre_b, pre_u = bo[n//2 - 1], up[n//2 - 1]
        nex_b, nex_u = bo[n//2], up[n//2]
        print((pre_u+nex_u) - (pre_b+nex_b) + 1)
    return


if __name__ == '__main__':
    main()

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

a.sort()
b.sort()
if n % 2 == 1:
    l = a[n // 2]
    r = b[n // 2]
    print(r - l + 1)
else:
    l1, l2 = a[n // 2 - 1], a[n // 2]
    r1, r2 = b[n // 2 - 1], b[n // 2]
    print((r1 + r2) - (l1 + l2) + 1)

Solution (Python):
import statistics

N = int(input())



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

low = statistics.median(AB[0])
high = statistics.median(AB[1])

if len(AB[0])%2 ==0:
    print(int(2*(high-low)+1))
else:
    print(high-low+1)

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

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

A = []
B = []
for a, b in ab:
    A.append(a)
    B.append(b)

A.sort()
B.sort()

if N % 2 == 0:
    a1 = A[N // 2 - 1]
    b1 = B[N // 2 - 1]
    a2 = A[N // 2]
    b2 = B[N // 2]
    xa = (a2 + a1) / 2
    xb = (b2 + b1) / 2
    print(int((xb - xa) * 2 + 1))
else:
    xa = A[N // 2]
    xb = B[N // 2]
    print(xb - xa + 1)

Solution (Python):
from operator import itemgetter

n = int(input())
info = [list(map(int, input().split())) for i in range(n)]
a = [info[i][0] for i in range(n)]
b = [info[i][1] for i in range(n)]

a = sorted(a)
b = sorted(b)
if n % 2 == 1:
    l = a[n // 2]
    r = b[n // 2]
    print(r - l + 1)
else:
    l1, l2 = a[n // 2 - 1], a[n // 2]
    r1, r2 = b[n // 2 - 1], b[n // 2]
    print((r1 + r2) - (l1 + l2) + 1)

Solution (Python):
n = int(input())
lower, upper = [], []
for _ in range(n):
    a, b = map(int, input().split())
    lower.append(a)
    upper.append(b)
lower.sort()
upper.sort()
if n % 2 == 1:
    mid = n // 2
    median_min = lower[mid]
    median_max = upper[mid]
else:
    mid = n // 2 - 1
    median_min = lower[mid] + lower[mid + 1]
    median_max = upper[mid] + upper[mid + 1]
print(median_max - median_min + 1)

Solution (Python):
lower, upper = [], []
n = int(input())
for _ in range(n):
    a, b = map(int, input().split())
    lower.append(a)
    upper.append(b)
lower.sort()
upper.sort(reverse=True)
if n % 2 == 1:
    mid = n // 2
    median_min = lower[mid]
    median_max = upper[mid]
else:
    mid = n // 2 - 1
    median_min = lower[mid] + lower[mid + 1]
    median_max = upper[mid] + upper[mid + 1]
print(median_max - median_min + 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 )

if n % 2 == 0:
  i1 = n // 2 - 1
  i2 = n // 2
  print( B[ i2 ] + B[ i1 ] - ( A[ i2 ] + A[ i1 ] ) + 1 )
else:
  i = ( n + 1 ) // 2 - 1
  print( B[ i ] - A[ i ] + 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:
    ans = B[N//2] - A[N//2] + 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
input = sys.stdin.readline

def solve():
    N = int(input())
    ABs = [tuple(map(int, input().split())) for _ in range(N)]

    def isOK_LE(X, thre):
        num = 0
        for A, B in ABs:
            if A <= X:
                num += 1
        return num >= thre

    def isOK_GE(X, thre):
        num = 0
        for A, B in ABs:
            if X <= B:
                num += 1
        return num >= thre

    def binS_LE(isOK, thre):
        ng, ok = 0, 10**9+1
        while abs(ok-ng) > 1:
            mid = (ng+ok) // 2
            if isOK(mid, thre):
                ok = mid
            else:
                ng = mid
        return ok

    def binS_GE(isOK, thre):
        ng, ok = 10**9+1, 0
        while abs(ok-ng) > 1:
            mid = (ng+ok) // 2
            if isOK(mid, thre):
                ok = mid
            else:
                ng = mid
        return ok

    if N % 2:
        num = (N+1)//2
        mn = binS_LE(isOK_LE, num)
        mx = binS_GE(isOK_GE, num)


        return mx-mn+1
    else:
        num = N//2
        mn1 = binS_LE(isOK_LE, num)
        mx1 = binS_GE(isOK_GE, num+1)
        mn2 = binS_LE(isOK_LE, num+1)
        mx2 = binS_GE(isOK_GE, num)


        mn = mn1+mn2
        mx = mx1+mx2


        return mx-mn+1


ans = solve()
print(ans)

Solution (Python):
arr = []
a,b = [],[]
for _ in range(int(input())):
    x,y = list(map(int,input().split()))
    a.append(x)
    b.append(y)
a.sort()
b.sort()
n = len(a)
if n%2!=0:
    x = n//2
    print(b[x]-a[x]+1)
else:
    x = n//2
    y = x-1
    a1 = (a[x]+a[y])/2
    b1 = (b[x]+b[y])/2
    ans = (b1-a1)/0.5
    print(int(ans)+1)

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

if n % 2 == 1:
    ab.sort(reverse=True,key=lambda x: x[1])
    max_ab = ab[n//2][1]
    ab.sort(reverse=True,key=lambda x: x[0])
    print(max_ab-ab[n//2][0]+1)
else:
    ab.sort(reverse=True,key=lambda x: x[1])
    ab1 = ab[n//2][1]
    ab2 = ab[n//2-1][1]
    ab.sort(key=lambda x: x[0])
    ab3 = ab[n//2][0]
    ab4 = ab[n//2-1][0]
    
    print(ab1+ab2-(ab3+ab4)+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()

def median(li):
    if n%2==1:
        return li[n//2]
    else:
        return sum(li[n//2-1:n//2+1])
print(median(B)-median(A)+1)

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

Solution (Python):
N = int(input())
A = [0]*N
B = [0]*N
for i in range(N):
    A_in, B_in = map(int, input().split())
    A[i] = A_in
    B[i] = B_in


A.sort()
B.sort()
if N % 2 == 1:
    print(B[(N+1)//2 - 1] - A[(N+1)//2 - 1] + 1)
else:
    d_B_med = (B[N//2 - 1] + B[N//2])
    d_A_med = (A[N//2 - 1] + A[N//2])
    print(d_B_med - d_A_med + 1)

Solution (Python):
from sys import stdin
input = stdin.readline
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()
if N%2 == 0:
    temp = N//2
    m = (A[temp]+A[temp-1])/2
    M = (B[temp]+B[temp-1])/2
    print(int((M-m+1/2)//(1/2)))
else:
    temp = N//2
    print(B[temp]-A[temp]+1)

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

def mid(AB, idx):
    if N % 2 == 0:
        return (AB[N//2-1][idx] + AB[N//2][idx]) / 2
    else:
        return AB[(N+1)//2-1][idx]

AB.sort()
amid = mid(AB, 0)
AB.sort(key=lambda x: x[1])
bmid = mid(AB, 1)
tmp = 1 if N % 2 == 1 else 2
print(int(tmp * (bmid - amid) + 1))

Solution (Python):

N = int(input())
mins, maxs = [], []
for i in range(N):
    a, b = map(int, input().split())
    mins.append(a)
    maxs.append(b)
mins.sort()
maxs.sort()
if N % 2 == 0:
    mincn = (mins[N//2-1] + mins[N//2])
    maxcn = (maxs[N//2-1] + maxs[N//2])
else:
    mincn = mins[N//2]
    maxcn = maxs[N//2]
print(maxcn - mincn + 1)

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

Solution (Python):
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_list.sort()
b_list.sort()

a_m = a_list[N // 2 - 1] + a_list[N // 2] if N % 2 == 0 else a_list[(N + 1) // 2 - 1]
b_m = b_list[N // 2 - 1] + b_list[N // 2] if N % 2 == 0 else b_list[(N + 1) // 2 - 1]
a_m /= 2
b_m /= 2

print(int((b_m - a_m) / 0.5) + 1)

Solution (Python):
n = int(input())
lister = []
for i in range(n):
    lister.append([int(i) for i in input().split()])
 
if n % 2 == 1:
    lister.sort(key=lambda x:x[0])
    miner = lister[n//2][0]
    lister.sort(key=lambda x:x[1])
    maxer = lister[n//2][1]
    print(maxer- miner + 1)
else:
    lister.sort(key=lambda x:x[0])
    miner = lister[n//2 - 1][0]
    miner += lister[n//2][0]
    lister.sort(key=lambda x:x[1])
    maxer = lister[n//2][1]
    maxer += lister[n//2 - 1][1]
    print(1 + (maxer- miner))

Solution (Python):


n = int(input())
a_list = []
b_list = []
for i in range(0, 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:
    x1 = n // 2 - 1
    x2 = n // 2
    print(b_list[x2] - a_list[x2] + b_list[x1] - a_list[x1] + 1)
else:
    x = n // 2
    print(b_list[x] - a_list[x] + 1)

Solution (Python):
import numpy as np
N = int(input())
A = np.zeros(N)
B = np.zeros(N)
for i in range(N):
    A[i], B[i] = map(int, input().split())

am = np.median(A)
bm = np.median(B)

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

Solution (Python):
n = int(input())
x =[]
y =[]
for i in range(n):
    a, b = map(int,input().split())
    x.append(a)
    y.append(b)
x =sorted(x)
y =sorted(y,reverse = True)

ans = 0
if n %2 == 0:
    m = n //2 -1
    ans = y[m] + y[m+1]-x[m]-x[m+1] +1
    print(ans)
    exit()
else:
    m = n//2
    ans = y[m] - x[m] + 1
    print(ans)
    exit()

Solution (Python):
import sys
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines
sys.setrecursionlimit(10 ** 7)

n = int(readline())
aa = []
bb = []
for _ in range(n):
    a, b = map(int, readline().split())
    aa.append(a)
    bb.append(b)
aa.sort()
bb.sort()
if n % 2 == 1:
    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):
from math import *
from statistics import median
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:
    ans=B[(N+1)//2-1]-A[(N+1)//2-1]+1
else:
    ans=1+((B[N//2-1]+B[N//2]))-((A[N//2-1]+A[N//2]))
print(ans)

Solution (Python):
import sys
import math
from collections import defaultdict
from bisect import bisect_left, bisect_right

sys.setrecursionlimit(10**7)
def input():
    return sys.stdin.readline()[:-1]

mod = 10**9 + 7

def I(): return int(input())
def LI(): return list(map(int, input().split()))
def LIR(row,col):
    if row <= 0:
        return [[] for _ in range(col)]
    elif col == 1:
        return [I() for _ in range(row)]
    else:
        read_all = [LI() for _ in range(row)]
        return map(list, zip(*read_all))



N = I()
A,B = LIR(N,2)
A.sort()
B.sort()

if N%2 == 1:
    min_ = A[(N-1)//2]
    max_ = B[(N-1)//2]
    print(max_-min_+1)
else:
    smin_ = A[N//2-1]+A[N//2]
    smax_ = B[N//2-1]+B[N//2]
    print(smax_-smin_+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()

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

Solution (Python):
n = int(input())
a = []
b = []
for i in range(n):
    x, y = map(int, input().split())
    a.append([x, y])
    b.append([y, x])
a = sorted(a)
b = sorted(b, reverse = True)

if n % 2 ==0:
    s = a[n//2 -1][0]
    e = b[n//2 -1][0]
    s2 = a[n//2][0]
    e2 = b[n//2][0]
    ans = e+ e2 -s-s2+1   
else:
    s = a[(n+1)//2 -1][0]
    e = b[(n+1)//2 -1][0]
    ans = e-s+1
print(ans)

Solution (Python):
import heapq as hp
n = int(input())
if n%2 ==0:
    m = n//2 + 1
else:
    m = (n+1) //2
a,b = [],[]
for i in range(0,n):
    c = list(map(int, input().split()))
    a.append(c[0])
    b.append(c[1])
la = hp.nlargest(m,a)
lb = hp.nlargest(m,b)
if n%2 == 0:
    c = la[-1] + la[-2] 
    d = lb[-1] + lb[-2] 
    print(d-c+1)
else:
    print(lb[-1]-la[-1]+1)

Solution (Python):
import sys
import math
import heapq
sys.setrecursionlimit(10**7)
INTMAX = 9223372036854775807
INTMIN = -9223372036854775808
DVSR = 1000000007
def POW(x, y): return pow(x, y, DVSR)
def INV(x, m=DVSR): return pow(x, m - 2, m)
def DIV(x, y, m=DVSR): return (x * INV(y, m)) % m
def LI(): return [int(x) for x in sys.stdin.readline().split()]
def LF(): return [float(x) for x in sys.stdin.readline().split()]
def LS(): return sys.stdin.readline().split()
def II(): return int(sys.stdin.readline())
def FLIST(n):
    res = [1]
    for i in range(1, n+1): res.append(res[i-1]*i%DVSR)
    return res

N=II()
AS=[]
BS=[]
for i in range(N):
    A,B=LI()
    AS.append(A)
    BS.append(B)
AS.sort()
BS.sort()
if N % 2:
    print(BS[N//2]-AS[N//2]+1)
else:
    print((BS[N//2]+BS[N//2-1]-(AS[N//2]+AS[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()

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

Solution (Python):
def main():
    import sys
    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)
    if n%2 == 0:
        ma = (A[n//2]+A[n//2-1])/2
        mb = (B[n//2]+B[n//2-1])/2
        ans = int(2*(mb-ma) + 1)
        print(ans)
    else:
        ma = A[n//2]
        mb = B[n//2]
        ans = (mb-ma) + 1
        print(ans)
        
        
if __name__ == '__main__':
    main()

Solution (Python):
import sys
sys.setrecursionlimit(10**7)

readline = sys.stdin.buffer.readline
def readstr():return readline().rstrip().decode()
def readstrs():return list(readline().decode().split())
def readint():return int(readline())
def readints():return list(map(int,readline().split()))
def printrows(x):print('\n'.join(map(str,x)))
def printline(x):print(' '.join(map(str,x)))


n = readint()
a = []
b = []
for i in range(n):
    x,y = readints()
    a.append(x)
    b.append(y)
a.sort()
b.sort()

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

Solution (Python):
def median(array):
    if N % 2:
        return array[N // 2]
    else:
        return sum(array[N // 2 - 1: N // 2 + 1])


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()
x = median(A)
y = median(B)
print(y - x + 1)

Solution (Python):
import math


def median(array):
    if N % 2:
        return array[N // 2]
    else:
        return sum(array[N // 2 - 1: N // 2 + 1])


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()
x = median(A)
y = median(B)
print(y - x + 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:
    sca=scb=N//2-1
    lca=lcb=N//2
    x=A[lca]+A[sca]
    y=B[lcb]+B[scb]
    print(y-x+1)
    
    
else:
    ca=cb=N//2
    ans=B[cb]-A[ca]+1
    print(ans)

Solution (Python):
import sys

read = sys.stdin.read
readline = sys.stdin.readline
readlines = sys.stdin.readlines
sys.setrecursionlimit(10 ** 9)
INF = 1 << 60


def main():
    N, *AB = map(int, read().split())
    A = AB[::2]
    B = AB[1::2]

    if N % 2 == 0:
        A = [a * 2 for a in A]
        B = [b * 2 for b in B]

    A.sort()
    B.sort()

    medA = (A[(N - 1) // 2] + A[N // 2]) // 2
    medB = (B[(N - 1) // 2] + B[N // 2]) // 2

    ans = medB - medA + 1
    print(ans)

    return


if __name__ == '__main__':
    main()

Solution (Python):
n, *AB = map(int, open(0).read().split())
A, B = map(sorted, [AB[::2], AB[1::2]])
mid = n//2
a = A[mid]
b = B[mid]
if n % 2 == 0:
    a += A[mid-1]
    b += B[mid-1]
print(b-a+1)