peterverebics/CodeNet_Python_118 huggingface dataset:
def e_count_median():
    N = int(input())
    # Intervals = [[int(i) for i in input().split()] for j in range(N)]
    Min, Max = [], []
    for _ in range(N):
        a, b = [int(i) for i in input().split()]
        Min.append(a)
        Max.append(b)

    if N % 2 == 0:
        return sum(Max) - sum(Min) + 1

    Min.sort()
    Max.sort()
    median_min, median_max = Min[N // 2], Max[N // 2]
    return median_max - median_min + 1

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

AB.sort()
if N % 2 == 0:
  l1 = AB[N//2][0] 
  l2 = AB[N//2 - 1][0]
else:
  l = AB[N//2][0]
AB.sort(key = lambda x: x[1])
if N % 2 == 0:
  r1 = AB[N//2][1] 
  r2 = AB[N//2 - 1][1]
else:
  r = AB[N//2][1]
  
if N % 2 == 0:
  ans = (r1 + r2) - (l1 + l2)
  ans *= 2
  ans -= 1
  print(ans)
else:
  print(r - l + 1)
import sys
sys.setrecursionlimit(10 ** 7)
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(reverse=True)

mia = a[n//2]
mab = b[n//2]

if n%2==0:
    print((mab-mia+1)*2+1)
else:
    print(mab-mia+1)
n = int(input())
ab = [tuple(map(int, input().split())) for _ in range(n)]
print(3)
#print(n, ab)
#90
#9900
from sys import stdin
from decimal import Decimal
N = int(stdin.readline().rstrip())
A = []
B = []
for i in range(N):
    a,b = [int(x) for x in stdin.readline().rstrip().split()]
    A.append(a)
    B.append(b)
    
A.sort()
B.sort()
amin = min(A)
amax = max(A)
bmin = min(amax,min(B))
bmax = max(B)

if N % 2 == 0:
    ans = 2 * (bmin-amin) + 2 * (bmax-amax)
    print(ans//2+1)
else:
    ans = B[N//2] - A[N//2] + 1
    print(ans)
n = int( input())
A = []
B = []

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

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

if n % 2 == 0:
  i1 = n // 2 - 1
  i2 = n // 2
  print(int(( B[ i2 ] + B[ i1 ] ) / 2 - ( A[ i2 ] + A[ i1 ] ) / 2 )  * 2 + 1 )
else:
  i = ( n + 1 ) // 2 - 1
  print( B[ i ] - A[ i ] + 1 )
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(ans)
import sys

readline = sys.stdin.readline
N = int(readline())
A = []
B = []
for _ in range(N):
    a, b = map(int, readline().split())
    A.append(a)
    B.append(b)
A.sort()
B.sort()
if N % 2 == 0:
    mi = (A[N//2-1]+A[N//2])//2
    ma = (B[N//2-1]+B[N//2])//2
    ans = (ma-mi)*2+1
else:
    mi = A[(N+1)//2-1]
    ma = B[(N+1)//2-1]
    ans = (ma-mi)+1
print(ans)
import math


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


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:
    print(y - x + 1)
else:
    print(math.ceil(y) - math.floor(x) + 1)
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))        # mn, mn + 1, mn + 2, ..., mx
else:
    print(int(mx - mn * 2 + 1))    # mn, mn + 0.5, mn + 1, ..., mx
import itertools
N = int(input())
AB = [list(map(int, input().split())) for n in range(N)]

if N % 2 == 0:
  k1 = int(N/2-1)
  k2 = int(N/2)
  minM = AB[k1][0] + AB[k2][0]
  maxM = AB[k1][1] + AB[k2][1]
  print(maxM-minM+1)
else:
  k = int((N+1)/2)-1
  A = AB[k][0]
  B = AB[k][1]
  print(B-A+1)
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((mb-ma)*2+1)
n = int(input())
info = [list(map(int, input().split())) for i in range(n)]

if n % 2 == 1:
    info = sorted(info)
    l = info[n // 2][0]
    info = sorted(info)[::-1]
    r = info[n // 2][1]
    print(r - l + 1)

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

A = sorted(A, key=lambda x:x[0])
A = sorted(A, key=lambda x:x[1])
# print(A)
n = 1
if N%2 == 1:
    a, b = A[(N-1)//2]
    print(b-a+1)
else:
    a1, b1 = A[N//2]
    a2, b2 = A[N//2-1]
    if (b1-a1)%2 == 0 or (b2-a2)%2 == 0:
        n += 1
    print(b1-a1+b2-a2+n)
n = int( input())
A = []
B = []

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

sorted( A )
sorted( B )

if n % 2 == 0:
  i1 = n // 2 - 1
  i2 = n // 2
  print( (( B[ i2 ] + A[ i2 ] ) - ( B[ i1 ] + A[ i1 ] )) // 2 + 1 )
else:
  i = ( n + 1 ) // 2 - 1
  print( B[ i ] - A[ i ] + 1 )
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(abs(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(abs(center_B - center_A)*2 + 1)
N = int(input())
A = []
B = []
for _ in range(N):
    a, b = map(int, input().split())
    A.append(a)
    B.append(b)

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)
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=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)
from heapq import heappush
n=int(input())
A=[]
B=[]
for i in range(n):
  a,b=map(int,input().split())
  heappush(A,a)
  heappush(B,b)
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)
from sys import stdin
input = stdin.readline

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

ab.sort()

ran = []

for a, b in ab:
    ran.append(b - a + 1)

ran.sort()

if N % 2 == 0:
    a1, b1 = ab[N // 2 - 1]
    a2, b2 = ab[N // 2]
    xa = (a2 + a1) / 2
    xb = (b2 + b1) / 2
    print(xa, xb)
    print((xb - xa) * 2 - 1)
else:
    xa, xb = ab[N // 2]
    print(xb - xa + 1)
#!/usr/bin python3
# -*- coding: utf-8 -*-

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

if __name__ == '__main__':
    main()
import statistics
n=int(input())
r=set([])
x=[[]]*n
for i in range(n):
  a,b=list(map(int,input().split()))
  x[i]=[a,b]
r0=statistics.median([x[z][0] for z in range(n)])
r1=statistics.median([x[z][1] for z in range(n)])
if ((r1*2) % 2)>0:
  mult=2
else:
  mult=1
#print(r0)
#print(r1)
mult=int((r1-r0)+mult)
print(mult)
  #r=r|
import sys

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

n = N // 2 if N % 2 != 0 else N // 2 - 1
left = AB[n][0]

AB.sort(key=lambda x: x[1], reverse=True)
right = AB[n][1]

print(max(0, right - left + 1))
N = int(input())
ABlist = [list(map(int, input().split())) for _ in range(N)]
ABlist.sort()
def sa(arr):
    return arr[1] - arr[0]
if N % 2 == 1:
    print(sa(ABlist[(N+1)//2-1])+1)
else:
    print(sa(ABlist[N//2-1]) + sa(ABlist[N//2]) + 1)
n = int(input())
ab = [list(map(int, input().split())) for _ in range(n)]
ab.sort()
l = ab[(n+1)//2-1][0]
ab.sort(key=lambda x:x[1], reverse=True)
r = ab[(n+1)//2-1][1]

print(r-l+1)
n = int(input())
x = []
for i in range(n):
    x.extend(list(map(int,input().split())))

x.sort()
if n%2==0:
    p = (n+1)//2 -1
else:
    p = n//2
print(x[-p-1]-x[p]+1)
import math

N = int(input())
list_A, list_B = list(), list()
for _ in range(N):
    A, B = map(int, input().split())
    list_A.append(A)
    list_B.append(B)

list_A.sort()
list_B.sort()

if N%2==0:
    tmp, tmp1 = N//2-1, N//2
    _min = math.floor(min(list_A[tmp], list_A[tmp1]))
    _max = math.ceil(max(list_B[tmp], list_B[tmp1]))
else:
    tmp = N//2
    _min = math.floor(list_A[tmp])
    _max = math.ceil(list_B[tmp])

print(_max-_min+1)
from copy import deepcopy
N = int(input())
ABs = [list(map(int,input().split())) for i in range(N)]
ABs_desc = deepcopy(ABs)

ABs.sort(key=lambda x:(x[0],-x[1]))
ABs_desc.sort(key=lambda x: (-x[1],x[0]))

if N%2:
    A1,B1 = ABs[N//2]
    A2,B2 = ABs_desc[N//2]
    print(B2-A1+1)
else:
    A1,B1 = ABs[(N-1)//2]
    A2,B2 = ABs_desc[(N-1)//2]
    print(B1+B2-A1-A2+1)
n = int(input())
ab = [list(map(int,input().split())) for _ in range(n)]

mi = 1
ma = 10 ** 9 + 1

for i in range(n):
    if ab[i][0] == ab[i][1]:
        continue
    elif ma == ab[i][0]:
        ma = ab[i][1]
    else:
        mi = max(mi,ab[i][0])
        ma = min(ma,ab[i][1])
print(ma-mi+1)
N = int(input())
AB = []
min_list = []
max_list = []
for i in range(N):
    AB.append(list(map(int,input().split())))
    min_list.append(AB[i][0])
    max_list.append(AB[i][1])

if N % 2 != 0:
    print(max_list[N//2] - min_list[N//2] + 1)
else:
    max_center = (max_list[N//2-1] + max_list[N//2])/2
    min_center = (min_list[N//2-1] + min_list[N//2])/2
    print(max_center*2 - min_center*2 + 1)
n = int(input())
x = []
for i in range(n):
    a, b = map(int, input().split())
    if a==b:
        x.append(a)
        continue
    x.extend([a, b])

x.sort()
if n%2==0:
    p = (n+1)//2 -1
else:
    p = n//2
print(x[-p-1]-x[p]+1)
import math


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


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:
    print(y - x + 1)
else:
    print(int(y - x) + 2)
import statistics

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

if n%2 == 0:
    leftId = statistics.median_high(left) - statistics.median_low(left)
    rightId = statistics.median_high(right) - statistics.median_low(right)
    print((rightId - leftId)*2 + 1)
else:
    leftId = statistics.median(left)
    rightId = statistics.median(right)
    while True:
        x = 1
    print(rightId - leftId + 1 - aaa)
import copy
n = int(input())
ab = [list(map(int,input().split())) for _ in range(n)]
ab2 = copy.deepcopy(ab)
ab = sorted(ab, key=lambda x:x[0])
ab2 = sorted(ab2, key=lambda x:x[1])
if n % 2 == 1:
    m = ab[n//2][0]
    M = ab2[n//2][1]
    print(max(0,M-m+1))
else:
    m = (ab[n//2][0]+ab[n//2-1][0])/2
    M = (ab[n//2][1]+ab[n//2-1][1])/2
    print(m,M)
    print(int((M-m)*2+1))
# Count median
N=int(input())
m=[]
M=[]
for i in range(N):
    x,y=map(int,input().split())
    m.append(x)
    M.append(y)
m.sort()
M.sort()

if N%2!=0:
    mini=m[N//2]
    maxi=M[-N//2]

    print(maxi-mini+1)
else:
    mini=m[N//2]
    maxi=M[-N//2]
    if maxi>=mini:
        print((maxi-mini)*2+1)
    else:
        print(0)
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&1:
        print(b[n//2]-a[n//2]+1)
    else:
        print(b[n//2-1]+b[n//2]-a[n//2]+1)
            
if __name__ == "__main__":
    main()
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 = int(mb-ma)
else:
    ans = 2*int(mb-ma) + 1

print(ans)
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][1]
    c = z[n//2-1][0]
    d = z[n//2][1]
    e = (b + d) / 2
    f = (a + c) / 2
    print(int((e - f) * 2) + 1)
n = int(input())
lister = []
for i in range(n):
    lister.append([int(i) for i in input().split()])
 
if n % 2 == 1:
    lister.sort(key=lambda x:x[0])
    miner = lister[n//2][0]
    lister.sort(key=lambda x:x[1])
    maxer = lister[n//2][1]
    print(maxer- miner + 1)
else:
    lister.sort(key=lambda x:x[0])
    miner = lister[n//2 - 1][0]
    lister.sort(key=lambda x:x[1])
    maxer = lister[n//2][1]
    print(1 + (maxer- miner))
from statistics import*
(n,),*t=[map(int,t.split())for t in open(0)]
a,b=map(median,zip(*t))
print(int(b-a)*(2-n%2)+1)
N = int(input())
left = []
right = []
for _ in range(N):
    l, r = map(int, input().split())
    left.append(l)
    right.append(r)
left.sort()
right.sort()
if N%2==0:
    for i, (l, r) in enumerate(zip(left, right)):
        if i==N//2:
            L = (l+r)
        if i==N//2+1:
            R = (l+r)
            print((R-L)+1)
else:
    for i, (l, r) in enumerate(zip(left, right), 1):
        if i==N//2+1:
            print(r-l+1)
import sys

def input():
    return sys.stdin.readline()[:-1]

n = int(input())
li = [input().split() for _ in range(n)]
a_li = sorted([int(x[0]) for x in li])
b_li = sorted([int(x[1]) for x in li], reverse=True)
if n%2 == 0:
    hn = int(n/2)
else:
    hn = int((n+1)/2)
s = b_li[hn-1]+b_li[hn]-a_li[hn-1]-a_li[hn]+1
print(s)
N=int(input())
List=[list(map(int,input().split())) for i in range(N)]

A=[]
B=[]
for i in range(N):
    A.append(List[i][0])
    B.append(List[i][1])

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

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

print(ans)
n=int(input())
AB=[]
C=[]
for _ in range(n):
    a,b = map(int,input().split())
    #AB.append((a,b))
    C.append(a)
    C.append(b)
C.sort()
#AB = sorted(AB,key=lambda x: x[1])
med = n//2

if n%2 != 0:
    p,q=C[2*n-n//2-1],C[n//2]
    print(q-p+1)
else:
    p,q,r,s = C[n//2-1],C[n//2],C[2*n-n//2-1],C[2*n-n//2]
    print(int(((s+r)/2 - (p+q)/2)*2 + 1))
n = int(input())
al = []
bl = []
for _ in range(n):
    a, b = map(int, input().split()) 
    al.append(a)
    bl.append(b)

# print(al,bl)
al.sort()
bl.sort()


print(bl[n//2] - al[n//2] + 1)
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-a)*2+1)
def main():
    N = int(input())
    A,B = [0]*N,[0]*N
    for i in range(N):
        A[i],B[i] = map(int, input().split())
    Xmin = min(A)
    Xmax = max(B)
    
    print(int((Xmax-Xmin)*2-1))


main()
N = int(input())
AS = []
BS = []
for i in range(N):
    A, B = [int(x) for x in input().split()]
    AS.append(A)
    BS.append(B)
AS2 = AS[:]
AS2.sort()

BS2 = BS[:]
BS2.sort()

if N % 2 == 0:
    lower = AS2[N // 2]
    upper = BS2[-N // 2]
    print((upper - lower) * 2 + 1)
else:
    lower = AS2[N // 2]
    upper = BS2[-N // 2]
    print(upper - lower + 1)
import statistics

N = int(input())
A = []
B = []
for i in range(N):
    a, b = map(int, input().split())
    A.append(a)
    B.append(b)
Am = statistics.median(A)
Bm = statistics.median(B)

if N % 2 == 0:
    print(round(2 * Bm - Am) + 1)
else:
    print(Bm - Am + 1)
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 = (b + d) / 2
    f = (a + c) / 2
    print(int((e - f) * 2) + 1)
N = int(input())
A = []
B = []
for i in range(N):
    a, b = map(int,input().split())
    A.append(a)
    B.append(b)

A.sort()
B.sort()

if N % 2 == 1:
    AA = A[(N+1)//2]
    BB = B[(N+1)//2-1] 
    print(BB-AA+1)
else:
    AA = (A[N//2-1]+A[N//2])//2
    BB = (B[N//2-2]+B[N//2-2])//2
    print(BB-AA+1)
import statistics

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

if n%2 == 0:
    leftId = statistics.median_high(left) - statistics.median_low(left)
    rightId = statistics.median_high(right) - statistics.median_low(right)
    print((rightId - leftId)*2 + 1)
else:
    leftId = statistics.median(left)
    rightId = statistics.median(right)
    aaa = 0

    print(rightId - leftId + 1 - aaa)
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)          # mn, mn + 1, mn + 2, ..., mx
else:
    print(int(mx - mn) * 2 + 1)    # mn, mn + 0.5, mn + 1, ..., mx
N = int(input())
A = dict()
B = dict()
for i in range(N):
    a, b = map(int, input().split())
    A[i] = a
    B[i] = b
A_sort = sorted(A.items(), key=lambda x:x[1])
B_sort = sorted(B.items(), key=lambda x:x[1])
if N % 2 == 1:
    print(B[(N+1)//2-1]-A[(N+1)//2-1]+1)
else:
    B_min = B[N//2-1]
    A_min = A[N//2-1]
    A_max = A[N//2]
    B_max = B[N//2]
    print(A_max+B_max-A_min-B_min+1)
N = int(input())
X_vec = {}
for n in range(N):
    A, B = list(map(int,input().split()))

    X_vec[n] =set(range(A,B+1))
if N %2 !=0:
    candi = X_vec[((N + 1) // 2) - 1]

    print(len(candi))
else:
    ans = []
    small= X_vec[N//2 -1]
    large = X_vec[N//2]
    print(len(small | large))
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:
    l=A[(n-1)//2]
    r=B[(n-1)//2]
    print(r-l+1)
else:
    l=(A[n//2]+A[n//2-1])/2
    r=(B[n//2]+B[n//2-1])/2
    print(int((r-l))*2+1)
n = int(input())
ab = sorted([list(map(int,input().split())) for i in range(n)])
ab_b = sorted(ab,key=lambda x:x[1])
if n%2==1:
    ans = ab_b[-2][1]-ab[1][0]+1
    
else:
    x1 = ab_b[-1][1]+ab[0][1]/2
    x2 = ab_b[-1][0]+ab[0][0]/2
    ans = int((x1-x2)*2)
print(ans)
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))


print(minmedian, maxmedian)
n = int(input())
l = [list(map(int, input().split())) for i in range(n)]

a = sorted(l, key=lambda x:x[0])
b = sorted(l, key=lambda x:x[1])

if n % 2 == 1:
  print(b[n//2][1] - a[n//2][0] +1)
else:
  print((b[n//2][1] - a[n//2-1][0]+1)*(b[n//2][1] - a[n//2-1][0])//2)
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()
ans = 0
if n%2 == 1:
  ans = b[n//2]-a[n//2]+1
else:
  ans = (b[n//2]-a[n//2])*2+1
print (ans)
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((b - a) * 2 + 1)
n = int(input())

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

c = [ab[i][1]-ab[i][0] for i in range(n)]

if n%2 == 1:
    center = n//2
    answer = ab[center][1]-ab[center][0]+1
else:
    center = [n//2-1,n//2]
    answer1 = ab[center[0]][1] - ab[center[0]][0]+1
    answer2 = ab[center[1]][1] - ab[center[1]][0]+1
    answer = answer1*answer2 - max(0,ab[center[0]][1]-min(ab[center[0]][0],ab[center[1]][1]))

print(answer)
import sys
input = sys.stdin.readline
N = int(input())
AB = [[int(i) for i in input().split()] for _ in range(N)]
AB.sort()
ans = 1
if N % 2:
    left = AB[N // 2]
    AB.sort(reverse=True,key=lambda x:x[1])
    right = AB[N // 2]
    ans += right[1]-left[0]

else:
    left = AB[N//2-1]
    AB.sort(reverse=True,key=lambda x:x[1])
    right = AB[N // 2-1]
    ans += left[1]+right[1] - (left[0]+right[0])

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

a = sorted([x[0] for x in ab])
b = sorted([y[1] for y in ab])

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

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

if n % 2 == 1:
    mid = int(n/2)+1
    print(l[mid-1][-1]-l[mid-1][0]+1)

else:
    mid_l = int(n/2)
    mid_r = int(n/2)+1
    
    print(l[mid_r-1][-1]-l[mid_l-1][0]+1)
n = int(input())
al = []
bl = []
for _ in range(n):
    a, b = map(int, input().split()) 
    al.append(a)
    bl.append(b)

# print(al,bl)
al.sort()
bl.sort()


if n%2 == 1:
    print(bl[n//2] - al[n//2] + 1)
else:
    print(bl[n//2] - al[n//2-1] + 1)
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()
from math import ceil
from heapq import heappush as p
n=int(input())
A=[]
B=[]
c=ceil(n//2)
for i in range(n):
  a,b=map(int,input().split())
  p(A,a)
  p(B,b)
if n%2:
  print(B[c]-A[c]+1)
else:
  print(int(((B[c]+B[c-1])/2-(A[c]+A[c-1])/2)//0.5+1))
from math import *
from statistics import median
N=int(input())
A,B=[],[]
for i in range(N):
    a,b=map(int,input().split())
    A.append(a);B.append(b)
A.sort();B.sort()
if N%2:
    ans=median(B)-median(A)+1
else:
    ans=(median(B)-median(A))*2+1
print(ans)
n = int(input())
X = []
for i in range(n):
    X.append(list(map(int, input().split())))

ans = 0
if n % 2 == 0:
    A = X[n // 2 - 1][1]
    B = X[n // 2][0]
    a = X[n // 2 - 1][1] - X[n // 2 - 1][0] + 1
    b = X[n // 2][1] - X[n // 2][0] + 1
    if B <= A:
        ans += (A - B + 1) * a -(A-B+1)
        b -= A - B + 1
    
    ans += a * b
else:
    ans = X[(n + 1) // 2 - 1][1] - X[(n + 1) // 2 - 1][0] + 1
    
print(ans)
N = int(input())
l = []
for _ in range(N):
  A, B = list(map(int,input().split()))
  l.append([A,B])

lp = sorted(l, key = lambda x:x[0])
fir = lp[(N-1)//2][0]
lm = sorted(l, key= lambda x:x[0], reverse = True)
fim = lm[(N-1)//2][-1]
print(abs(fir-fim)+1)
from sys import stdin
from sys import setrecursionlimit
import bisect
setrecursionlimit(10 ** 7)

n = int(input())
li = []
lin = []

for _ in range(n):
    a,b = map(int,stdin.readline().rstrip().split())
    li.append([a,b])
    lin.append([b,a])

li.sort()
lin.sort()

if n%2 == 1:
    print(lin[n//2][0]-li[n//2][0]+1)
else:
    print(lin[n//2][0]-li[(n-1)//2][0]+1)
n=int(input())
ar=[list(map(int,input().split())) for i in range(n)]
if n%2==1:
    print(ar[n//2][1]-ar[n//2][0]+1)
else:
    x=(ar[n//2][0]+ar[n//2-1][0])/2
    y=(ar[n//2][1]+ar[n//2-1][1])/2
    print(int(y-x)*2+1)