Problem:
 Score : 500 points    Problem Statement There are N integers X_1, X_2, \cdots, X_N , and we know that A_i \leq X_i \leq B_i .
Find the number of different values that the median of X_1, X_2, \cdots, X_N can take.      Notes The median of X_1, X_2, \cdots, X_N is defined as follows. Let x_1, x_2, \cdots, x_N be the result of sorting X_1, X_2, \cdots, X_N in ascending order.   If N is odd, the median is x_{(N+1)/2} ;  if N is even, the median is (x_{N/2} + x_{N/2+1}) / 2 .       Constraints  2 \leq N \leq 2 \times 10^5  1 \leq A_i \leq B_i \leq 10^9  All values in input are integers.         Input Input is given from Standard Input in the following format:  N  A_1  B_1  A_2  B_2  :  A_N  B_N       Output Print the answer.        Sample Input 1 2
1 2
2 3      Sample Output 1 3    If X_1 = 1 and X_2 = 2 , the median is \frac{3}{2} ;    if X_1 = 1 and X_2 = 3 , the median is 2 ;    if X_1 = 2 and X_2 = 2 , the median is 2 ;    if X_1 = 2 and X_2 = 3 , the median is \frac{5}{2} .    Thus, the median can take three values: \frac{3}{2} , 2 , and \frac{5}{2} .       Sample Input 2 3
100 100
10 10000
1 1000000000      Sample Output 2 9991

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

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

if n%2 == 1:
  l = A[n//2]
  r = B[n//2]
  print(r-l + 1)
else:
  l = (A[n//2-1]+A[n//2])/2
  r = (B[n//2-1]+B[n//2])/2
  print(int((r-l)*2+1))

Solution (Python):
import statistics


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

    amed = statistics.median(a)
    bmed = statistics.median(b)

    if n % 2:
        print(int(bmed - amed + 1))
    else:
        print(int((bmed - amed) * 2 + 1))


if __name__ == '__main__':
    main()

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

Solution (Python):
import sys


import math
import collections

import bisect
import itertools
import fractions

import copy
import heapq
import decimal

import queue
import numpy as np

sys.setrecursionlimit(10000001)
INF = 10 ** 16
MOD = 10 ** 9 + 7

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





def main():
    n = ni()
    a = []
    b = []
    for _ in range(n):
        ai, bi = ns()
        a.append(ai)
        b.append(bi)

    a.sort()
    b.sort()

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


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 n%2==1:
    num1=-1*(n//-2)-1
    print(blist[num1]-alist[num1]+1)
else:
    num1=n//2-1
    num2=num1+1
    print((blist[num2]+blist[num1])-(alist[num2]+alist[num1])+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==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())
ab = [list(map(int, input().split())) for _ in range(N)]

ba = []
for i, j in ab:
    ba.append([j, i])

ab.sort()
ba.sort(reverse = True)

if N % 2 == 1:
    n = (N+1) // 2 - 1
    ans = ba[n][0] - ab[n][0] + 1
    
else:
    n = N // 2 - 1
    ans = (ba[n][0] + ba[n+1][0]) - (ab[n][0] + ab[n+1][0]) + 1

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

youso = int(n/2)

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

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

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 :
    l = a[int(n/2)]
    u = b[int(n/2)]
    ans = u - l + 1
else:
    l = a[int(n/2-1)] + a[int(n/2)]
    u = b[int(n/2-1)] + b[int(n/2)]
    ans = u - l +1

print(ans)

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


import math
import numpy as np

N = int(input())
A = []
B = []
for i in range(N):
    t = list(map(int, input().split()))
    A.append(t[0])
    B.append(t[1])
A.sort()
B.sort()

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

    print(a)

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

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

Solution (Python):
import math
n = int(input())
a = []
b = []
for i in range(n):
    x, y = map(int, input().split())
    a.append(x)
    b.append(y)
a = sorted(a)
b = sorted(b)
res = 0
if n % 2 == 1:
    m = n // 2
    m1 = a[m]
    m2 = b[m]
    res = m2 - m1 + 1
else:
    ml = n // 2 - 1
    m1 = a[ml] + a[ml + 1]
    m2 = b[ml] + b[ml + 1]
    res = m2 - m1 + 1

print(res)

Solution (Python):

import sys
import math
import numpy as np
import itertools

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

Solution (Python):
import statistics
import math

N = int(input())
A_B = [[int(i) for i in input().split(' ')] for n in range(N)]

t = list(zip(*A_B))

A_sta = statistics.median(t[0])
B_sta = statistics.median(t[1])

if N % 2 == 0:
    count = int(2 * (B_sta - A_sta) + 1)
else:
    count = B_sta - A_sta + 1

print(count)

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:
    i=int(n/2)
    ans_a=(a[i]+a[i-1])/2
    ans_b=(b[i]+b[i-1])/2
    ans=(ans_b-ans_a+1)*2-1
    print(int(ans))
else:
    i=int((n-1)/2)
    ans_a=a[i]
    ans_b=b[i]
    ans=ans_b-ans_a+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.sort()
B.sort()
if n%2==0:
    A_med=(A[int(n/2)-1]+A[int(n/2)])/2
    B_med=(B[int(n/2)-1]+B[int(n/2)])/2
    print(int((B_med-A_med)*2+1))
else:
    A_med=A[int((n+1)/2)-1]
    B_med=B[int((n+1)/2)-1]
    print(int(B_med-A_med+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())

    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())
A = [0] * (N + 1)
B = [0] * (N + 1)

count = 0

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

A.sort()
B.sort()
if N % 2 == 1:
  centerA = A[(N + 1) // 2]
  centerB = B[(N + 1) // 2]
else:
  centerA = (A[N // 2] + A[N // 2 + 1]) / 2
  centerB = (B[N // 2] + B[N // 2 + 1]) / 2



if N % 2 == 1:
  count = centerB - centerA + 1
else:
  count = (centerB - centerA) * 2 + 1

print(int(count))

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

if __name__ == "__main__":
    main()

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

if N % 2== 0:
    A.sort()
    med_A = (A[N//2] + A[N//2 - 1])/2
    B.sort()
    med_B = (B[N//2] + B[N//2 - 1])/2
    print(int((med_B-med_A) * 2 + 1))
else:
    A.sort()
    med_A = A[(N-1)//2]
    B.sort()
    med_B = B[(N-1)//2]
    print(int(round(med_B) - round(med_A) + 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()

ans = 0

if n % 2 == 1:
    l1 = A[int(n/2)]
    r1 = B[int(n/2)]
    ans = r1 - l1 + 1
else:
    l2 = A[int(n/2)-1] + A[int((n/2))]
    r2 = B[int(n/2)-1] + B[int((n/2))]
    ans = r2 - l2 + 1

print(ans)

Solution (Python):
import statistics

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

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

if n % 2 == 1:
    ans = mb - ma + 1
else:
    ma = int(ma * 2)
    mb = int(mb * 2)
    ans = mb - ma + 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.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):
N=int(input())
A=list()
B=list()
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[int((N-1)/2+0.5)]-A[int((N-1)/2+0.5)]+1)
else:
  print((B[int(N/2+0.5)-1]+B[int(N/2+0.5)])-(A[int(N/2+0.5)-1]+A[int(N/2+0.5)])+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 = sorted(a)
b = sorted(b)
 
if n%2!=0:
    ans = b[(n-1)//2] - a[(n-1)//2] + 1
else:
    ans = (b[n//2-1] + b[n//2]) - (a[n//2-1] + a[n//2]) + 1
 
print(ans)

Solution (Python):
from math import sqrt
itl = lambda: list(map(float, input().strip().split()))


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


def solve():
    N = int(input())

    A = []
    B = []
    for _ in range(N):
        a, b = itl()
        A.append(int(a))
        B.append(int(b))
    A.sort()
    B.sort()

    ma = median(N, A)
    mb = median(N, B)
    return mb - ma + 1


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

Solution (Python):
from collections import defaultdict
from fractions import Fraction
N = int(input())
A = [0 for  _ in range(N)]
B = [0 for  _ in range(N)]
for i in range(N):
    A[i], B[i] = [int(i) for i in input().split()]
A.sort()
B.sort()

if N%2 == 1:
    target = ((N+1)//2)-1
    print(B[target]-A[target]+1)
else:
    target1 = ((N)//2)-1
    target2 = (N)//2
    num1 = (A[target1]+A[target2])/2
    num2 = (B[target1]+B[target2])/2
    print(int(((num2-num1)/0.5)+1))

Solution (Python):
n=int(input())
low=[]
high=[]
for i in range(n):
    a,b=map(float,input().split())
    low.append(a)
    high.append(b)
low.sort()
high.sort()
if n%2==0:
    low_avg=(low[n//2-1]+low[n//2])/2
    high_avg=(high[n//2-1]+high[n//2])/2
    ans=(high_avg-low_avg)*2+1
else:
    ans=high[(n-1)//2]-low[(n-1)//2]+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=sorted(a)
b=sorted(b)

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

print(ans)

Solution (Python):
import numpy as np

        
n = int(input())

a = np.zeros(n,dtype=int)
b = np.zeros(n,dtype=int)

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


a.sort()
b.sort()
                    
if n%2 == 1:
    a0cen = a[(n-1)//2]
    b0cen = b[(n-1)//2]
    nn = b0cen - a0cen + 1
else:
    a0cen1 = a[(n-2)//2]+a[n//2]
    b0cen1 = b[(n-2)//2]+b[n//2]
    nn = int(b0cen1 -a0cen1 +1)

print(nn)

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

low = [0]*n
high = [0]*n

for i in range(n):
    a, b = [int(x) for x in input().split(" ")]
    low[i] = a
    high[i] = b

low.sort()
high.sort()

if n%2 == 1:
    print(high[n//2]-low[n//2]+1)
else:
    x = (low[(n-1)//2] + low[n//2])/2
    y = (high[(n-1)//2] + high[n//2])/2
    print(int(2*y - 2*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:
    a_min=(A[n//2-1]+A[n//2])/2
    b_max=(B[n//2-1]+B[n//2])/2
    print(int(1+(b_max-a_min)/0.5))
else:
    a_min=A[n//2]
    b_max=B[n//2]
    print(int(b_max-a_min)+1)

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


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

    A.sort()
    B.sort()

    if n % 2 == 1:
        left = A[n // 2]
        right = B[n // 2]
    else:
        m = n // 2 - 1
        left = A[m] + A[m + 1]
        right = B[m] + B[m + 1]

    ans = right - left + 1
    print(ans)

if __name__ == '__main__':
    main()

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

A.sort()
B.sort()

if N % 2 == 0:
    median_max = B[N//2-1] + B[N//2]
    median_min = A[N//2-1] + A[N//2]
    print(median_max - median_min + 1)
else:
    print(B[N//2] - A[N//2] + 1)

Solution (Python):
import statistics
import math

N = int(input())
listA = [0] * N
listB = [0] * N
idx = 0
for i in range(N):
  listA[idx],listB[idx] = map(int, input().split())
  idx += 1

medianA = 0
medianB = 0
ans = 0
if N%2 == 0:
  medianA = statistics.median(listA)
  medianB = statistics.median(listB)
  ans = (medianB - medianA) * 2 + 1
else:
  medianA = statistics.median(listA)
  medianB = statistics.median(listB)
  ans = medianB - medianA + 1

print(int(ans))

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

A = [a for a, b in AB]
B = [b for a, b in AB]

A.sort()
B.sort()

if N % 2:
    ma = B[N // 2]
    mi = A[N // 2]
else:
    ma = B[N // 2 - 1] + B[N // 2]
    mi = A[N // 2 - 1] + A[N // 2]

print(ma - mi + 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:
    mi = a[n//2-1] + a[n//2]
    ma = b[n//2-1] + b[n//2]
    print(ma - mi + 1)
else:
    mi = a[n//2]
    ma = b[n//2]
    print(ma - mi + 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 :
    print(b[n//2] - a[n//2] + 1)
    exit(0)

def m_r(c):
    return (c[n//2] + c[n//2 - 1])

z = m_r(b) - m_r(a) + 1
print(z)

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

res = 0

if n % 2 == 1:
    midA = A[n // 2]
    midB = B[n // 2]
    if midB >= midA:
        res = midB - midA + 1
    else:
        res = 0
else:
    midA = A[n // 2 - 1] + A[n // 2] 
    midB = B[n // 2 - 1] + B[n // 2]
    if midB >= midA:
        res = midB - midA + 1
    else:
        res = 0
print(res)

Solution (Python):
def resolve():
	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)
	
	if N%2==1: 
		i = int((N-1)/2)
		median_min = sorted(A)[i]
		median_max = sorted(B)[i]
	else:
		i_0 = int((N/2)-1)
		i_1 = int(N/2)
		ordered_A = sorted(A)
		ordered_B = sorted(B)
		median_min = ordered_A[i_0] + ordered_A[i_1] 
		median_max = ordered_B[i_0] + ordered_B[i_1]
	print(median_max - median_min +1)
    
resolve()

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

Solution (Python):

import sys, io, os, re
import bisect
from pprint import pprint
from math import sin, cos, pi, radians, sqrt, floor
from copy import copy, deepcopy
from collections import deque
from fractions import gcd
from functools import reduce

def array1(n): return [0] * n
def array2(n, m): return [[0] * m for x in range(n)]
def array3(n, m, l): return [[[0] * l for y in xrange(m)] for x in xrange(n)]

n = int(sys.stdin.readline().strip())
a = array1(n)
b = array1(n)

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

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

if n % 2 == 1:
    print(int(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):
from statistics import median
n=int(input())
A,B=[],[]
for _ in range(n):
  a,b=map(int,input().split())
  A.append(a*2)
  B.append(b*2)
ma,mb = int(median(A)),int(median(B))

if n%2 == 0:
  print(mb-ma+1)
else:
  print((mb-ma)//2+1)

Solution (Python):
def main():
    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 == 1:
        
        mid = N // 2
        print(maxs[mid] - mins[mid] + 1)

    else:
        mid1 = N // 2
        mid2 = mid1 - 1
        smallest = mins[mid1] + mins[mid2]
        largest = maxs[mid1] + maxs[mid2]
        print(largest - smallest + 1)


if __name__ == '__main__':
    main()

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

sorted_A = A
sorted_B = B

if N % 2 != 0:
  center_A = sorted_A[N//2]
  center_B = sorted_B[N//2]
  print(center_B - center_A + 1)
else:
  center_A = (sorted_A[N//2-1] + sorted_A[N//2]) / 2
  center_B = (sorted_B[N//2-1] + sorted_B[N//2]) / 2
  print(int((center_B - center_A)*2 + 1))

Solution (Python):
def resolve():
	from statistics import median
	import sys
	input = sys.stdin.readline
	n = int(input())
	ab = [list(map(int, input().split())) for i in range(n)]
	mina = median(i[0] for i in ab)
	maxb = median(i[1] for i in ab)
	abrange = maxb - mina
	if n%2 == 0:
		print(int(abrange*2 + 1))
	else:
		print(int(abrange + 1))
resolve()

Solution (Python):
def resolve():
	from statistics import median
	import sys
	input = sys.stdin.readline
	n = int(input())
	ab = [list(map(int, input().split())) for i in range(n)]
	mina = median(i[0] for i in ab)
	maxb = median(i[1] for i in ab)
	abrange = maxb - mina
	if n%2 == 0:
		print(int(abrange/0.5 + 1))
	else:
		print(int(abrange/1 + 1))
resolve()

Solution (Python):
def main():
    import sys
    sys.setrecursionlimit(10**9)
    input = sys.stdin.readline

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

    if N % 2 == 0:
        median_min = (A[N//2 - 1] + A[N//2])
        median_max = (B[N//2 - 1] + B[N//2])
    else:
        median_min = A[N//2]
        median_max = B[N//2]
    print(median_max - median_min + 1)
    
main()

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

al = []
bl = []
for i in range(n):
    a,b = [int(i) for i in input().split()]
    al.append(a)
    bl.append(b)
    
al = sorted(al)
bl = sorted(bl)

median_a = al[n//2]if n % 2 else (al[n // 2] + al[n//2 - 1]) / 2 
median_b = bl[n//2]if n % 2 else (bl[n // 2] + bl[n//2 - 1]) / 2 

if n % 2:
    print(int((median_b - median_a + 1)))
else:
    print(int((median_b - median_a) * 2 + 1))

Solution (Python):
def main():
    n = int(input())
    A = []
    B = []
    for _ in range(n):
        a, b = map(int, input().split())
        A += [a]
        B += [b]
    A.sort()
    B.sort()

    if n % 2 == 0:
        mid_pos = n // 2
        mid_A = A[mid_pos - 1] + A[mid_pos]
        mid_B = B[mid_pos - 1] + B[mid_pos]
        cnt = mid_B - mid_A + 1
    else:
        mid_pos = (n + 1) // 2 - 1
        mid_A = A[mid_pos]
        mid_B = B[mid_pos]
        cnt = mid_B - mid_A + 1
    print(cnt)

if __name__ == "__main__":
    main()

Solution (Python):
import sys
import  math
import fractions
from collections import defaultdict
stdin = sys.stdin
     
ns = lambda: stdin.readline().rstrip()
ni = lambda: int(stdin.readline().rstrip())
nm = lambda: map(int, stdin.readline().split())
nl = lambda: list(map(int, stdin.readline().split()))


N=int(input())
min_l=[]
max_l=[]
for k in range(N):
    A,B=nm()
    min_l.append(A)
    max_l.append(B)

min_l.sort()
max_l.sort()

if(N%2==0):
    print(int(((max_l[N//2-1]+max_l[N//2])/2-(min_l[N//2-1]+min_l[N//2])/2)*2+1))    
else:
    print(((max_l[(N-1)//2])-(min_l[(N-1)//2]))+1)

Solution (Python):
def main():
    n = int(input())
    al = []
    bl = []
    for _ in range(n):
        a, b = map(int, input().split())
        al.append(a)
        bl.append(b)
    als = list(sorted(al))
    bls = list(sorted(bl))
    if n%2:
        print(bls[n//2]-als[n//2]+1)
    else:
        print(bls[n//2-1]+bls[n//2]-als[n//2]-als[n//2-1]+1)

if __name__ == "__main__":
    main()

Solution (Python):

import glob


REL_PATH = 'ABC\\169\\E'


TOP_PATH = 'C:\\AtCoder'


class Common:
    problem = []
    index = 0

    def __init__(self, rel_path):
        self.rel_path = rel_path

    def initialize(self, path):
        file = open(path)
        self.problem = file.readlines()
        self.index = 0
        return

    def input_data(self):
        try:
            IS_TEST
            self.index += 1
            return self.problem[self.index - 1]

        except NameError:
            return input()

    def resolve(self):
        pass

    def exec_resolve(self):
        try:
            IS_TEST
            for path in glob.glob(TOP_PATH + '\\' + self.rel_path + '/*.txt'):
                print("Test: " + path)
                self.initialize(path)
                self.resolve()
                print("\n\n")
        except NameError:
            self.resolve()


class Solver(Common):

    def resolve(self):

        N = int(self.input_data())
        A = [[0, 0] for i in range(N)]
        B = [[0, 0] for i in range(N)]

        for i in range(N):
            tmp = self.input_data().split()
            A[i][0] = i
            A[i][1] = int(tmp[0])
            B[i][0] = i
            B[i][1] = int(tmp[1])

        
        A_sorted = sorted(A, key=lambda x: x[1])
        B_sorted = sorted(B, key=lambda x: x[1])
        '''
        if N % 2 == 0:
            for i in range(N):
                for j in range(N):
                    if A_sorted[j][0] == i:
                        min = A_sorted[j]
                        break
                for j in range(N):
                    if B_sorted[j][0] == i:
                        max = B_sorted[j]
                        break
                

            pass
        else:
            pass
        '''
        if N % 2 == 0:
            median_min = A_sorted[int(N/2)][1] + A_sorted[int(N/2)-1][1]
            median_max = B_sorted[int(N/2)][1] + B_sorted[int(N/2)-1][1]
        else:
            median_min = A_sorted[int(N/2)][1]
            median_max = B_sorted[int(N/2)][1]
        result = median_max - median_min + 1

        print(str(result))



solver = Solver(REL_PATH)
solver.exec_resolve()

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

l = sorted(ab, key=lambda x: x[0])
r = sorted(ab, key=lambda x: x[1])

if N % 2 == 0:
    maxab = ab[(N // 2) - 1][1]
    minab = ab[N // 2][0]
    x1 = (l[(N // 2) - 1][0] + l[N // 2][0])
    x2 = (r[(N // 2) - 1][1] + r[N // 2][1])
    print(x2 - x1 + 1)

else:
    print(r[N // 2][1] - l[N // 2][0] + 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()

s, t = 0, 0
if n % 2 == 0:
    s = (A[n//2-1] + A[n//2])
    t = (B[n//2-1] + B[n//2])
else:
    s = A[n//2]
    t = B[n//2]

print(t-s+1)

Solution (Python):
def median(array):
    tmp = sorted(array)
    if len(array) % 2:
        return tmp[len(array)//2]
    else:
        return (tmp[len(array)//2] + tmp[len(array)//2 - 1]) / 2


[n], *x = [[*map(int, t.split())] for t in open(0)]
a, b = zip(*x)
if n % 2 == 0:
    print(int(2*(median(b) - median(a)) + 1))
else:
    print(median(b) - median(a) + 1)

Solution (Python):
n = int(input())
A = [[int(i) for i in input().split(" ")] for j in range(n)]
a = sorted([i[0] for i in A])
b = sorted([i[1] for i in A], reverse=True)
if n%2 == 1:
    print(b[n//2]-a[n//2]+1)
else:
    l = (a[n//2-1] + a[n//2]) / 2
    r = (b[n//2-1] + b[n//2]) / 2
    print(int((r-l)*2)+1)

Solution (Python):
how_many = int(input())
least, biggest = [],[]
for i in range(how_many):
    nums = input().split()
    nums = [int(num) for num in nums]
    least.append(nums[0])
    biggest.append(nums[1])
least.sort()
biggest.sort()
if how_many % 2 == 1:
    print(biggest[int((how_many-1) / 2)] - least[int((how_many-1) / 2)] + 1)
else:
    l = (least[int(how_many / 2)] + least[int(how_many / 2 - 1)]) / 2
    b = (biggest[int(how_many / 2)] + biggest[int(how_many / 2 - 1)]) / 2
    print(int((b-l) / 0.5 + 1))

Solution (Python):
n = int(input())
a = []
b = []
for i in range(n):
    a_, b_ = map(int, input().split())
    a.append(a_)
    b.append(b_)
a.sort()
b.sort()
if n%2 == 0:
    print(b[n//2] + b[n//2-1] - a[n//2] - a[n//2-1] + 1)
else:
    print(b[n//2] - a[n//2] + 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.sort()
B.sort()
j = n//2
if n%2 == 0:
  print((B[j]+B[j-1])-(A[j]+A[j-1])+1)
else:
  print(B[j]-A[j]+1)

Solution (Python):
n = int(input())
x = [list(map(int, input().split())) for _ in range(n)]
y = sorted(x)
z = sorted(x, key=lambda x: x[1])

if n % 2 == 1:
    print(z[n//2][1] - y[n//2][0] + 1)
else:
    a = y[n//2-1][0]
    b = y[n//2][0]
    c = z[n//2-1][1]
    d = z[n//2][1]
    e = (c + d) / 2
    f = (a + b) / 2
    print(int((e - f) * 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:
    x = a[N//2]+a[N//2-1]
    y = b[N//2]+b[N//2-1]
    print(y-x+1)

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

Solution (Python):
import sys
import math
from decimal import Decimal, ROUND_HALF_UP, ROUND_HALF_EVEN
from collections import deque
from bisect import bisect_left
from itertools import product
def I(): return int(sys.stdin.readline())
def MI(): return map(int, sys.stdin.readline().split())
def LI(): return list(map(int, sys.stdin.readline().split()))
def LI2(N): return [list(map(int, sys.stdin.readline().split())) for i in range(N)]

def LSI(): return list(map(int, list(sys.stdin.readline().rstrip())))
def LSI2(N): return [list(map(int, list(sys.stdin.readline().rstrip()))) for i in range(N)]

def ST(): return sys.stdin.readline().rstrip()
def LST(): return sys.stdin.readline().rstrip().split()
def LST2(N): return [sys.stdin.readline().rstrip().split() for i in range(N)]
def FILL(i,h): return [i for j in range(h)]
def FILL2(i,h,w): return [FILL(i,w) for j in range(h)]
def FILL3(i,h,w,d): return [FILL2(i,w,d) for j in range(h)]
def FILL4(i,h,w,d,d2): return [FILL3(i,w,d,d2) for j in range(h)]
def sisha(num,digit): return Decimal(str(num)).quantize(Decimal(digit),rounding=ROUND_HALF_UP)

MOD = 1000000007
INF = float("inf")
sys.setrecursionlimit(10**6+10)

N = I()
L = LI2(N)
A = [i[0] for i in L]
B = [i[1] for i in L]
A.sort()
B.sort()
if N%2==0:
    medA = (A[N//2-1]+A[N//2])
    medB = (B[N//2-1]+B[N//2])
    print((medB-medA)+1)
else:
    medA = A[(N-1)//2]
    medB = B[(N-1)//2]
    print(medB-medA+1)

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

ls = []
rs = []
for _ in range(n):
    x, y = map(int, input().split())
    ls.append(x)
    rs.append(y)

ls = sorted(ls)
rs = sorted(rs)

if n % 2 == 1:
    print(rs[len(rs)//2] - ls[len(ls)//2] + 1)
else:
    a = (rs[len(rs)//2-1] * 10 + rs[len(rs)//2] * 10) // 2
    b = (ls[len(ls)//2-1] * 10 + ls[len(ls)//2] * 10) // 2
    print((a - b) // 5 + 1)

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

mid_min = 0
mid_max = 0

ab.sort(key=lambda x: x[0])
if n & 1:
    mid_min = ab[n // 2][0]
else:
    mid_min = (ab[(n - 1) // 2][0] + ab[n // 2][0])

ab.sort(key=lambda x: x[1])
if n & 1:
    mid_max = ab[n // 2][1]
else:
    mid_max = (ab[(n - 1) // 2][1] + ab[n // 2][1])

print(mid_max - mid_min + 1)

Solution (Python):

from sys import stdin, stdout

def solve():
    n = int(stdin.readline().strip())

    seqA = []
    seqB = []
    for i in range(n):
        a,b = map(int, stdin.readline().split())
        seqA.append(a)
        seqB.append(b)

    seqA = sorted(seqA)
    seqB = sorted(seqB)
    mA = seqA[n//2]
    mB = seqB[n//2]
    if n%2==0:
        mA += seqA[n//2-1]
        mB += seqB[n//2-1]

    print(mB-mA+1)

solve()

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

if n%2 == 1:
    medA, medB = A[n//2], B[n//2]
    
else:
    medA = A[n//2] + A[n//2 - 1]
    medB = B[n//2] + B[n//2 - 1]

print(medB - medA + 1)

Solution (Python):
import sys
from functools import lru_cache
 

readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines
sys.setrecursionlimit(10**6)
def read():
  return int(readline())
def reads():
  return map(int, readline().split())
def mp(arg):
  return map(int,arg.split())
n=read()
a,b=[0]*n,[0]*n
for i in range(n):
  a[i],b[i]=reads()
a=sorted(a)
b=sorted(b)
if n%2==1:
  print(b[(n-1)//2]-a[(n-1)//2]+1)
else:
  mi=(a[n//2-1],a[n//2])
  ma=(b[n//2-1],b[n//2])
  res=(ma[0]+ma[1])-(mi[0]+mi[1])+1
  print(res)

Solution (Python):
from sys import stdin

def main():
  s = []
  read = stdin.readline
  N =int(read())
  data = [list(map(int,read().split(" "))) for _ in range(N)]
  A = sorted([i[0] for i in data])
  B = sorted([i[1] for i in data])
  if N%2 == 1:
    a1 = A[((N+1)//2)-1]
    b1 = B[((N+1)//2)-1]
    print(b1 - a1 + 1)
  else:
    l = []
    a1 = A[(N//2)-1]
    b1 = B[(N//2)-1]
    a2 = A[(N//2)]
    b2 = B[(N//2)]
    print(b1 + b2 + 1 - a1 - a2)
    
  
if __name__ == "__main__":
  main()