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())
A, B = [], []
for _ in range(N):
    a, b = list(map(int, input().split()))
    A.append(a)
    B.append(b)
A.sort()
B.sort()
if N%2 != 0:
    k = int(N/2)
    ans = B[k] - A[k] + 1
else:
    k = int(N/2)
    a, b = A[k]+A[k-1], B[k]+B[k-1]
    ans = b - a + 1
print(ans)

Solution (Python):
N=int(input())
A=[0 for i in range(N)]
B=[0 for i in range(N)]
for i in range(N):
    A[i],B[i]=map(int,input().split())
A.sort()
B.sort()
medmin=0
medmax=0
if N%2==0:
    medmin=(A[-1+N//2]+A[N//2])
    medmax=(B[-1+N//2]+B[N//2])
else:
    medmin=A[(N-1)//2]
    medmax=B[(N-1)//2]
print(medmax-medmin+1)

Solution (Python):
import math

import queue
from collections import deque,defaultdict
import heapq
from sys import stdin,setrecursionlimit


ipt = stdin.readline
setrecursionlimit(10**7)

def main():
    n = int(input())
    al = []
    ar = []
    bl = []
    br = []
    for i in range(n):
        a,b = map(int,ipt().split())
        ali = heapq.heappushpop(al,-a)
        ari = heapq.heappushpop(ar,a)
        heapq.heappush(ar,-ali)
        heapq.heappush(al,-ari)
        bli = heapq.heappushpop(bl,-b)
        bri = heapq.heappushpop(br,b)
        heapq.heappush(br,-bli)
        heapq.heappush(bl,-bri)
    ali = -heapq.heappop(al)
    ari = heapq.heappop(ar)
    bli = -heapq.heappop(bl)
    bri = heapq.heappop(br)
    amed2 = ali+ari
    bmed2 = bri+bli
    if n%2 == 0:
        print(bmed2-amed2+1)
    else:
        print((bmed2-amed2)//2+1)

    return

if __name__ == '__main__':
    main()

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

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

    minimum.append(a)
    maximum.append(b)



minimum.sort()
maximum.sort()

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

Solution (Python):
N = int(input())
ab = [list(map(int, input().split())) for _ in range(N)]
mnl = [ab[i][0] for i in range(N)]
mxl = [ab[i][1] for i in range(N)]
mnl.sort()
mxl.sort()

if N % 2:
  mn = mnl[N//2]
  mx = mxl[N//2]
  print(mx-mn+1)
else:
  mn = (mnl[N//2-1]+mnl[N//2])/2
  mx = (mxl[N//2-1]+mxl[N//2])/2
  d = mx-mn
  print(int(mx-mn+1+d))

Solution (Python):
from operator import itemgetter, attrgetter
N, *A = map(int, open(0).read().split())
*A, = zip(*[iter(A)]*2)

if N % 2 == 0:
    A.sort()
    mid_l = A[N//2-1][0]+A[N//2][0]
    A.sort(key=itemgetter(1))
    mid_r = A[N//2-1][1]+A[N//2][1]
    print(mid_r - mid_l+1)
else:
    A.sort()
    mid_l = A[N//2][0]
    A.sort(key=itemgetter(1))

    mid_r = A[N//2][1]
    print(mid_r - mid_l+1)

Solution (Python):
n = int(input())
a = []
b = []
for _ in range(n):
    atmp, btmp = map(int, input().split())
    a.append(atmp)
    b.append(btmp)
a.sort()
b.sort()
if n % 2 == 1:
    pos = n // 2
    print(b[pos] - a[pos] + 1)
else:
    pos = n // 2 - 1
    a1 = a[pos]
    a2 = a[pos + 1]
    b1 = b[pos]
    b2 = b[pos + 1]
    medmin = a1 + a2
    medmax = b1 + b2
    print(medmax - medmin + 1)

Solution (Python):
import sys; input = sys.stdin.buffer.readline
from collections import defaultdict
con = 10 ** 9 + 7; INF = float("inf")

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


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

	A.sort()
	B.sort()

	if N % 2 == 0:
		M = int(N // 2)
		L = A[M - 1] + A[M]
		R = B[M - 1] + B[M]
		ans = R - L + 1
		print(ans)

	else:
		M = int(N // 2)
		L = A[M]
		R = B[M]
		ans = R - L + 1
		print(ans)

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

def median(X):
  n = len(X)
  X = sorted(X)
  if len(X)%2==0:
    return (X[n//2-1]+X[n//2])*.5
  else:
    return X[n//2]

if N%2==0:
  print(int((median(B)-median(A))*2+1))
else:
  print(int(median(B)-median(A)+1))

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

Solution (Python):
def resolve():
    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)
    if n%2 == 0:
        meda = (a[n//2-1]+a[n//2])/2
        medb = (b[n // 2 - 1] + b[n // 2]) / 2
        ans = int((medb-meda)/0.5) + 1
    else:
        meda = a[n//2]
        medb = b[n//2]
        ans = int(medb-meda+1)
    print(ans)
resolve()

Solution (Python):
import sys
from operator import itemgetter

def solve():
    input = sys.stdin.readline
    N = int(input())
    X = [[int(a) for a in input().split()] for _ in range(N)]
    X.sort()
    lower = 0
    if N % 2 == 1: lower = X[N//2][0]
    else: lower = X[(N-1)//2][0] + X[N//2][0]

    X.sort(key = itemgetter(1))
    higher = 0
    if N % 2 == 1: higher = X[N//2][1]
    else: higher = X[(N-1)//2][1] + X[N//2][1]

    print(higher - lower + 1)

    return 0

if __name__ == "__main__":
    solve()

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

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

Solution (Python):
from operator import itemgetter
n=int(input())
l=[list(map(int,input().split())) for i in range(n)]
l.sort()
if n%2==1:
  x=l[n//2][0]
  l=sorted(l,key=itemgetter(1))
  y=l[n//2][1]
  print(y-x+1)
else:
  x=(l[n//2][0]+l[(n//2)-1][0])/2
  l=sorted(l,key=itemgetter(1))
  y=(l[n//2][1]+l[(n//2)-1][1])/2
  print(int((y-x)*2)+1)

Solution (Python):
import math
from functools import reduce
from collections import deque
import sys
sys.setrecursionlimit(10**7)

from statistics import median

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


def get_nums_l():
    return [ int(s) for s in input().split(" ")]


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


def get_all_int():
    return map(int, open(0).read().split())

def rangeI(it, l, r):
    for i, e in enumerate(it):
        if l <= i < r:
            yield e
        elif l >= r:
            break

def log(*args):
    print("DEBUG:", *args, file=sys.stderr)

INF = 999999999999999999999999
MOD = 10**9+7

n = int(input())
AB = []
for _ in range(n):
    AB.append(get_nums_l())
A = [ ab[0] for ab in AB ]
B = [ ab[1] for ab in AB ]

if n%2 == 1:
    min_of_med = median(A)
    max_of_med = median(B)
    print(max_of_med - min_of_med + 1)

else:
    A.sort()
    B.sort()
    min_of_med = A[n//2 - 1] + A[n//2]
    max_of_med = B[n//2 - 1] + B[n//2]
    print(max_of_med - min_of_med + 1)

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

A,B = zip(*AB)
A = sorted(list(A))
B = sorted(list(B))


if N % 2 == 1:
    mn = A[N//2]
    mx = B[N//2]
    print(mx-mn+1)
else:
    mn1 = 2*A[N//2-1]
    mn2 = 2*A[N//2]
    mn = (mn2+mn1)//2
    mx1 = 2*B[N//2-1]
    mx2 = 2*B[N//2]
    mx = (mx2+mx1)//2
    print(mx-mn+1)

Solution (Python):

def s0():return input()
def s1():return input().split()
def s2(n):return [input() for x in range(n)]
def s3(n):return [input().split() for _ in range(n)]
def s4(n):return [[x for x in s] for s in s2(n)]
def n0():return int(input())
def n1():return [int(x) for x in input().split()]
def n2(n):return [int(input()) for _ in range(n)]
def n3(n):return [[int(x) for x in input().split()] for _ in range(n)]
def t3(n):return [tuple(int(x) for x in input().split()) for _ in range(n)]
def p0(b,yes="Yes",no="No"): print(yes if b else no)



import itertools


from bisect import bisect_left,bisect_right

n=n0()
AB=n3(n)
A=[x[0] for x in AB]
B=[x[1] for x in AB]

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]
    a=(a1+a2)/2
    b=(b1+b2)/2
    ans=int((b-a+0.5)*2)
else:
    a=A[n//2]
    b=B[n//2]
    ans=b-a+1
print(ans)

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

N = int(input())
pairs = [tuple(map(int, input().split())) for _ in range(N)]
As, Bs = zip(*pairs)

if N % 2 == 0:
    sA = sorted(As)
    medA2 = sA[N//2-1] + sA[N//2]
    sB = sorted(Bs)
    medB2 = sB[N//2-1] + sB[N//2]
    print(medB2 - medA2 + 1)
else:
    sA = sorted(As)
    medA = sA[N//2]
    sB = sorted(Bs)
    medB = sB[N//2]
    print(medB - medA + 1)

Solution (Python):
def main():
    N = int(input())
    l = []
    a = []
    b = []
    for _ in range(N):
        A, B = map(int, input().split())
        l.append((A, B))
        a.append(A)
        b.append(B)
    a.sort()
    b.sort()
    if N % 2 == 1:
        return b[N//2] - a[N//2] + 1
    return b[N//2] + b[(N//2)-1] - a[N//2] - a[(N//2)-1] + 1
print(main())

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


import numpy as np

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

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

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

ab.sort()

if n % 2 == 1:
    m = (n-1) // 2
    l = ab[m][0]

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

    m = (n-1) // 2
    r = ab[m][1]
    print(r - l + 1)
else:

    m = n // 2
    l1 = ab[m-1][0]
    l2 = ab[m][0]

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

    m = n // 2
    r1 = ab[m][1]
    r2 = ab[m-1][1]
    print((r1+r2)-(l1+l2)+1)

Solution (Python):


import sys
readline = sys.stdin.readline
read = sys.stdin.read

n,*ab = map(int,read().split())


a = []
b = []
M = iter(ab)
for ai,bi in zip(M,M):
    a.append(ai)
    b.append(bi)

a.sort()
b.sort()

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


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

Solution (Python):
n = int(input())
bounds = [list(map(int, input().split())) for _ in range(n)]
upper = sorted([b[1] for b in bounds])
lower = sorted([b[0] for b in bounds])

if n % 2 == 0:
	u_mid2 = upper[n // 2 - 1] + upper[n // 2]
	l_mid2 = lower[n // 2 - 1] + lower[n // 2]
	print(u_mid2 - l_mid2 + 1)
else:
	print(upper[n // 2] - lower[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()

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

Solution (Python):
from __future__ import division, print_function

''' Hey stalker :) '''
INF = 10 ** 10
TEST_CASES = False

def main():
    n = get_int()
    starts = []
    ends = []
    for i in range(n):
        x, y = get_list()
        starts.append(x)
        ends.append(y)
    starts.sort()
    ends.sort()
    flo = n//2
    if n%2==0:
        a = starts[flo] + starts[flo-1]
        b = ends[flo] + ends[flo-1]
    else: a,b = starts[flo], ends[flo]
    print(b-a+1)


''' FastIO Footer: PyRival Library, Thanks @c1729 and contributors '''
import os
import sys
from bisect import bisect_left, bisect_right
from io import BytesIO, IOBase

if sys.version_info[0] < 3:
    from __builtin__ import xrange as range
    from future_builtins import ascii, filter, hex, map, oct, zip
BUFSIZE = 8192


class FastIO(IOBase):
    newlines = 0

    def __init__(self, file):
        self._fd = file.fileno()
        self.buffer = BytesIO()
        self.writable = "x" in file.mode or "r" not in file.mode
        self.write = self.buffer.write if self.writable else None

    def read(self):
        while True:
            b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
            if not b:
                break
            ptr = self.buffer.tell()
            self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr)
        self.newlines = 0
        return self.buffer.read()

    def readline(self):
        while self.newlines == 0:
            b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
            self.newlines = b.count(b"\n") + (not b)
            ptr = self.buffer.tell()
            self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr)
        self.newlines -= 1
        return self.buffer.readline()

    def flush(self):
        if self.writable:
            os.write(self._fd, self.buffer.getvalue())
            self.buffer.truncate(0), self.buffer.seek(0)


class IOWrapper(IOBase):
    def __init__(self, file):
        self.buffer = FastIO(file)
        self.flush = self.buffer.flush
        self.writable = self.buffer.writable
        self.write = lambda s: self.buffer.write(s.encode("ascii"))
        self.read = lambda: self.buffer.read().decode("ascii")
        self.readline = lambda: self.buffer.readline().decode("ascii")


def print(*args, **kwargs):
    """Prints the values to a stream, or to sys.stdout by default."""
    sep, file = kwargs.pop("sep", " "), kwargs.pop("file", sys.stdout)
    at_start = True
    for x in args:
        if not at_start:
            file.write(sep)
        file.write(str(x))
        at_start = False
    file.write(kwargs.pop("end", "\n"))
    if kwargs.pop("flush", False):
        file.flush()


if sys.version_info[0] < 3:
    sys.stdin, sys.stdout = FastIO(sys.stdin), FastIO(sys.stdout)



input = lambda: sys.stdin.readline().rstrip("\r\n")
get_int = lambda: int(input())
get_list = lambda: list(map(int, input().split()))

if __name__ == "__main__":
    if TEST_CASES:
        [main() for _ in range(int(input()))]
    else:
        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(reverse=True)
if n%2 == 1:
    ans = B[(n+1)//2-1]-A[(n+1)//2-1]+1
    print(ans)
else:
    y = A[n//2-1] + A[n//2]
    x = B[n//2-1] + B[n//2]
    ans = x-y+1
    print(ans)

Solution (Python):
import sys

input=sys.stdin.readline

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:
    k=N//2
    A.sort()
    B.sort()
    small=A[k]
    large=B[k]
    print(large-small+1)

else:
    k=N//2
    A.sort()
    B.sort()
    small=A[k-1]+A[k]
    large=B[k-1]+B[k]
    print(large-small+1)

Solution (Python):
n = int(input())
ab = [list(map(int, input().split())) for i in range(n)]
left = sorted([i for i,j in ab])
right = sorted([j for i,j in ab])
if n%2 == 0:
    x = left[n//2] + left[n//2-1]
    y = right[n//2] + right[n//2-1]
    ans = y-x+1
else:
    x = left[n//2]
    y = right[n//2]
    ans = y-x+1
print(ans)

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

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

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

    ab.sort(key=lambda x: x[0])
    if n % 2 == 0:
        median_min1 = ab[n//2-1][0]
        median_min2 = ab[n//2][0]
    else:
        median_min1 = ab[n//2][0]
        median_min2 = ab[n//2][0]

    ab.sort(key=lambda x: x[1])
    if n % 2 == 0:
        median_max1 = ab[n//2-1][1]
        median_max2 = ab[n//2][1]
    else:
        median_max1 = ab[n//2][1]
        median_max2 = ab[n//2][1]

    if n % 2 == 0:
        ans = (median_max1 + median_max2) - (median_min1 + median_min2) + 1
    else:
        ans = median_max1 - median_min1 + 1

    print(ans)

if __name__ == '__main__':
    main()

Solution (Python):
import statistics
n=int(input())
a=list()
b=list()
for i in range(n):
    x,y=map(int,input().split())
    a.append(x)
    b.append(y)

if n%2==0:
    print(int(statistics.median(b)*2-statistics.median(a)*2+1))
else:
    print(int(statistics.median(b)-statistics.median(a)+1))

Solution (Python):






import sys
input = sys.stdin.readline

import math

import bisect
from collections import defaultdict
from collections import deque
from functools import lru_cache






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






def I(): return int(input().strip())
def S(): return input().strip()
def IL(): return list(map(int,input().split()))
def SL(): return list(map(str,input().split()))
def ILs(n): return list(int(input()) for _ in range(n))
def SLs(n): return list(input().strip() for _ in range(n))
def ILL(n): return [list(map(int, input().split())) for _ in range(n)]
def SLL(n): return [list(map(str, input().split())) for _ in range(n)]


def P(arg): print(arg); return
def Y(): print("Yes"); return
def N(): print("No"); return
def E(): exit()
def PE(arg): print(arg); exit()
def YE(): print("Yes"); exit()
def NE(): print("No"); exit()


def DD(arg): return defaultdict(arg)



def inv(n): return pow(n, MOD-2, MOD)


kaijo_memo = []
def kaijo(n):
  if(len(kaijo_memo) > n):
    return kaijo_memo[n]
  if(len(kaijo_memo) == 0):
    kaijo_memo.append(1)
  while(len(kaijo_memo) <= n):
    kaijo_memo.append(kaijo_memo[-1] * len(kaijo_memo) % MOD)
  return kaijo_memo[n]

gyaku_kaijo_memo = []
def gyaku_kaijo(n):
  if(len(gyaku_kaijo_memo) > n):
    return gyaku_kaijo_memo[n]
  if(len(gyaku_kaijo_memo) == 0):
    gyaku_kaijo_memo.append(1)
  while(len(gyaku_kaijo_memo) <= n):
    gyaku_kaijo_memo.append(gyaku_kaijo_memo[-1] * pow(len(gyaku_kaijo_memo),MOD-2,MOD) % MOD)
  return gyaku_kaijo_memo[n]

def nCr(n,r):
  if(n == r):
    return 1
  if(n < r or r < 0):
    return 0
  ret = 1
  ret = ret * kaijo(n) % MOD
  ret = ret * gyaku_kaijo(r) % MOD
  ret = ret * gyaku_kaijo(n-r) % MOD
  return ret


def factorization(n):
  arr = []
  temp = n
  for i in range(2, int(-(-n**0.5//1))+1):
    if temp%i==0:
      cnt=0
      while temp%i==0: 
        cnt+=1 
        temp //= i
      arr.append([i, cnt])
  if temp!=1:
    arr.append([temp, 1])
  if arr==[]:
    arr.append([n, 1])
  return arr


def make_divisors(n):
  divisors = []
  for i in range(1, int(n**0.5)+1):
    if n % i == 0:
      divisors.append(i)
      if i != n // i: 
        divisors.append(n//i)
  return divisors


def make_primes(N):
  max = int(math.sqrt(N))
  seachList = [i for i in range(2,N+1)]
  primeNum = []
  while seachList[0] <= max:
    primeNum.append(seachList[0])
    tmp = seachList[0]
    seachList = [i for i in seachList if i % tmp != 0]
  primeNum.extend(seachList)
  return primeNum


def gcd(a, b):
    while b:
        a, b = b, a % b
    return a


def lcm(a, b):
    return a * b // gcd (a, b)


def count_bit(n):
  count = 0
  while n:
    n &= n -1
    count += 1
  return count


def base_10_to_n(X, n):
  if X//n:
    return base_10_to_n(X//n, n)+[X%n]
  return [X%n]

def base_n_to_10(X, n):
  return sum(int(str(X)[-i-1])*n**i for i in range(len(str(X))))


def int_log(n, a):
  count = 0
  while n>=a:
    n //= a
    count += 1
  return count




N = I()
data = ILL(N)
data.sort()
data2 = sorted(data,key = lambda x:x[1])

if N%2 == 1:
  print(data2[N//2][1]-data[N//2][0]+1)
  
if N%2 == 0:
  sita = data[N//2-1][0]+data[N//2][0]
  ue = data2[N//2-1][1]+data2[N//2][1]
  print(ue-sita+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=sorted(a)
b=sorted(b)
if n%2==1:
  ans=b[n//2]-a[n//2]+1
else:
  ma=b[n//2-1]+b[n//2]
  mi=a[n//2-1]+a[n//2]
  ans=ma-mi+1
print(ans)

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

Solution (Python):
n,*ab = map(int,open(0).read().split())
a = ab[::2]
b = ab[1::2]
a.sort()
b.sort(reverse=True)

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

print(int(ans))

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

if n % 2 == 1:
    x.sort()
    l = x[n // 2][0]
    x.sort(key=lambda x: -x[1])
    r = x[n // 2][1]
    print(r - l + 1)

else:
    x.sort()
    l1 = x[n // 2 - 1][0]
    l2 = x[n // 2][0]
    x.sort(key=lambda x: -x[1])
    r1 = x[n // 2 - 1][1]
    r2 = x[n // 2][1]
    print(r1 + r2 - l1 - l2 + 1)

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

def main():
    N = int(readline())
    m = map(int,read().split())
    AB = list(zip(m,m))

    A = [ab[0] for ab in AB]
    B = [ab[1] for ab in AB]

    A.sort()
    B.sort()

    
    
    

    if N % 2 == 1:
        Amed = A[N // 2]
        Bmed = B[N // 2]

        print(Bmed - Amed + 1)
    else:
        Amed = A[N // 2] + A[N // 2 - 1]
        Bmed = B[N // 2] + B[N // 2 - 1]

        print(Bmed - Amed + 1)

if __name__ == '__main__':
    main()

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

al.sort()
bl.sort(reverse=True)

if n % 2 == 0:
    print((bl[n//2-1] - al[n//2-1])+((bl[n//2] - al[n//2])+1))
else:
    print(bl[n//2] - al[n//2]+1)

Solution (Python):
def solve():
    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(reverse=True)
    if N%2==1:
        mid = (N+1)//2-1
        ans = B[mid]-A[mid]+1
    else:
        mid1 = N//2-1
        mid2 = N//2
        ans = (B[mid1]+B[mid2])-(A[mid1]+A[mid2])+1
    return ans
print(solve())

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

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

mi = sorted([A[i][0] for i in range(N)])
ma = sorted([A[i][1] for i in range(N)])

if N % 2 == 0:
    mi2 = mi[N//2-1] + mi[N//2]
    ma2 = ma[N//2-1] + ma[N//2]
else:
    mi2 = mi[N//2]
    ma2 = ma[N//2]

print(ma2 - mi2 + 1)

Solution (Python):
import sys
sys.setrecursionlimit(300000)

def I(): return int(sys.stdin.readline())
def MI(): return map(int, sys.stdin.readline().split())
def LMI(): return list(map(int, sys.stdin.readline().split()))
MOD = 10 ** 9 + 7
INF = float('inf')


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

def med(arr):
    n = N
    arr.sort()
    if n % 2 == 0:
        return (arr[n//2-1] + arr[n//2]) / 2
    else:
        return arr[n//2]

meda = med(A)
medb = med(B)
if N % 2 != 0:
    print(int(max(meda, medb) - min(meda, medb) + 1))
else:
    print(int(2 * medb - 2 * meda + 1))

Solution (Python):
N=int(input())
AB=[list(map(int,input().split())) for i in range(N)]
from statistics import median
A,B=zip(*AB)
x,y=median(A),median(B)
print(int(y-x+1) if N%2 else int((y-x)*2)+1)

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

start = []
end = []

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

start.sort()
end.sort()

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

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

if N % 2 == 0:
    h = H[N // 2 - 1] + H[N // 2]
    l = L[N // 2 - 1] + L[N // 2]
    ans = h - l + 1
else:
    h = H[N//2]
    l = L[N//2]
    ans = h - l + 1

print(ans)

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

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

if n % 2 == 1:
    ab.sort()
    min_val = ab[n//2][0]
    ab.sort(key=lambda x: -x[1])
    max_val = ab[n//2][1]
    print(max_val - min_val + 1)
else:
    ab.sort()
    min_val = ab[n//2][0] + ab[n//2 - 1][0]
    ab.sort(key=lambda x: -x[1])
    max_val = ab[n//2][1] + ab[n//2 - 1][1]
    print(max_val - min_val + 1)

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