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 sys import stdin
from sys import setrecursionlimit
from functools import cmp_to_key
from collections import Counter, deque, defaultdict
from math import floor, ceil
from bisect import bisect_left
from itertools import combinations
setrecursionlimit(100000)

INF = int(1e10)
MOD = int(1e9 + 7)
MAX_N = 200000 + 5

def main():
    from builtins import int, map
    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()
    ans = 0

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


if __name__ == '__main__':
    main()

Solution (Python):
def median(q):
    l=len(q)
    q=sorted(q,reverse=True)
    if l%2==0:
        return (q[int(l/2)]+q[int(l/2)-1])/2
    else:
        return q[int((l+1)/2-1)]

n=int(input())

a=[]
b=[]

for i in range(n):
   x,y=map(int,input().split())
   a.append(x)
   b.append(y)
   
med_a=median(a)
med_b=median(b)

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

Solution (Python):
N,*ABf = map(int, open(0).read().split())
AB = [ABf[i:i+2] for i in range(0, len(ABf), 2)]
A = sorted([x[0] for x in AB])
B = sorted([x[1] for x in AB])
if N % 2 == 1:
    print(B[N//2]-A[N//2]+1)
else:
    print(int(((B[N//2-1]+B[N//2])*(0.5)-(A[N//2-1]+A[N//2])*(0.5))*2+1))

Solution (Python):
import numpy as np
N = int(input())
A = []
B = []
for i in range(N):
    in1, in2 = list(map(int,input().split()))
    A.append(in1)
    B.append(in2)
temp1 = np.median(A)
temp2 = np.median(B)
if N % 2 == 0:
    ans = (temp2 - temp1) * 2 + 1
else:
    ans = (temp2 - temp1) + 1
print(int(ans))

Solution (Python):
I = lambda : list(map(int,input().split()))

n,=I();a=[];b=[]
for i in range(n):
  x,y=I()
  a.append(x);b.append(y)
a.sort();b.sort()
if n%2:
  print(b[n//2]-a[n//2]+1)
else:
  x=(a[n//2-1]+a[n//2]);y=(b[n//2-1]+b[n//2])
  print(y-x+1)

Solution (Python):
n = int(input())
a_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 & 1:
  min_medium = a_list[n // 2]
  max_medium = b_list[n // 2]
  print(max_medium - min_medium + 1)
else:
  min_medium_x2 = a_list[n // 2 - 1] + a_list[n // 2]
  max_medium_x2 = b_list[n // 2 - 1] + b_list[n // 2]
  print(max_medium_x2 - min_medium_x2 + 1)

Solution (Python):

def resolve():
    N = int(input())
    L = [0]*N
    R = [0] * N
    for i in range(N):
        l, r = map(int, input().split())
        L[i] = l
        R[i] = r

    L.sort()
    R.sort()
    ans = 0
    if N%2 == 1:
        mid_L = L[N//2]
        mid_R = R[N // 2]
        ans = mid_R - mid_L +1
    else:
        mid_L = L[N // 2-1] + L[N // 2]
        mid_R = R[N // 2-1] + R[N // 2]
        ans = mid_R - mid_L + 1

    print(ans)

if __name__ == "__main__":
    resolve()

Solution (Python):
from sys import stdin, stdout

int_in = lambda: int(stdin.readline())
arr_in = lambda: [int(x) for x in stdin.readline().split()]
mat_in = lambda rows: [arr_in() for y in range(rows)]
str_in = lambda: stdin.readline().strip()
out = lambda o: stdout.write("{}\n".format(o))
arr_out = lambda o: out(" ".join(map(str, o)))
bool_out = lambda o: out("YES" if o else "NO")
tests = lambda: range(1, int_in() + 1)
case_out = lambda i, o: out("Case 



def solve(n, ranges):
    a = sorted(map(lambda x: x[0], ranges))
    b = sorted(map(lambda x: x[1], ranges))

    if len(ranges) % 2 == 0:
        m_a = a[(len(a)//2)-1] + a[(len(a)//2)]
        m_b = b[(len(b)//2)-1] + b[(len(b)//2)]
    else:
        m_a = a[((len(a)+1)//2)-1]
        m_b = b[((len(b)+1)//2)-1]
    return m_b - m_a + 1



if __name__ == "__main__":
    n = int_in()
    ranges = mat_in(n)
    out(solve(n, ranges))

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

Solution (Python):
import statistics

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

Solution (Python):
import statistics

n = int(input())
la = []
lb = []
for i in range(n):
  a, b = map(int, input().split())
  la.append(a)
  lb.append(b)
a = statistics.median(la)
b = statistics.median(lb)
if n % 2 == 1:
  print(b - a + 1)
else:
  print(int((b - a) * 2 + 1))

Solution (Python):
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==0):
    print(bb[n//2-1]+bb[n//2]-aa[n//2]-aa[n//2-1]+1)
else:
    print(bb[n//2]-aa[n//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)

mn = median(A)
mx = median(B)

if N % 2 == 1:
    print(int(mx - mn + 1))        
else:
    print(int((mx - mn) * 2 + 1))

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

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

if N % 2 == 1:
  mid = N // 2
  print(b[mid] - a[mid] + 1)
else:
  mid1 = N // 2
  mid2 = mid1 - 1
  print(b[mid1] + b[mid2] - a[mid1] - a[mid2] + 1)

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

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

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

Solution (Python):
import numpy as np

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

if N % 2 == 1:
    a = np.sort(arr[:, 0])
    b = np.sort(arr[:, 1])
    print(b[N // 2] - a[N // 2] + 1)

else:
    a = np.sort(arr[:, 0])
    b = np.sort(arr[:, 1])
    print((b[N // 2] + b[N // 2 - 1]) - (a[N // 2 - 1] + a[N // 2]) + 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==0:
    p = n//2
    right = (a[p]+a[p-1])/2 - 0.5
    left = (b[p]+b[p-1])/2
    r = left-right
    if int(r)==r:
        print(int(r)*2)
    else:
        print(int(r)*2 +1)
else:
    p = n//2
    right = a[p]
    left = b[p]
    print(int(left-right)+1)

Solution (Python):
import numpy as np
(n,),*l = [[*map(int,i.split())]for i in open(0)]
a,b = np.median(l,axis=0)
if n%2>0:
    print(int(b-a+1))
else:
    print(int(b*2-a*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:
  n = N // 2
  a, b = A[n], B[n]
  print(b - a + 1)
else:
  n = N // 2
  a0, b0 = A[n-1], B[n-1]
  a1, b1 = A[n], B[n]
  left = a0 + a1; right = b0 + b1
  print(right - left + 1)

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

if N%2==0:
    Min=[]
    for i in range(N):
        Min.append(min(L[i]))
    
    Min.sort()
    MIN=(Min[N//2]+Min[N//2-1])/2
    
    Max=[]
    for i in range(N):
        Max.append(max(L[i]))
    Max.sort()
    MAX=(Max[N//2]+Max[N//2-1])/2
    print(int((MAX-MIN)*2+1))
else:
    Min=[]
    for i in range(N):
        Min.append(min(L[i]))
    
    Min.sort()
    MIN=Min[N//2]
    Max=[]
    for i in range(N):
        Max.append(max(L[i]))
    Max.sort()
    MAX=Max[N//2]
    print(int((MAX-MIN)+1))

Solution (Python):
import numpy as np

N = int(input())
A, B = [], []
for i in range(N):
    a, b = map(int, input().split())
    A.append(a if N & 1 else 2 * a)
    B.append(b if N & 1 else 2 * b)

a, b = int(np.median(A)), int(np.median(B))
print(b - a + 1)

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

a, b = [*map(list, zip(*[[*map(int, input().split())] for _ in range(n)]))]
a.sort()
b.sort()

l0, r0 = a[(n-1)//2], b[(n-1)//2]
if n % 2 == 1:
    print(r0-l0+1)
else:
    l1, r1 = a[n//2], b[n//2]
    print((r1+r0)-(l1+l0)+1)

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

Solution (Python):
import numpy as np

N = int(input())
A, B = [], []
for i in range(N):
    a, b = map(int, input().split())
    A.append(a if N & 1 else 2 * a)
    B.append(b if N & 1 else 2 * b)

a, b = int(np.median(A)), int(np.median(B))
if a > b:
    a, b = b, a
print(b - a + 1)

Solution (Python):
import sys
import math

N = int(sys.stdin.readline().strip())
ABlist = []
for _ in range(N):
    a, b = map(int, sys.stdin.readline().strip().split())
    ABlist.append((a, b))

Asorted = sorted(ABlist)
Bsorted = sorted(ABlist, key=lambda x: x[1])
if N % 2 == 1:
    left = Asorted[N//2][0]
    right = Bsorted[N//2][1]
    
    print(right - left + 1)
else:
    left = (Asorted[N//2 - 1][0] + Asorted[N//2][0]) / 2
    right = (Bsorted[N//2 - 1][1] + Bsorted[N//2][1]) / 2
    print(int((right - left) * 2 + 1))

Solution (Python):
import sys

readline = sys.stdin.readline
MOD = 10 ** 9 + 7
INF = float('INF')
sys.setrecursionlimit(10 ** 5)


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

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

    a.sort()
    b.sort()

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


if __name__ == '__main__':
    main()

Solution (Python):
n = int(input())
A = []
B = []
for _ in range(n):
    v1, v2 = list(map(int, input().split(' ')))
    A.append(v1)
    B.append(v2)

A.sort()
B.sort()

if n % 2:
    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
input = lambda: sys.stdin.readline().rstrip()


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

    As = sorted(A)
    Bs = sorted(B)

    if N % 2 == 0:
        i1 = N // 2
        i2 = N // 2 - 1
        low = As[i1] + As[i2]
        up = Bs[i1] + Bs[i2]
        ans = up - low + 1
    else:
        i = (N - 1) // 2
        low = As[i]
        up = Bs[i]
        ans = up - low + 1

    print(ans)


if __name__ == '__main__':
    solve()

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

def main():
    N,*ab = map(int, read().split())

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

    A.sort()
    B.sort()

    if N % 2 == 0:
        a1, a2 = A[N // 2 - 1], A[N // 2]
        b1, b2 = B[N // 2 - 1], B[N // 2]

        ans = b1 + b2 - (a1 + a2) + 1
    
    else:
        a = A[N // 2]
        b = B[N // 2]
        
        ans = b - a + 1
    
    print(ans)


if __name__ == "__main__":
    main()

Solution (Python):
n=int(input())
import numpy as np
ab=np.array([[int(j)for j in input().split()]for i in range(n)])
a=np.median(ab[:,0])
b=np.median(ab[:,1])
if n%2:
    print(int(b-a+1))
else:
    print(int(2*b-2*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 = list()
B = list()
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+1)//2 - 1] - A[(N+1)//2 - 1]) + (B[(N+1)//2] - A[(N+1)//2]) + 1)

Solution (Python):
import sys,collections as cl,bisect as bs
sys.setrecursionlimit(100000)
input = sys.stdin.readline
mod = 10**9+7
Max = sys.maxsize
def l(): 
	return list(map(int,input().split()))
def m(): 
	return map(int,input().split())
def onem(): 
	return int(input())
def s(x): 
	a = []
	if len(x) == 0:
		return []
	aa = x[0]
	su = 1
	for i in range(len(x)-1):
		if aa != x[i+1]:
			a.append([aa,su])
			aa = x[i+1]
			su = 1
		else:
			su += 1
	a.append([aa,su])
	return a
def jo(x): 
	return " ".join(map(str,x))
def max2(x): 
	return max(map(max,x))
def In(x,a): 
    k = bs.bisect_left(a,x)
    if k != len(a) and a[k] ==  x:
        return True
    else:
        return False

def pow_k(x, n):
    ans = 1
    while n:
        if n % 2:
            ans *= x
        x *= x
        n >>= 1
    return ans

"""
def nibu(x,n,r):
	ll = 0
	rr = r
	while True:
		mid = (ll+rr)//2

	if rr == mid:
		return ll
	if (ここに評価入れる):
		rr = mid
	else:
		ll = mid+1
"""
n = onem()

le = []

ri = []

if n % 2 != 0:
	for i in range(n):
		a,b = m()
		le.append(a)
		ri.append(b)
	le.sort()
	ri.sort()
	print(ri[n//2] - le[n//2]+1)



else:
	for i in range(n):
		a,b = m()
		le.append(a*2)
		ri.append(b*2)
	le.sort()
	ri.sort()
	print(((ri[n//2]+ri[n//2-1]) - (le[n//2]+le[n//2-1]))//2+1)

Solution (Python):
N = int(input())
AB = [list(map(int,input().split())) for _ in range(N)]
 
A = []
B = []
for i in range(N):
  A.append(AB[i][0])
  B.append(AB[i][1])
A.sort()
B.sort()
if N % 2 == 0:
    n = N // 2
    med1 = A[n-1] + A[n]
    med2 = B[n-1] + B[n]
    x = med2 - med1 + 1
else:
    n = N // 2
    med1 = A[n]
    med2 = B[n]
    x = med2 - med1 + 1
    
print(x)

Solution (Python):
n = int(input())
a = []
b = []
for i in range(n):
    a1,b1 = map(int, input().split())
    a.append(a1)
    b.append(b1)
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]-a[n//2-1]+b[n//2]-a[n//2]+1)

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

def main():
    N,*ab = map(int, read().split())

    AB = []
    for a, b in zip(*[iter(ab)]*2):
        AB.append((a, b))

    if N % 2 == 0:
        AB.sort()
        a1, _ = AB[N // 2 - 1]
        a2, _ = AB[N // 2]
    
        AB.sort(key=lambda x: x[1])
        _, b1 = AB[N // 2 - 1]
        _, b2 = AB[N // 2]

        ans = b1 + b2 - (a1 + a2) + 1
    
    else:
        AB.sort()
        a, _ = AB[N // 2]
    
        AB.sort(key=lambda x: x[1])
        _, b = AB[N // 2]
        
        ans = b - a + 1
    
    print(ans)


if __name__ == "__main__":
    main()

Solution (Python):

import sys
from bisect import bisect_left,bisect_right
sys.setrecursionlimit(10**9)
INF=10**18
MOD=10**9+7
input=lambda: sys.stdin.readline().rstrip()
YesNo=lambda b: bool([print('Yes')] if b else print('No'))
YESNO=lambda b: bool([print('YES')] if b else print('NO'))
int1=lambda x:int(x)-1

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

Solution (Python):

from sys import stdin
input = stdin.readline
printn = lambda x: print(x,end='')
inn = lambda : int(input())
inl   = lambda: list(map(int, input().split()))
inm   = lambda:      map(int, input().split())
ins = lambda : input().strip()
DBG = True 
BIG = 10**18
R = 10**9 + 7

def ddprint(x):
  if DBG:
    print(x)

n = inn()
a = []
b = []
for i in range(n):
    aa,bb = inm()
    a.append(aa)
    b.append(bb)
a.sort()
b.sort()
if n%2==1:
    m = n//2
    print(b[m]-a[m]+1)
else:
    m = n//2 - 1
    print(b[m]+b[m+1]-a[m]-a[m+1]+1)

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

m_a = statistics.median( a )
m_b = statistics.median( b )

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

Solution (Python):


import sys






























def main():
    mod = 1000000007                
    inf = float('inf')              
    
    sys.setrecursionlimit(10**6)    
    def input(): return sys.stdin.readline().rstrip()
    def ii():    return int(input())
    def mi():    return map(int, input().split())
    def mi_0():  return map(lambda x: int(x)-1, input().split())
    def lmi():   return list(map(int, input().split()))
    def lmi_0(): return list(map(lambda x: int(x)-1, input().split()))
    def li():    return list(input())
    
    
    n = ii()
    left = []
    right = []
    for _ in range(n):
        a, b = mi()
        left.append(a)
        right.append(b)
    left.sort()
    right.sort()

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


if __name__ == "__main__":
    main()

Solution (Python):
n = int(input())
la = []
lb = []

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

la.sort()
lb.sort()

if n % 2 == 1:
    lr = (n + 1) // 2
    ma = la[lr-1]
    mb = lb[lr-1]
    print(mb-ma+1)
else:
    l = n // 2
    r = n // 2 + 1
    ma = (la[l-1] + la[r-1]) / 2
    mb = (lb[l - 1] + lb[r - 1]) / 2
    print(int((mb-ma)*2+1))

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

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

Solution (Python):
import sys

N = int(sys.stdin.readline().rstrip())

maxs = []
mins = []

for _ in range(N):
    a, b = map(int, sys.stdin.readline().rstrip().split())
    maxs.append(b)
    mins.append(a)

maxs.sort()
mins.sort()

if N % 2 == 1:
    mid = (N + 1) // 2 - 1
    ans = maxs[mid] - mins[mid] + 1
else:
    mid = N // 2
    ans = (maxs[mid - 1] + maxs[mid] - mins[mid - 1] - mins[mid] + 1)

print(ans)

Solution (Python):
N = int(input())
A = list()
B = list()
for _ in range(N):
    a, b = map(int, input().split())
    A.append(a)
    B.append(b)
A.sort()
B.sort(reverse=True)
if N%2 == 1:
    print(B[(N+1)//2 - 1] - A[(N+1)//2 - 1] + 1)
else:
    print((B[(N+1)//2 - 1] - A[(N+1)//2 - 1]) + (B[(N+1)//2] - A[(N+1)//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 = sorted(A)
B = sorted(B)
res = 0
if N % 2 == 1:
    l = A[int(N/2)]
    r = B[int(N/2)]
    res = r - l + 1
else:
    l = A[int(N/2) - 1] + A[int(N/2)]
    r = B[int(N/2) - 1] + B[int(N/2)]
    res = r - l + 1
print(res)

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

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

if N % 2 == 1:
    L = A[N // 2]
    R = B[N // 2]
else:
    L = A[N // 2 - 1] + A[N // 2]
    R = B[N // 2 - 1] + B[N // 2]

print(R - L + 1)

Solution (Python):
import statistics
N = int(input())
 
a = []
b = []
 
for i in range(N):
    m, n = map(int, input().split())
    a.append(m)
    b.append(n)
 
if N % 2 == 1:
    print(int(statistics.median(b)-statistics.median(a)+1))
else:
    print(int(statistics.median(b)*2-statistics.median(a)*2+1))

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

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

print(e_count_median())

Solution (Python):
import bisect
n = int(input())
a = []
b = []

for i in range(n):
    m, p = map(int, input().split())
    a.append(m)
    b.append(p)
a.sort()
b.sort()
middle = n // 2
if n % 2:
    print(b[middle] - a[middle] + 1)
else: 
    a_m = ( a[middle] + a[middle - 1] ) / 2
    b_m = ( b[middle] + b[middle - 1] ) / 2
    print(int((b_m - a_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=sorted(a)
b=sorted(b)
if N%2==1:
    print(b[N//2]-a[N//2]+1)
else:
    print(int(((b[N//2-1]+b[N//2])/2-(a[N//2-1]+a[N//2])/2)*2+1))

Solution (Python):
import statistics
f = statistics.median
N = int(input())

a = [0]*N
b = [0]*N

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

if N % 2 == 1:
    print(int(f(b)-f(a)+1))
else:
    print(int(f(b)*2-f(a)*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 - 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):
import sys, re
from collections import deque, defaultdict, Counter
from math import ceil, sqrt, hypot, factorial, pi, sin, cos, radians, gcd
from itertools import accumulate, permutations, combinations, product, groupby, combinations_with_replacement
from operator import itemgetter, mul
from copy import deepcopy
from string import ascii_lowercase, ascii_uppercase, digits
from bisect import bisect, bisect_left
from heapq import heappush, heappop
from functools import reduce
def input(): return sys.stdin.readline().strip()
def INT(): return int(input())
def MAP(): return map(int, input().split())
def LIST(): return list(map(int, input().split()))
def ZIP(n): return zip(*(MAP() for _ in range(n)))
sys.setrecursionlimit(10 ** 9)
INF = float('inf')
mod = 10 ** 9 + 7

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

Solution (Python):
N = int(input())
ab = []
for i in range(N):
    ab.append(tuple(map(int,input().split())))
 
up = sorted(ab,key=lambda a:a[1],reverse=False)
down = sorted(ab,key=lambda a:a[0],reverse=False)
 
if N%2 == 1:
    print(up[N//2][1]-down[N//2][0]+1)
else:
    r = (up[N//2][1]+up[N//2-1][1])
    l = (down[N//2][0]+down[N//2-1][0])
    print(r-l+1)

Solution (Python):


import numpy as np

LI = lambda: list(map(int, input().split()))


N = int(input())
A, B = [None] * N, [None] * N
for i in range(N):
    A[i], B[i] = LI()


def main():
    a, b = np.array(A, dtype=int), np.array(B, dtype=int)
    a.sort()
    b.sort()
    i = N // 2
    if N % 2 == 0:
        a *= 2
        b *= 2
        l = (a[i - 1] + a[i]) // 2
        r = (b[i - 1] + b[i]) // 2
        ans = r - l + 1
    else:
        ans = b[i] - a[i] + 1
    print(ans)


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

Solution (Python):




import sys
input = sys.stdin.readline



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

    As = sorted(A)
    Bs = sorted(B)

    if N % 2 == 1:
        Am = As[N//2]
        Bm = Bs[N//2]
    else:
        Am = As[N//2-1] + As[N//2]
        Bm = Bs[N//2-1] + Bs[N//2]

    res = Bm - Am + 1

    print(res)



main()

Solution (Python):
N = int(input())
ab = []
for i in range(N):
    ab.append(tuple(map(int,input().split())))
 
up = sorted(ab,key=lambda a:a[1],reverse=True)
down = sorted(ab,key=lambda a:a[0],reverse=True)
 
if N%2 == 1:
    print(up[N//2][1]-down[N//2][0]+1)
else:
    r = (up[N//2][1]+up[N//2-1][1])
    l = (down[N//2][0]+down[N//2-1][0])
    print(r-l+1)

Solution (Python):
import sys
from heapq import heappush, heappop
def input(): return sys.stdin.readline().strip()

def main():
    """
    中央値の最小値から最大値まで、全ての値を取れるというだけのオチ。。。
    確かに中央値じゃなくて和の場合の問題やったことあるわ。。。
    """
    N = int(input())
    lower = []
    upper = []
    for i in range(N):
        a, b = map(int, input().split())
        heappush(lower, (a, i))
        heappush(upper, (-b, i))
    
    if N % 2 != 0:
        for _ in range(N // 2):
            a, i = heappop(lower)
        a, _ = heappop(lower)
        for _ in range(N // 2):
            b, i = heappop(upper)
        b, _ = heappop(upper)
        print(-b - a + 1)
    else:
        for _ in range(N // 2 - 1):
            a, i = heappop(lower)
        a0, i0 = heappop(lower)
        a1, i1 = heappop(lower)
        for _ in range(N // 2 - 1):
            b, i = heappop(upper)
        b0, i0 = heappop(upper)
        b1, i1 = heappop(upper)
        print((-b1 - b0) - (a1 + a0) + 1)


    

if __name__ == "__main__":
    main()

Solution (Python):
N = int(input())
ab = []
for i in range(N):
    ab.append(tuple(map(int,input().split())))
 
up = sorted(ab,key=lambda a:a[1],reverse=True)
down = sorted(ab,key=lambda a:a[0],reverse=True)
 
if N%2 == 1:
    print(up[N//2][1]-down[N//2][0]+1)
else:
    up2 = sorted(ab,key=lambda a:a[1],reverse=False)
    down2 = sorted(ab,key=lambda a:a[0],reverse=False)
    r = (up[N//2][1]+up2[N//2][1])
    l = (down[N//2][0]+down2[N//2][0])
    print(r-l+1)

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

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

min_s.sort()
max_s.sort()
if n % 2 == 0:
    min_med = (min_s[n // 2 - 1] + min_s[n // 2]) / 2
    max_med = (max_s[n // 2 - 1] + max_s[n // 2]) / 2
    print(int((max_med - min_med) * 2 + 1))

else:
    min_med = min_s[(n + 1) // 2 - 1]
    max_med = max_s[(n + 1) // 2 - 1]
    print(int((max_med - min_med)+1))

Solution (Python):
N = int(input())
ab = []
for i in range(N):
    ab.append(tuple(map(int,input().split())))
 
up = sorted(ab,key=lambda a:a[1])
down = sorted(ab,key=lambda a:a[0])
 
if N%2 == 1:
    print(up[N//2][1]-down[N//2][0]+1)
else:
    up2 = sorted(ab,key=lambda a:a[1],reverse=True)
    down2 = sorted(ab,key=lambda a:a[0],reverse=True)
    r = (up[N//2][1]+up2[N//2][1])
    l = (down[N//2][0]+down2[N//2][0])
    print(r-l+1)

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

A = [i[0] for i in AB]
B = [i[1] for i in AB]
from statistics import median

a_med = median(A)
b_med = median(B)

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

Solution (Python):
n=int(input())
a=[]
b=[]
for i in range(n):
  c,d=map(int,input().split())
  a.append(c)
  b.append(d)
a=sorted(a)
b=sorted(b)
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:
  print(b[n//2]-a[n//2]+1)

Solution (Python):
import math

N = int(input())
A = []
B = []
for i in range(N):
    in1, in2 = list(map(int,input().split()))
    A.append(in1)
    B.append(in2)
AA = sorted(A)
BB = sorted(B)

if N%2==1:
    low = AA[N//2]
    high = BB[N//2]
    print(high - low +1)

else:
    low = AA[N//2-1] + AA[N//2]
    high = BB[N//2-1] + BB[N//2]
    
    print(high - low +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 == 0:
    ans = 0
    ans += b[n // 2 - 1] + b[n // 2]
    ans -= a[n // 2 - 1] + a[n // 2]
    print(ans + 1)
else:
    print(b[n // 2] - a[n // 2] + 1)

Solution (Python):
from statistics import median

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)]
ma, mb = median(a), median(b)

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

Solution (Python):
from statistics import median

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

if n % 2 == 0:
    ma, mb = median(a), median(b)
    print(int(2 * mb - 2 * ma + 1))
if n % 2 == 1:
    ma, mb = median(a), median(b)
    print(int(mb - ma + 1))