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 statistics import median


def main():
    N = int(input())
    A = [None] * N
    B = [None] * N
    for i in range(N):
        A[i], B[i] = map(int, input().split())
    min_median = median(A)
    max_median = median(B)
    if N % 2 == 1:
        print(max_median - min_median + 1)
    else:
        print(round((max_median-min_median)*2)+1)


if __name__ == "__main__":
    main()

Solution (Python):
def main():
    N = int(input())
    A = [None] * N
    B = [None] * N
    for i in range(N):
        A[i], B[i] = map(int, input().split())
    A.sort()
    B.sort()
    if N % 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)


if __name__ == "__main__":
    main()

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

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

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

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

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


if n%2==1:
    med1 = ab[n//2]
    amin=med1[0]
else:
    med1 = ab[(n-1)//2]
    med2 = ab[(n-1)//2+1]
    amin = (med1[0] + med2[0])

ab.sort(key=lambda x: x[1])


if n%2==1:
    med1 = ab[n//2]
    amax=med1[1]
else:
    med1 = ab[(n-1)//2]
    med2 = ab[(n-1)//2+1]
    amax = (med1[1] + med2[1])

if n%2==1:
    print(amax-amin+1)
else:
    print(amax - amin + 1)

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

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

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

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

Solution (Python):
n = int(input())
minnums = [[] for _ in range(n)]
maxnums = [[] for _ in range(n)]

for i in range(n):
  minnums[i], maxnums[i] = map(int, input().split())
  
minnums.sort()
maxnums.sort()

if n % 2:
  minmedian = minnums[n // 2]
  maxmedian = maxnums[n // 2]
  print(maxmedian - minmedian + 1)
else:
  minmedian = (minnums[n // 2 - 1] + minnums[n // 2]) / 2
  maxmedian = (maxnums[n // 2 - 1] + maxnums[n // 2]) / 2
  print(int((maxmedian - minmedian) * 2 + 1))

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

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

if N % 2 == 1:
    i = N // 2
    AB.sort()
    L = AB[i][0]
    AB.sort(key=lambda x: x[1])
    R = AB[i][1]
    ans = R - L + 1
else:
    i = N // 2 - 1
    j = i + 1
    AB.sort()
    L = AB[i][0] + AB[j][0]
    AB.sort(key=lambda x: x[1])
    R = AB[i][1] + AB[j][1]
    ans = R - L + 1

print(ans)

Solution (Python):
from collections import deque
from heapq import heapify,heappop,heappush,heappushpop
from copy import copy,deepcopy
from itertools import product,permutations,combinations,combinations_with_replacement
from collections import defaultdict,Counter
from bisect import bisect_left,bisect_right


from functools import reduce
from pprint import pprint
from statistics import median

INF = float("inf")

def mycol(data,col):
    return [ row[col] for row in data ]

def mysort(data,col,reverse_flag):
    data.sort(key=lambda x:x[col],reverse=reverse_flag)
    return data

def mymax(data):
    M = -1*float("inf")
    for i in range(len(data)):
        m = max(data[i])
        M = max(M,m)
    return M

def mymin(data):
    m = float("inf")
    for i in range(len(data)):
        M = min(data[i])
        m = min(m,M)
    return m

def mycount(ls,x):
    
    l = bisect_left(ls,x)
    r = bisect_right(ls,x)
    return (r-l)

def myoutput(ls,space=True):
    if space:
        if len(ls)==0:
            print(" ")
        elif type(ls[0])==str:
            print(" ".join(ls))
        elif type(ls[0])==int:
            print(" ".join(map(str,ls)))
        else:
            print("Output Error")
    else:
        if len(ls)==0:
            print("")
        elif type(ls[0])==str:
            print("".join(ls))
        elif type(ls[0])==int:
            print("".join(map(str,ls)))
        else:
            print("Output Error")

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

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

def RI():
    return list(map(int,input().split()))

def CI(n):
    return [ int(input()) for _ in range(n) ]

def LI(n):
    return [ list(map(int,input().split())) for _ in range(n) ]

def S():
    return input()

def MS():
    return input().split()

def RS():
    return list(input().split())

def CS(n):
    return [ input() for _ in range(n) ]

def LS(n):
    return [ list(input().split()) for _ in range(n) ]

n = I()
ab = LI(n)

a = mycol(ab,0)
ma = median(a)

b = mycol(ab,1)
mb = median(b)

if n%2==1:
    ans = mb - ma + 1
else:
    ans = (mb-ma)*2 + 1
print(int(ans))

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

    if N % 2 == 0:
        tmp = (B[N//2]+B[N//2-1])/2 - (A[N//2]+A[N//2-1])/2
        print(int(tmp / 0.5)+1)
    else:
        print(B[N//2] - A[N//2] + 1)
    
if __name__ == '__main__':
    solve()

Solution (Python):

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

a.sort()
b.sort()
    
if n%2==0:
    n2=n//2
    ca=(a[n2-1]+a[n2])
    cb=(b[n2-1]+b[n2])
    c=cb-ca+1
else:
    n2=(n-1)//2
    ca=a[n2]
    cb=b[n2]
    c=cb-ca+1
    
print(c)

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

Solution (Python):
n = int(input())
ab = [tuple(map(int, input().split())) for _ in range(n)]
a, b = map(list, zip(*ab))
a.sort()
b.sort(reverse=True)
a1, b1 = a[n//2], b[n//2]
a2, b2 = a[n//2-1], b[n//2-1]
if n % 2: print(b1 - a1 + 1)
else: print((b1+b2) - (a1+a2) + 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))

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

A, B = [], []

a, b = None, None

sum = [0 for i in range(N)]

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

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

a.sort()
b.sort()
if n%2==1:
  print(b[n//2]-a[n//2]+1)
else:
  a_cnt=a[n//2]+a[n//2-1]
  b_cnt=b[n//2]+b[n//2-1]
  print(b_cnt-a_cnt+1)

Solution (Python):
import math,string,itertools,fractions,heapq,collections,re,array,bisect,sys,copy,functools
import time,random

sys.setrecursionlimit(10**7)
inf = 10**20
eps = 1.0 / 10**10
mod = 10**9+7
mod2 = 998244353
dd = [(-1,0),(0,1),(1,0),(0,-1)]
ddn = [(-1,0),(-1,1),(0,1),(1,1),(1,0),(1,-1),(0,-1),(-1,-1)]

def LI(): return list(map(int, sys.stdin.readline().split()))
def LLI(): return [list(map(int, l.split())) for l in sys.stdin.readlines()]
def LI_(): return [int(x)-1 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 I(): return int(sys.stdin.readline())
def F(): return float(sys.stdin.readline())
def S(): return input()
def pf(s): return print(s, flush=True)
def pe(s): return print(str(s), file=sys.stderr)
def JA(a, sep): return sep.join(map(str, a))
def JAA(a, s, t): return s.join(t.join(map(str, b)) for b in a)


def main():
    n = I()
    ab = [LI() for _ in range(n)]
    aa = sorted(map(lambda x: x[0], ab))
    ba = sorted(map(lambda x: x[1], ab))

    if n % 2 == 1:
        a = aa[n//2]
        b = ba[n//2]
        return b - a + 1
    a1 = aa[n//2-1]
    a2 = aa[n//2]
    b1 = ba[n//2-1]
    b2 = ba[n//2]

    r = b2 - a2
    r += b1 - a1

    return r + 1

print(main())

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&1:
    print(b[n//2]-a[n//2]+1)
else:
    print(1+(b[n//2]+b[(n-1)//2])-(a[n//2]+a[(n-1)//2]))

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

x = np.median(A)
y = np.median(B)
if n%2==0:
    print(int((y-x)/0.5+1))
else:
    print(int(y-x+1))

Solution (Python):
import statistics
import math

n = int(input())
aa,bb = [],[]

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

Solution (Python):
import sys

input = lambda: sys.stdin.readline().rstrip()

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

l = list(map(lambda x: x[0], arr))
h = list(map(lambda x: x[1], arr))
l.sort()
h.sort()

ml = l[N // 2] if N & 1 else (l[N // 2 - 1] + l[N // 2])
mh = h[N // 2] if N & 1 else (h[N // 2 - 1] + h[N // 2])

print(mh - ml + 1)

Solution (Python):
n = int(input())
ab = [map(int, input().split()) for _ in range(n)]
a, b = [list(i) for i in zip(*ab)]
c = sorted(a)
d = sorted(b)

ans = 0
if n % 2 == 1:
    ans = d[(n-1)//2] - c[(n-1)//2] + 1
else:
    ans = d[n//2] + d[n//2 - 1] - c[n//2] - c[n//2 - 1] + 1

print(ans)

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

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

Solution (Python):
from statistics import median
N = int(input())
A, B = zip(*tuple(tuple(map(int, input().split())) for _ in range(N)))
print(int((median(B) - median(A)) * (1 + (not N & 1))) + 1)

Solution (Python):
n=int(input())
arr1=[]
arr2=[]
for _ in range(n):
  a,b=map(int,input().split())
  arr1.append(a)
  arr2.append(b)
arr1=sorted(arr1)
arr2=sorted(arr2)
if n%2==1:
  l=arr1[n//2]
  r=arr2[n//2]
else:
  l=arr1[n//2-1]+arr1[n//2]
  r=arr2[n//2-1]+arr2[n//2]
print(r-l+1)

Solution (Python):
import numpy as np

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

for _ in range(n):
    a, b = map(int, input().split())
    A.append(a if n % 2 == 1 else a * 2)  
    B.append(b if n % 2 == 1 else b * 2)

a = np.median(A)
b = np.median(B)


print(int(max(a, b) - min(a, b) + 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:
    print(B[n//2] + B[n//2-1] - A[n//2] - A[n//2-1] + 1)
else:
    print(B[(n-1)//2] - A[(n-1)//2] + 1)

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

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


if n % 2 == 0:
    left = a_line[n // 2 - 1] + a_line[n // 2]
    right = b_line[n // 2 - 1] + b_line[n // 2]
    print(right - left + 1)
else:
    print(b_line[n // 2] - a_line[n // 2] + 1)

Solution (Python):
import sys
import itertools

import time

sys.setrecursionlimit(10 ** 7)

from collections import defaultdict

read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines

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

a = sorted(a)
b = sorted(b)

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

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

a = [_ab[0] for _ab in ab]
b = [_ab[1] for _ab in ab]
a.sort()
b.sort()

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

Solution (Python):
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 == 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):
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 == 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):
def calc_median(X):
    
    Xl = len(X)
    if Xl % 2:
        ret = X[(Xl + 1) // 2 - 1]
    else:
        ret = (X[Xl // 2 - 1] + X[Xl // 2]) / 2

    return ret


N, *AB = map(int, open(0).read().split())

A = sorted(AB[::2])
B = sorted(AB[1::2])

AM = calc_median(A)
BM = calc_median(B)

if N % 2:
    ans = BM - AM + 1
else:
    ans = int((BM - AM) * 2 + 1)

print(ans)

Solution (Python):
n = int(input())
min_val, max_val = zip(*[map(int, input().split()) for _ in range(n)])
min_val = sorted(min_val)
max_val = sorted(max_val)

if n % 2:
    mid = n//2
    min_median = min_val[mid]
    max_median = max_val[mid]
    print(max_median-min_median+1)
else:
    midl = (n-1)//2
    midr = midl+1
    min_median = min_val[midl]+min_val[midr]
    max_median = max_val[midl]+max_val[midr]
    print(max_median-min_median+1)

Solution (Python):
def calc_median(X):
    
    Xl = len(X)
    if Xl % 2:
        ret = X[(Xl + 1) // 2 - 1]
    else:
        ret = (X[Xl // 2 - 1] + X[Xl // 2]) / 2

    return ret


N = int(input())
AB = [list(map(int, input().split())) for _ 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()

AM = calc_median(A)
BM = calc_median(B)

if N % 2:
    ans = BM - AM + 1
else:
    ans = int((BM - AM) * 2 + 1)

print(ans)

Solution (Python):
N = int(input())
A = [0]*N
B = [0]*N

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

A.sort()
B.sort()
if N % 2 == 1:
    print(B[N//2]-A[N//2]+1)
else:
    Am = (A[N//2]+A[N//2-1])/2
    Bm = (B[N//2]+B[N//2-1])/2
    print(int((Bm-Am)*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)
x = median(A)
y = median(B)

if n % 2 == 0:
    print(int((y - x) * 2 + 1))
else:
    print(y - x + 1)

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

def main():
    N = int(input())
    rg = []

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

    def disasm(i):
        rg.sort()
        a,_ = rg[i]
        rg.sort(key=lambda x: x[1])
        _,b = rg[i]
        return a,b


    if N % 2 == 1:
        a,b = disasm(N//2)
        print(b-a+1)
        exit()

    a,b = disasm(N//2-1)
    c,d = disasm(N//2)

    print(b+d-a-c+1)


if __name__ == "__main__":
  main()

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)
m_a = median(A)
m_b = median(B)

if n%2 == 0:
    ans = (m_b - m_a)*2 + 1
else:
    ans = m_b - m_a + 1
print(int(ans))

Solution (Python):
from sys import stdin
def main():
    
    readline=stdin.readline
    n=int(readline())
    x=[list(map(int,readline().split())) for _ in range(n)]
    
    a=[x[i][0] for i in range(n)]
    b=[x[i][1] for i in range(n)]
    a.sort()
    b.sort()
    if n%2==1:
        a_med=a[n//2]
        b_med=b[n//2]
    else:
        a_med=a[n//2-1]+a[n//2]
        b_med=b[n//2-1]+b[n//2]
    print(b_med-a_med+1)

if __name__=="__main__":
    main()

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

Solution (Python):
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 = sorted(A)
  B = sorted(B)
  if N % 2 == 1:
    print(B[(N-1)//2]-A[(N-1)//2]+1)
  else:
    med_A = (A[N//2-1] + A[N//2])/2
    med_B = (B[N//2-1] + B[N//2])/2
    print(int((med_B-med_A)*2 + 1))
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:
    print(B[(n - 1) // 2] - A[(n - 1) // 2] + 1)
else:
    print((B[(n - 1) // 2] + B[n // 2]) - (A[(n - 1) // 2] + A[n // 2]) + 1)

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

Solution (Python):
import sys, math,os
from io import BytesIO, IOBase


from collections import defaultdict as dd, deque, Counter

def data(): return sys.stdin.readline().strip()
def mdata(): return list(map(Decimal, data().split()))
def outl(var) : sys.stdout.write(' '.join(map(str, var))+'\n')
def out(var) : sys.stdout.write(str(var)+'\n')
sys.setrecursionlimit(100000)
INF = float('inf')
mod = int(1e9)+7
from decimal import Decimal


def main():

    n=int(data())
    l=[]
    l1=[]
    for i in range(n):
        a,b=mdata()
        l.append(a)
        l1.append(b)
    l.sort()
    l1.sort()
    if n%2!=0:
        a=l[n//2]
        b=l1[n//2]
        cnt=b-a+1
        out(cnt)
    else:
        a1=l[n//2-1]
        b1 = l1[n // 2-1]
        a2=l[n//2]
        b2 = l1[n // 2]
        out(int(((b1+b2)/2-(a1+a2)/2)*2+1))


if __name__ == '__main__':
    main()

Solution (Python):



import sys
from collections import defaultdict, deque
from heapq import heappush, heappop
import math
import bisect
input = sys.stdin.readline





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

A.sort()
B.sort()

if N % 2 == 0:
    min_x = (A[N//2] + A[(N//2)-1]) / 2
    max_x = (B[N//2] + B[(N//2)-1]) / 2
    
    ans = (max_x - min_x)*2 + 1
else:
    min_x = A[N//2]
    max_x = B[N//2]
    
    ans = max_x - min_x + 1

print(int(ans))

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

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

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

mins = sorted(mins)
maxs = sorted(maxs)

if n % 2 != 0:
    print(maxs[((n+1)//2) - 1] - mins[((n+1)//2) - 1] + 1)
else:
    print(int(2 * ((maxs[((n+1)//2) - 1] + maxs[n//2])/2 - (mins[((n+1)//2) - 1] + mins[n//2])/2) + 1))

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

a = []
b = []
for i in range(n):
  ab = input().split()
  a.append(int(ab[0]))
  b.append(int(ab[1]))
import statistics
a = statistics.median(a)
b = statistics.median(b)
if n % 2 != 0:
  print(int(b-a+1))
else:
  print(int(2*(b-a)+1))

Solution (Python):



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

if __name__ == '__main__':
    main()

Solution (Python):
import numpy as np
i4 = np.int32

nin = np.fromstring(open(0).read(), i4, sep=' ')
N = nin[0]
ab = nin[1:].reshape(-1, 2).T
a = np.sort(ab[0])
b = np.sort(ab[1])
i = N // 2
if N % 2:
    print(b[i] - a[i] + 1)
else:
    nmin = a[i - 1] + a[i]
    nmax = b[i - 1] + b[i]
    print(nmax - nmin + 1)

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

import statistics
a_med=statistics.median(a)
b_med=statistics.median(b)

if n%2==0:
    ans=2*b_med-2*a_med+1
else:
    ans=b_med-a_med+1
print(int(ans))

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

a = [0 for _ in range(n)]
b = [0 for _ in range(n)]
ans = 0

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

ma = statistics.median(a)
mb = statistics.median(b)

if(n%2 == 1):
    ans = mb-ma + 1
else:
    ans = 2*(mb-ma) + 1

print(int(ans))

Solution (Python):
import statistics
import math

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

A_m = statistics.median(A)
B_m = statistics.median(B)
if n%2 == 1:
    num = B_m - A_m +1
elif n %2 ==0:
    num = 2*B_m - 2*A_m +1
print(int(num))

Solution (Python):
n=int(input())
i=0
x=[]
y=[]
def linked_merge_sort(lst):
    if len(lst) == 1:
        return
    
    
    
    
    q, r = divmod(len(lst), 2)
    left = [lst.pop() for _ in range(q)]
    right = [lst.pop() for _ in range(q + r)]
    
    
    
    
    linked_merge_sort(left)
    linked_merge_sort(right)
    
    
    
    
    left.reverse()  
    right.reverse()
    while left and right:
        if left[-1] <= right[-1]:
            lst.append(left.pop())
        else:
            lst.append(right.pop())
    while left:
        lst.append(left.pop())
    while right:
        lst.append(right.pop())
while i<n:
    a=list(map(int,input().split()))
    x.append(a[0])
    y.append(a[1])
    i+=1
linked_merge_sort(x)
linked_merge_sort(y)
if n%2==0:
    p=(x[n//2]+x[(n//2)-1])/2
    q=(y[n//2]+y[(n//2)-1])/2
    ans=(q-p)*2+1
else:
    p=x[(n-1)//2]
    q=y[(n-1)//2]
    ans=q-p+1
print(int(ans))

Solution (Python):
import sys 
import statistics
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines
N = int(readline())
A = []
B = []
for _ in range(N):
  a,b = map(int,readline().split())
  A.append(a)
  B.append(b)
median_A = statistics.median(A)
median_B = statistics.median(B)
if N % 2 == 1:
  print(median_B-median_A+1)
else:
  print(int((median_B-median_A)*2)+1)

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

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

Solution (Python):
def main():

    import statistics

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

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

    meda = statistics.median(a)
    medb = statistics.median(b)

    if n % 2:
        print(int(medb - meda + 1))
    else:
        print(int((medb - meda) * 2 + 1))


if __name__ == '__main__':
    main()

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

Solution (Python):
import numpy as np
(n,), *d = [[*map(int, i.split())] for i in open(0)]
a, b = np.median(d, axis=0)
if n%2:print(int(b - a + 1))
else:print(int(b*2 - a*2 + 1))

Solution (Python):
n = int(input().strip())
lower=[0]*n
upper=[0]*n
for i in range(n):
    A, B = map(int, input().strip().split())
    lower[i]=A
    upper[i]=B
lower.sort()
upper.sort()

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

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

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

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

ans = mx - mn + 1
print(ans)

Solution (Python):

import sys


def solve(N: int, A: "List[int]", B: "List[int]"):
    As = sorted(A)
    Bs = sorted(B)

    if N % 2 == 1:
        min_ = As[(N-1)//2]
        max_ = Bs[(N-1)//2]

        print(max_-min_ + 1)
    else:
        min_1 = As[N//2]
        
        min_2 = As[N//2-1]
        min_ = (min_1 + min_2)/2
        max_1 = Bs[N//2]
        
        max_2 = Bs[N//2-1]
        max_ = (max_1 + max_2)/2
        
        print(int((max_ - min_)//0.5 + 1))


    return



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

if __name__ == '__main__':
    main()

Solution (Python):
import sys
readline = sys.stdin.readline
 
N = int(readline().strip())
A = []
B = []
for i in range(N):
  ai, bi = map(int, readline().split())
  A.append(ai)
  B.append(bi)

A.sort()
B.sort()

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

Solution (Python):
import statistics  

import sys
sys.setrecursionlimit(10 ** 5 + 10)


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


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

    M = statistics.median(B)
    m = statistics.median(A)

    if N % 2 == 0:
        print(int((M-m)//0.5+1))
    else:
        print(M-m+1)


resolve()

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_)
am, bm = median(a), median(b)
print(int(max(0, bm - am) * 2) + 1 if n % 2 == 0 else int(max(0, bm - am)) + 1)

Solution (Python):
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 = sorted(A)
    B = sorted(B)
    if n%2==0:
        print(int(((B[n//2-1]+B[n//2])/2-(A[n//2-1]+A[n//2])/2)*2)+1)
    else:
        print(B[(n+1)//2-1]-A[(n+1)//2-1]+1)
if __name__ == "__main__":
    main()

Solution (Python):
n = int(input())
list_AB = [ list(map(int,input().split(" "))) for _ in range(n)]
mins = []
maxs = []
for a, b in list_AB:
    mins.append(a)
    maxs.append(b)

mins.sort()
maxs.sort()

if n % 2 == 1:
    ans = maxs[n//2] - mins[n//2] + 1
else:
    small = mins[n//2] + mins[n//2-1]
    large = maxs[n//2] + maxs[n//2-1]
    ans = large - small +1

print(ans)

Solution (Python):
N=int(input())
As=[0]*N
Bs=[0]*N
for i in range(N):
    As[i],Bs[i] = map(int,input().split())
As.sort()
Bs.sort()

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

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

Solution (Python):
def median(A,N):
    A.sort()
    if N % 2 == 1:
        return A[N//2]
    else:
        return A[(N-1)//2] + A[(N-1)//2+1]

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

    A = [AB[i][0] for i in range(N)]
    B = [AB[i][1] for i in range(N)]

    ans = median(B,N) - median(A,N) + 1
    print(ans)

if __name__ == "__main__":
    main()

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

Solution (Python):
N=int(input())
A=[]
B=[]
for i in range(N):
    a,b=map(int,input().split())
    A.append(a)
    B.append(b)
A.sort()
B.sort()
if N%2==1:
    print(B[N//2]-A[N//2]+1)
else:
    A_chu=(A[N//2-1]+A[N//2])/2
    B_chu=(B[N//2-1]+B[N//2])/2
    ans=(B_chu-A_chu)*2+1
    print(int(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=sorted(a)
b=sorted(b)
if N%2==1:
    print(b[N//2]-a[N//2]+1)
else:
    print((b[N//2-1]+b[N//2])-(a[N//2-1]+a[N//2])+1)