AtCoder Beginner Contest 169 - Count Median

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-----
2
1 2
2 3

-----Sample Output-----
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}.

Difficulty: MEDIUM

Starter code:

Solutions:
n = int(input())
l = []
r = []
m = []
for i in range(n):
	(a, b) = map(int, input().split())
	l.append(a)
	r.append(b)
l.sort()
r.sort()
if n % 2 == 1:
	print(r[(n - 1) // 2] - l[(n - 1) // 2] + 1)
else:
	print(r[n // 2 - 1] + r[n // 2] - l[n // 2] - l[n // 2 - 1] + 1)


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)


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


n = int(input())
a = []
b = []
for i in range(n):
	(x, y) = map(int, input().split())
	a += [x]
	b += [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)


N = int(input())
A = [0] * N
B = [0] * N
(x, y) = (0, 0)
for i in range(N):
	(x, y) = map(int, input().split())
	A[i] = x
	B[i] = y
A.sort()
B.sort()
if N & 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)


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


import statistics
N = int(input())
A = []
B = []
for i in range(N):
	(a, b) = map(int, input().split())
	A.append(a)
	B.append(b)
ma = statistics.median(A)
mb = statistics.median(B)
if N % 2 == 0:
	print(int((mb - ma) * 2 + 1))
else:
	print(int(mb - ma + 1))


import sys
read = sys.stdin.buffer.read
(N, *AB) = map(int, read().split())
(A, B) = (AB[::2], AB[1::2])
A.sort()
B.sort(reverse=True)
pos = (N + 1) // 2 - 1
if N % 2 == 1:
	ans = B[pos] - A[pos] + 1
else:
	ans = B[pos] + B[pos + 1] - (A[pos] + A[pos + 1]) + 1
print(ans)


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


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


from statistics import median
n = int(input())
a = [None] * n
b = [None] * n
for i in range(n):
	(a[i], b[i]) = map(int, input().split())
if n % 2 == 1:
	print(abs(median(b) - median(a)) + 1)
else:
	print(int(abs(median(b) - median(a)) * 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 == 0:
	MIN = A[N // 2 - 1] + A[N // 2]
	MAX = B[N // 2 - 1] + B[N // 2]
	ans = MAX - MIN + 1
else:
	MIN = A[N // 2]
	MAX = B[N // 2]
	ans = MAX - MIN + 1
print(ans)


n = int(input())
a = []
b = []
for i in range(n):
	(tmpa, tmpb) = map(int, input().split())
	a.append(tmpa)
	b.append(tmpb)
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)


N = int(input())
AB = [list(map(int, input().split())) for _ in range(N)]
A = sorted([ab[0] * (2 - N % 2) for ab in AB])
B = sorted([ab[1] * (2 - N % 2) for ab in AB])
if N % 2 == 1:
	print(B[N // 2] - A[N // 2] + 1)
else:
	print((B[N // 2] + B[N // 2 - 1]) // 2 - (A[N // 2] + A[N // 2 - 1]) // 2 + 1)


def main(N, lines):
	a = sorted([line[0] for line in lines])
	b = sorted([line[1] for line in lines])
	if N % 2 == 1:
		mi = a[N // 2]
		ma = b[N // 2]
		print(int(ma - mi + 1))
	else:
		mi = a[N // 2 - 1] + a[N // 2]
		ma = b[N // 2 - 1] + b[N // 2]
		print(int(ma - mi + 1))
N = int(input())
lines = []
for i in range(N):
	lines.append(list(map(int, input().split())))
main(N, lines)


N = int(input())
A = [tuple(map(int, input().split())) for _ in range(N)]
B = A[:]
A.sort(key=lambda x: x[0])
B.sort(key=lambda x: x[1])
if N % 2:
	print(B[N // 2][1] - A[N // 2][0] + 1)
else:
	print(B[N // 2][1] + B[N // 2 - 1][1] - (A[N // 2][0] + A[N // 2 - 1][0]) + 1)


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


from numpy import *
t = loadtxt(open(0), skiprows=1)
(a, b) = median(t, 0)
print(int((b - a) * (2 - len(t) % 2)) + 1)


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()
cnt = 0
if N % 2 == 1:
	l = A[N // 2]
	r = B[N // 2]
	cnt = r - l + 1
else:
	l = A[N // 2 - 1] + A[N // 2]
	r = B[N // 2 - 1] + B[N // 2]
	cnt = r - l + 1
print(cnt)


n = int(input())
m = []
M = []
for _ in range(n):
	(x, y) = map(int, input().split())
	m.append(x)
	M.append(y)
m = sorted(m)
M = sorted(M)
z = n // 2
if n % 2 == 1:
	a = m[z]
	b = M[z]
	print(b - a + 1)
else:
	a = m[z] + m[z - 1]
	b = M[z] + M[z - 1]
	print(b - a + 1)


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


(N, *AB) = map(int, open(0).read().split())
A = sorted((a for a in AB[::2]))
B = sorted((b for b in AB[1::2]))
if N % 2:
	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)


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


import numpy as np
N = int(input())
A = []
B = []
for i in range(N):
	(a, b) = [int(x) for x in input().split()]
	A.append(a)
	B.append(b)
C = np.array(A)
D = np.array(B)
m_inf = np.median(C)
m_sup = np.median(D)
if N % 2 == 0:
	ans = 2 * m_sup - 2 * m_inf + 1
else:
	ans = m_sup - m_inf + 1
print(int(ans))


(n, *t) = map(int, open(0).read().split())
A = sorted(t[0::2])
B = sorted(t[1::2])
if n % 2 == 0:
	kl = n // 2 - 1
	kr = n // 2
else:
	kl = n // 2
	kr = n // 2
(lm, lM) = (A[kl], A[kr])
(rm, rM) = (B[kl], B[kr])
(L, R) = (0, 0)
if n % 2 == 0:
	L = lm + lM
	R = rm + rM
	a = R - L + 1
else:
	a = rm - lm + 1
print(a)


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()
(l, h) = (A[n // 2], B[n // 2])
if n % 2 == 0:
	l += A[n // 2 - 1]
	h += B[n // 2 - 1]
print(h - l + 1)


def solve(n, a, b):
	l = (n + 1) // 2 - 1
	r = l + 1 + (n % 2 == 0)
	lb = sum(sorted(a)[l:r])
	ub = sum(sorted(b)[l:r])
	return ub - lb + 1
n = int(input())
a = [0] * n
b = [0] * n
for i in range(n):
	(a[i], b[i]) = map(int, input().split())
print(solve(n, a, b))


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 - a[n // 2 - 1])

def __starting_point():
	main()
__starting_point()


n = int(input())
a = sorted([list(map(int, input().split())) for i in range(n)])
b = sorted(a, 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][1] + b[n // 2][1] - (a[n // 2 - 1][0] + a[n // 2][0]) + 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()
if len(A) % 2 != 0:
	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)


N = int(input())
t = N // 2
(la, lb) = ([], [])
for _ in range(N):
	(A, B) = list(map(int, input().split()))
	la.append(A)
	lb.append(B)
la.sort()
lb.sort()
print(lb[t] - la[t] + 1 if N % 2 else lb[t - 1] - la[t] + lb[t] - la[t - 1] + 1)


from statistics import median
n = int(input())
ab = [list(map(int, input().split())) for _ in range(n)]
a = [i for (i, j) in ab]
b = [j for (i, j) in ab]
if n % 2 == 1:
	print(abs(median(b) - median(a)) + 1)
else:
	print(int(abs(median(b) - median(a)) * 2) + 1)


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


from statistics import median
X = []
X1 = []
N = int(input())
for i in range(N):
	(a, b) = map(int, input().split())
	X.append(a)
	X1.append(b)
m1 = median(X)
m2 = median(X1)
if len(X) % 2:
	print(int(m2 - m1 + 1))
else:
	print(int(2 * (m2 - m1) + 1))


from math import ceil, floor, factorial, gcd, sqrt, log2, cos, sin, tan, acos, asin, atan, degrees, radians, pi, inf
from itertools import accumulate, groupby, permutations, combinations, product, combinations_with_replacement
from collections import deque, defaultdict, Counter
from bisect import bisect_left, bisect_right
from operator import itemgetter
from heapq import heapify, heappop, heappush
from queue import Queue, LifoQueue, PriorityQueue
from copy import deepcopy
from time import time
from functools import reduce
import string
import sys
sys.setrecursionlimit(10 ** 7)

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

def INT():
	return int(input())

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

def MAP1():
	return map(lambda x: int(x) - 1, input().split())

def LIST():
	return list(MAP())

def LIST1():
	return list(MAP1())

def solve():
	N = INT()
	a = []
	b = []
	for i in range(N):
		(A, B) = MAP()
		a.append(A)
		b.append(B)
	a.sort()
	b.sort()
	if N % 2 == 1:
		am = a[(N + 1) // 2 - 1]
		bm = b[(N + 1) // 2 - 1]
		ans = bm - am + 1
	else:
		am = (a[N // 2 - 1] + a[N // 2]) / 2
		bm = (b[N // 2 - 1] + b[N // 2]) / 2
		ans = int((bm - am) * 2 + 1)
	print(ans)

def __starting_point():
	solve()
__starting_point()


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


import statistics
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 == 1:
	med_min = A[N // 2]
	med_max = B[N // 2]
	print(med_max - med_min + 1)
else:
	med_min_db = A[N // 2] + A[N // 2 - 1]
	med_max_db = B[N // 2] + B[N // 2 - 1]
	print(med_max_db - med_min_db + 1)


n = int(input())
a = [0] * n
b = [0] * n
for i in range(n):
	(aa, bb) = list(map(int, input().split()))
	a[i] = aa
	b[i] = bb
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)


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, reverse=True)
if n % 2 == 1:
	x = 1 + n // 2
	print(b[x - 1] - a[x - 1] + 1)
else:
	x = n // 2
	print(b[x - 1] + b[x] - a[x - 1] - a[x] + 1)


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


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)


from statistics import median
N = int(input())
As = [0] * N
Bs = [0] * N
for i in range(N):
	(As[i], Bs[i]) = map(int, input().split())
med_A = median(As)
med_B = median(Bs)
if N % 2:
	print(med_B - med_A + 1)
else:
	print(int((med_B - med_A) * 2) + 1)


n = int(input())
l = []
r = []
for _ in range(n):
	(a, b) = list(map(int, input().split()))
	l.append(a)
	r.append(b)
l.sort()
r.sort()
if n % 2 == 1:
	l_mid = l[n // 2]
	r_mid = r[n // 2]
	print(r_mid - l_mid + 1)
else:
	l_mid = (l[n // 2] + l[n // 2 - 1]) / 2
	r_mid = (r[n // 2] + r[n // 2 - 1]) / 2
	print(int((r_mid - l_mid) * 2) + 1)


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


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)


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


n = int(input())
s = []
e = []
for i in range(n):
	(a, b) = map(int, input().split())
	s.append(a)
	e.append(b)
s = sorted(s)
e = sorted(e, reverse=True)
x = n // 2
if n % 2 == 1:
	ans = e[x] - s[x] + 1
else:
	ts = (s[x] + s[x - 1]) / 2
	te = (e[x] + e[x - 1]) / 2
	ans = (te - ts) // 0.5 + 1
print(int(ans))


(n, *l) = map(int, open(0).read().split())
(m, M) = (sorted(l[::2]), sorted(l[1::2]))
d = n // 2
print(M[d] - m[d] + 1 + (M[d - 1] + -m[d - 1]) * (n % 2 ^ 1))


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


import statistics
N = int(input())
min_all = []
max_all = []
for _ in range(N):
	(a, b) = list(map(int, input().split()))
	min_all.append(a)
	max_all.append(b)
min_median = statistics.median(min_all)
max_median = statistics.median(max_all)
if N % 2:
	ans = max_median - min_median + 1
else:
	ans = int((max_median - min_median + 0.5) * 2)
print(ans)


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)


n = int(input())
(A, B) = map(list, zip(*[map(int, input().split()) for i in range(n)]))
A.sort()
B.sort()
if n & 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)


n = int(input())
ab = [map(int, input().split()) for _ in range(n)]
(a, b) = [list(i) for i in zip(*ab)]
c = sorted(a)
d = sorted(b)
ans = 0
if n % 2 == 1:
	ans = d[(n - 1) // 2] - c[(n - 1) // 2] + 1
else:
	ans = d[n // 2] + d[n // 2 - 1] - c[n // 2] - c[n // 2 - 1] + 1
print(ans)


from sys import stdin
import sys
import math
from functools import reduce
import functools
import itertools
from collections import deque, Counter
from operator import mul
import copy
import heapq
n = int(input())
aa = []
bb = []
for i in range(n):
	(a, b) = list(map(int, input().split()))
	aa.append(a)
	bb.append(b)
aa.sort()
bb.sort()
if n % 2 == 0:
	m_a = aa[n // 2 - 1] + aa[n // 2]
	m_b = bb[n // 2 - 1] + bb[n // 2]
	print(m_b - m_a + 1)
	return
else:
	median_a = aa[n // 2]
	median_b = bb[n // 2]
	print(median_b - median_a + 1)
	return


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)


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


import sys
from itertools import chain
import numpy as np

def solve(N: int, A: 'List[int]', B: 'List[int]'):
	A = np.sort(A)
	B = np.sort(B)
	if N % 2 == 1:
		l = A[N // 2]
		r = B[N // 2]
		return r - l + 1
	else:
		l2 = A[N // 2 - 1] + A[N // 2]
		r2 = B[N // 2 - 1] + B[N // 2]
		return r2 - l2 + 1

def main():
	tokens = chain(*(line.split() for line in sys.stdin))
	N = int(next(tokens))
	AB = np.array(list(map(int, tokens)), dtype=np.int32)
	A = AB[0::2]
	B = AB[1::2]
	answer = solve(N, A, B)
	print(answer)

def __starting_point():
	main()
__starting_point()


import statistics
N = int(input())
A = []
B = []
for i in range(N):
	(a, b) = list(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())
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)


N = int(input())
L = []
for i in range(N):
	(A, B) = list(map(int, input().split()))
	L.append((A, B))
L1 = sorted(L, key=lambda x: x[0])
L2 = sorted(L, key=lambda x: x[1])
if N % 2 == 1:
	n = N // 2
	print(L2[n][1] - L1[n][0] + 1)
else:
	n = N // 2
	m = (L1[n - 1][1] + L1[n][1]) / 2
	print(L2[n - 1][1] + L2[n][1] - L1[n - 1][0] - L1[n][0] + 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(int(ans))


from statistics import median as m
n = int(input())
a = [0] * n
b = [0] * n
for i in range(n):
	(x, y) = map(int, input().split())
	a[i] = x
	b[i] = y
x = m(a)
y = m(b)
if n % 2 == 0:
	x *= 2
	y *= 2
print(int(y - x + 1))


ni = lambda : int(input())
nm = lambda : list(map(int, input().split()))
nl = lambda : list(map(int, input().split()))
n = ni()
mins = []
maxs = []
for i in range(n):
	(a, b) = nm()
	mins.append(a)
	maxs.append(b)
smn = sorted(mins)
smx = sorted(maxs)
if n % 2 == 1:
	mn = smn[(n + 1) // 2 - 1]
	mx = smx[(n + 1) // 2 - 1]
	print(round(mx - mn + 1))
else:
	mn = (smn[n // 2 - 1] + smn[n // 2]) / 2.0
	mx = (smx[n // 2 - 1] + smx[n // 2]) / 2.0
	print(round((mx - mn) * 2 + 1))


N = int(input())
AB = [list(map(int, input().split())) for _ in range(N)]
(A, B) = map(list, zip(*AB))
A.sort()
B.sort()

def median(a):
	n = N
	return a[(n + 1) // 2 - 1] if n % 2 else (a[n // 2 - 1] + a[n // 2]) / 2
A_mid = median(A)
B_mid = median(B)
r = int((B_mid - A_mid) * [2, 1][N % 2]) + 1
print(r)


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)


import sys
import math
import os
import itertools
import string
import heapq
import _collections
from collections import Counter
from collections import defaultdict
from collections import deque
from functools import lru_cache
import bisect
import re
import queue
import decimal

class Scanner:

	@staticmethod
	def int():
		return int(sys.stdin.readline().rstrip())

	@staticmethod
	def string():
		return sys.stdin.readline().rstrip()

	@staticmethod
	def map_int():
		return [int(x) for x in Scanner.string().split()]

	@staticmethod
	def string_list(n):
		return [Scanner.string() for i in range(n)]

	@staticmethod
	def int_list_list(n):
		return [Scanner.map_int() for i in range(n)]

	@staticmethod
	def int_cols_list(n):
		return [Scanner.int() for i in range(n)]
MOD = int(1000000000.0) + 7
INF = int(1000000000000000.0)

def solve():
	N = Scanner.int()
	A = [0 for _ in range(N)]
	B = [0 for _ in range(N)]
	for i in range(N):
		(A[i], B[i]) = Scanner.map_int()
	A.sort()
	B.sort()
	if N % 2 == 0:
		mA = A[N // 2] + A[N // 2 - 1]
		mB = B[N // 2] + B[N // 2 - 1]
		print(mB - mA + 1)
	else:
		mA = A[N // 2]
		mB = B[N // 2]
		print(mB - mA + 1)

def main():
	solve()

def __starting_point():
	main()
__starting_point()


a = []
b = []
n = int(input())
for _ 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 - 1) // 2] - a[(n - 1) // 2] + 1)
	return
print(b[n // 2] + b[n // 2 - 1] - a[n // 2] - a[n // 2 - 1] + 1)


N = int(input())
A = []
B = []
for _ in range(N):
	(a, b) = map(int, input().split())
	A.append(a)
	B.append(b)
from statistics import median
Am = median(A)
Bm = median(B)
if N % 2 == 1:
	ans = Bm - Am + 1
	print(ans)
else:
	ans = int((Bm - Am) * 2 + 1)
	print(ans)


(n, *ab) = map(int, open(0).read().split())
a = sorted(ab[::2])
b = sorted(ab[1::2])
m = (n - 1) // 2
if n % 2 == 0:
	print(b[m] - a[m] + b[m + 1] - a[m + 1] + 1)
else:
	print(b[m] - a[m] + 1)


n = int(input())
arr_a = []
arr_b = []
for i in range(n):
	(a, b) = map(int, input().split())
	arr_a.append(a)
	arr_b.append(b)
arr_a.sort()
arr_b.sort()
if n % 2 == 1:
	print(arr_b[n // 2] - arr_a[n // 2] + 1)
else:
	median_a = arr_a[int(n / 2 - 1)] + arr_a[int(n / 2)]
	median_b = arr_b[int(n / 2 - 1)] + arr_b[int(n / 2)]
	print(median_b - median_a + 1)


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)


N = int(input())
A = []
B = []
for _ in range(N):
	(a, b) = [int(i) for i in input().split()]
	A.append(a)
	B.append(b)
A.sort()
B.sort()
if N % 2 == 1:
	M = (N - 1) // 2
	print(B[M] - A[M] + 1)
	exit()
M = N // 2 - 1
L = N // 2
print(B[M] + B[L] - A[M] - A[L] + 1)


N = int(input().strip())
AB_list = [list(map(int, input().rstrip().split())) for i in range(N)]
(A_list, B_list) = list(map(list, list(zip(*AB_list))))
A_list.sort()
B_list.sort()
if N % 2 == 0:
	Med_A = A_list[(N - 1) // 2] + A_list[(N - 1) // 2 + 1]
	Med_B = B_list[(N - 1) // 2] + B_list[(N - 1) // 2 + 1]
else:
	Med_A = A_list[(N - 1) // 2]
	Med_B = B_list[(N - 1) // 2]
Med_range = Med_B - Med_A + 1
print(Med_range)


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


N = int(input())
(A, B) = ([], [])
for _ in range(N):
	(a, b) = map(int, input().split())
	A.append(a)
	B.append(b)
(A, B) = (sorted(A), sorted(B))
m1 = A[N // 2] + A[(N - 1) // 2]
m2 = B[N // 2] + B[(N - 1) // 2]
print((m2 - m1) // (N % 2 + 1) + 1)


import sys
input = sys.stdin.readline

def S():
	return input().rstrip()

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

def MI():
	return list(map(int, input().split()))
n = I()
ab = list(map(int, sys.stdin.read().split()))
a = ab[::2]
b = ab[1::2]
a.sort()
b.sort()
if n % 2 == 0:
	m1 = (a[n // 2 - 1] + a[n // 2]) / 2
	m2 = (b[n // 2 - 1] + b[n // 2]) / 2
	print(int((m2 - m1) * 2 + 1))
else:
	m1 = a[n // 2]
	m2 = b[n // 2]
	print(m2 - m1 + 1)


n = int(input())
min = []
max = []
for i in range(n):
	(a, b) = map(int, input().split())
	min.append(a)
	max.append(b)
min.sort()
max.sort()
if n % 2 == 0:
	print(max[n // 2] + max[n // 2 - 1] - (min[n // 2] + min[n // 2 - 1]) + 1)
else:
	print(max[n // 2] - min[n // 2] + 1)


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


N = int(input())
AB = [[int(i) for i in input().split()] for _ in range(N)]
(A, B) = map(list, zip(*AB))
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)


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


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())
(a, b) = ([], [])
for i in range(n):
	(c, d) = map(int, input().split())
	a.append(c)
	b.append(d)
a.sort()
b.sort(reverse=True)
if n % 2 == 1:
	ac = a[(n + 1) // 2 - 1]
	bc = b[(n + 1) // 2 - 1]
	ans = bc - ac
else:
	ac = a[n // 2 - 1] + a[n // 2]
	bc = b[n // 2 - 1] + b[n // 2]
	ans = bc - ac
print(ans + 1)


n = int(input())
AB = [list(map(int, input().split())) for _ in range(n)]
(A, B) = zip(*AB)
A = sorted(A)
B = sorted(B)
if n % 2:
	a_m = A[(n - 1) // 2]
	b_m = B[(n - 1) // 2]
else:
	a_m = A[n // 2] + A[n // 2 - 1]
	b_m = B[n // 2] + B[n // 2 - 1]
ans = b_m - a_m + 1
print(ans)


n = int(input())
(s, t) = ([], [])
for i in range(n):
	(a, b) = map(int, input().split())
	s.append(a)
	t.append(b)
s = sorted(s)
t = sorted(t)
if n % 2 == 0:
	print(t[n // 2 - 1] + t[n // 2] - s[n // 2 - 1] - s[n // 2] + 1)
else:
	print(t[n // 2] - s[n // 2] + 1)


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 == 1:
	print(bl[n // 2] - al[n // 2] + 1)
else:
	print(bl[n // 2 - 1] - al[n // 2] + bl[n // 2] - al[n // 2 - 1] + 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()
if n % 2 == 1:
	print(b[n // 2] - a[n // 2] + 1)
else:
	front = n // 2
	back = (n - 1) // 2
	print(b[front] + b[back] - (a[front] + a[back]) + 1)


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


import sys
input = sys.stdin.readline
n = int(input())
ab = [list(map(int, input().split())) for i in range(n)]
(l, r) = list(zip(*ab))
l = list(l)
r = list(r)
l.sort()
r.sort()
if n % 2:
	print(r[n // 2] - l[n // 2] + 1)
else:
	print(r[n // 2 - 1] + r[n // 2] - (l[n // 2 - 1] + l[n // 2]) + 1)


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)


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

def median(li):
	if n % 2 == 1:
		return li[n // 2]
	else:
		return sum(li[n // 2 - 1:n // 2 + 1])
print(median(B) - median(A) + 1)


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


def solve():
	N = int(input())
	(Ls, Rs) = ([], [])
	for i in range(N):
		(a, b) = list(map(int, input().split()))
		(Ls.append(a), Rs.append(b))
	(Ls.sort(), Rs.sort())
	ans = 0
	if N % 2 == 1:
		l = Ls[N // 2]
		r = Rs[N // 2]
		ans = r - l + 1
	else:
		l2 = Ls[N // 2 - 1] + Ls[N // 2]
		r2 = Rs[N // 2 - 1] + Rs[N // 2]
		ans = r2 - l2 + 1
	print(ans)

def __starting_point():
	solve()
__starting_point()


import numpy as np
(N, *AB) = list(map(int, open(0).read().split()))
min_med = np.median([a for a in AB[::2]])
max_med = np.median([b for b in AB[1::2]])
if N % 2:
	print(int(max_med - min_med) + 1)
else:
	print(int(max_med * 2 - min_med * 2) + 1)


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)


import statistics
import math
N = int(input())
A = [0] * N
B = [0] * N
for i in range(N):
	(A[i], B[i]) = map(int, input().split())
AM = statistics.median(A)
BM = statistics.median(B)
if N % 2 == 1:
	ANS = BM - AM + 1
else:
	ANS = int((BM - AM) * 2 + 1)
print(ANS)


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


import copy
import random
import bisect
import fractions
import math
import sys
import collections
mod = 10 ** 9 + 7
sys.setrecursionlimit(mod)
d = collections.deque()

def LI():
	return list(map(int, sys.stdin.readline().split()))
N = int(input())
A = [0 for i in range(N)]
B = [0 for i in range(N)]
for i in range(N):
	(a, b) = LI()
	A[i] = a
	B[i] = b
A.sort()
B.sort()
if N % 2 == 1:
	min_mid = A[(N - 1) // 2]
else:
	min_mid = (A[N // 2 - 1] + A[N // 2]) / 2
if N % 2 == 1:
	max_mid = B[(N - 1) // 2]
else:
	max_mid = (B[N // 2 - 1] + B[N // 2]) / 2
if N % 2 == 0:
	print(int((max_mid - min_mid) / 0.5 + 1))
else:
	print(math.ceil(max_mid) - math.floor(min_mid) + 1)


n = int(input())
a = []
b = []
for _ in range(n):
	(ai, bi) = map(int, input().split())
	a.append(ai)
	b.append(bi)
a.sort()
b.sort()
ma = 0
mb = 0
if n % 2:
	ma = a[n // 2]
	mb = b[n // 2]
else:
	ma = a[n // 2] + a[n // 2 - 1]
	mb = b[n // 2] + b[n // 2 - 1]
print(mb - ma + 1)


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


import sys
import numpy as np
input = sys.stdin.readline
read = sys.stdin.read

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

def main():
	np.set_printoptions(threshold=20)
	N = int(input())
	AB = np.array(read().split(), dtype=np.int)
	A = AB[0::2]
	B = AB[1::2]
	A.sort()
	B.sort()
	if N % 2 == 1:
		n = N // 2
		print(B[n] - A[n] + 1)
	else:
		n = N // 2
		print(B[n] + B[n - 1] - (A[n] + A[n - 1]) + 1)

def __starting_point():
	main()
__starting_point()


from operator import itemgetter
n = int(input())
AB = [list(map(int, input().split())) for _ in range(n)]
sortA = sorted(AB, key=itemgetter(0))
sortB = sorted(AB, key=itemgetter(1))
if n % 2 == 1:
	print(sortB[n // 2][1] - sortA[-n // 2][0] + 1)
else:
	print(int(((sortB[n // 2][1] + sortB[n // 2 - 1][1]) / 2 - (sortA[n // 2][0] + sortA[n // 2 - 1][0]) / 2) / (1 / 2) + 1))


def main():
	n = int(input())
	(A, B) = ([], [])
	for _ in range(n):
		(a, b) = list(map(int, input().split()))
		A.append(a)
		B.append(b)
	(A, B) = (sorted(A), sorted(B))
	if n % 2 == 0:
		(a_m, b_m) = (A[n // 2] + A[n // 2 - 1], B[n // 2] + B[n // 2 - 1])
		print(b_m - a_m + 1)
	else:
		(a_m, b_m) = (A[n // 2], B[n // 2])
		print(b_m - a_m + 1)

def __starting_point():
	main()
__starting_point()


n = int(input())
(v1, v2) = ([], [])
for _ in range(n):
	(a, b) = map(int, input().split())
	v1.append(a)
	v2.append(b)
v1.sort()
v2.sort()
if n & 1:
	m = n // 2
	print(v2[m] - v1[m] + 1)
else:
	m = n // 2
	print(v2[m - 1] - v1[m - 1] + v2[m] - v1[m] + 1)


N = int(input())
A = [0] * N
B = [0] * N
for n in range(N):
	(A[n], B[n]) = map(int, input().split())
A.sort()
B.sort()
if N % 2 == 1:
	print(B[N // 2] - A[N // 2] + 1)
else:
	Am = (A[N // 2] + A[N // 2 - 1]) / 2
	Bm = (B[N // 2] + B[N // 2 - 1]) / 2
	print(int((Bm - Am) * 2) + 1)


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


from statistics import median
N = int(input())
A = []
B = []
for _ in range(N):
	(a, b) = map(int, input().split())
	A.append(a)
	B.append(b)
m = median(A)
M = median(B)
if N % 2 == 0:
	m *= 2
	M *= 2
print(int(M - m + 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:
	ans = b[n // 2] - a[n // 2] + 1
else:
	x1 = a[n // 2] + a[n // 2 - 1]
	x2 = b[n // 2] + b[n // 2 - 1]
	ans = x2 - x1 + 1
print(ans)


import sys
input = sys.stdin.readline
sys.setrecursionlimit(10 ** 7)
from collections import Counter, deque
from collections import defaultdict
from itertools import combinations, permutations, accumulate, groupby, product
from bisect import bisect_left, bisect_right
from heapq import heapify, heappop, heappush
from math import floor, ceil, pi, factorial
from operator import itemgetter

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

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

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

def LI2():
	return [int(input()) for i in range(n)]

def MXI():
	return [[LI()] for i in range(n)]

def SI():
	return input().rstrip()

def printns(x):
	print('\n'.join(x))

def printni(x):
	print('\n'.join(list(map(str, x))))
inf = 10 ** 17
mod = 10 ** 9 + 7
n = I()
lis1 = []
lis2 = []
for i in range(n):
	(a, b) = MI()
	lis1.append(a)
	lis2.append(b)
lis1.sort()
lis2.sort()
if n % 2 == 1:
	med1 = lis1[n // 2]
	med2 = lis2[n // 2]
	print(med2 - med1 + 1)
if n % 2 == 0:
	med1 = lis1[n // 2 - 1] + lis1[n // 2]
	med2 = lis2[n // 2 - 1] + lis2[n // 2]
	print(med2 - med1 + 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()
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)


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)


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)


import statistics
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:
	print(statistics.median(B) - statistics.median(A) + 1)
else:
	print(int(statistics.median(B) * 2 - statistics.median(A) * 2 + 1))


N = int(input())
A = []
B = []
for i in range(N):
	(_A, _B) = [int(i) for i in input().split(' ')]
	A.append(_A)
	B.append(_B)
A = sorted(A)
B = sorted(B)
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)


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


def main():
	import sys
	input = sys.stdin.readline
	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 & 1:
		j = (N - 1) // 2
		ans = B[j] - A[j] + 1
		print(ans)
		return
	j = N // 2 - 1
	k = N // 2
	ans = B[j] + B[k] - (A[j] + A[k]) + 1
	print(ans)
	return

def __starting_point():
	main()
__starting_point()


import statistics
import math
N = int(input())
min_x = []
max_x = []
for i in range(N):
	(A, B) = list(map(int, input().split()))
	min_x.append(A)
	max_x.append(B)
min_x.sort()
max_x.sort()
result = []
if len(min_x) % 2 == 0:
	min_median = min_x[len(min_x) // 2 - 1] + min_x[len(min_x) // 2]
	max_median = max_x[len(min_x) // 2 - 1] + max_x[len(min_x) // 2]
	print(len(list(range(math.floor(min_median), math.ceil(max_median) + 1))))
else:
	min_median = min_x[len(min_x) // 2]
	max_median = max_x[len(min_x) // 2]
	print(max_median - min_median + 1)


n = int(input())
a = []
b = []
for i in range(n):
	(x, y) = map(int, input().split())
	a.append(x)
	b.append(y)
import statistics as st
am = st.median(a)
bm = st.median(b)
if n % 2 == 1:
	print(int(bm - am + 1))
else:
	print(int((bm - am) * 2 + 1))


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


import sys
from collections import deque, defaultdict, Counter
from itertools import accumulate, product, permutations, combinations
from operator import itemgetter
from bisect import bisect_left, bisect_right
from heapq import heappop, heappush
from math import ceil, floor, sqrt, gcd, inf
from copy import deepcopy
import numpy as np
import scipy as sp
INF = inf
MOD = 1000000007
n = int(input())
A = [[int(i) for i in input().split()] for j in range(n)]
tmp = 0
res = 0
x = np.median(np.array(A), axis=0)
if n % 2 == 0:
	res = int((x[1] - x[0]) * 2 + 1)
else:
	res = int(x[1] - x[0] + 1)
print(res)


n = int(input())
a = [0] * n
b = [0] * n
for i in range(n):
	(a[i], b[i]) = map(int, input().split())
a.sort(reverse=True)
b.sort()
if n % 2:
	a_med = a[n // 2]
	b_med = b[n // 2]
	print(b_med - a_med + 1)
else:
	a_med = (a[n // 2 - 1] + a[n // 2]) / 2
	b_med = (b[n // 2 - 1] + b[n // 2]) / 2
	print(int((b_med - a_med) * 2) + 1)


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


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


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)


from statistics import median
la = []
lb = []
for _ in range(int(input())):
	(a, b) = map(int, input().split())
	la.append(a)
	lb.append(b)
ma = median(la)
mb = median(lb)
if len(la) % 2:
	print(int(mb - ma + 1))
else:
	print(int(2 * (mb - ma) + 1))


N = int(input())
A = [list(map(int, input().split())) for i in range(N)]
if N % 2 == 1:
	minA = sorted([row[0] for row in A])
	maxA = sorted([row[1] for row in A])
	medA = minA[int(N / 2)]
	medB = maxA[int(N / 2)]
	print(medB - medA + 1)
else:
	minA = sorted([row[0] for row in A])
	maxA = sorted([row[1] for row in A])
	medA = (minA[int(N / 2 - 1)] + minA[int(N / 2)]) / 2
	medB = (maxA[int(N / 2 - 1)] + maxA[int(N / 2)]) / 2
	print(int((medB - medA) * 2 + 1))


def med(l):
	t = len(l)
	if t % 2:
		return l[t // 2]
	else:
		return (l[t // 2] + l[t // 2 - 1]) / 2
n = int(input())
a = []
b = []
for i in range(n):
	(x, y) = list(map(int, input().split()))
	a += [x]
	b += [y]
a.sort()
b.sort()
if n % 2 == 0:
	print(int((med(b) - med(a)) * 2) + 1)
else:
	print(med(b) - med(a) + 1)


n = int(input())
ll = []
rr = []
for _ in range(n):
	(a, b) = map(int, input().split())
	ll.append(a)
	rr.append(b)
ll.sort()
rr.sort()
if n % 2 == 0:
	print(rr[n // 2 - 1] + rr[n // 2] - (ll[n // 2] + ll[n // 2 - 1]) + 1)
else:
	print(rr[n // 2] - ll[n // 2] + 1)


(n, *ab) = map(int, open(0).read().split())
a = ab[::2]
b = ab[1::2]
m = n // 2
a.sort()
b.sort()
ans = 0
if n & 1 == 1:
	ans = b[m] - a[m] + 1
else:
	ans = int(2 * ((b[m] + b[m - 1]) / 2 - (a[m] + a[m - 1]) / 2))
	ans += 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:
	m = A[N // 2] + A[N // 2 - 1]
	M = B[N // 2] + B[N // 2 - 1]
	print(M - m + 1)
else:
	m = A[N // 2]
	M = B[N // 2]
	print(M - m + 1)


n = int(input())
aa = []
bb = []
for _ in range(n):
	(a, b) = map(int, input().split())
	aa.append(a)
	bb.append(b)
aa = sorted(aa)[(n - 1) // 2:]
bb = sorted(bb, reverse=True)[(n - 1) // 2:]
if n % 2 == 1:
	print(abs(bb[0] - aa[0]) + 1)
else:
	print(bb[0] + bb[1] - (aa[0] + aa[1]) + 1)


import numpy as np
N = int(input())
AB = np.vstack([list(map(int, input().split())) for _ in range(N)])
meds = np.median(AB, axis=0)
if N % 2 == 0:
	print(int((meds[1] - meds[0]) * 2 + 1))
else:
	print(int(meds[1] - meds[0] + 1))


N = int(input())
Alist = []
Blist = []
for _ in range(N):
	(a, b) = map(int, input().split())
	Alist.append(a)
	Blist.append(b)
Alist.sort()
Blist.sort()
if N % 2 == 1:
	center_A = Alist[(N - 1) // 2]
	center_B = Blist[(N - 1) // 2]
	print(int(center_B - center_A + 1))
else:
	center_A = (Alist[N // 2 - 1] + Alist[N // 2]) / 2
	center_B = (Blist[N // 2 - 1] + Blist[N // 2]) / 2
	print(int(center_B * 2 - center_A * 2 + 1))


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)


n = int(input())
(a, b) = ([], [])
for i in range(n):
	inp = list(map(int, input().split()))
	a.append(inp[0])
	b.append(inp[1])
a.sort()
b.sort()
am = sum(a[(n - 1) // 2:n // 2 + 1])
bm = sum(b[(n - 1) // 2:n // 2 + 1])
print(bm - am + 1)


from statistics import median
N = int(input())
A = []
B = []
for n in range(N):
	(a, b) = map(int, input().split())
	A.append(a)
	B.append(b)
cenA = median(A)
cenB = median(B)
if N % 2 == 1:
	print(int(cenB - cenA + 1))
elif N % 2 == 0:
	print(int((cenB - cenA) * 2 + 1))
else:
	print('RE')


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


import collections
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()
(N_q, N_mod) = divmod(N, 2)
if N_mod == 1:
	ans = B[N_q] - A[N_q] + 1
else:
	ans = B[N_q - 1] - A[N_q - 1] + B[N_q] - A[N_q] + 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.sort()
B.sort()
m_l = A[N // 2] if N % 2 == 1 else A[N // 2 - 1] + A[N // 2]
m_r = B[N // 2] if N % 2 == 1 else B[N // 2 - 1] + B[N // 2]
print(m_r - m_l + 1)


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


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


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


import sys
sys.setrecursionlimit(10 ** 8)
ini = lambda : int(sys.stdin.readline())
inm = lambda : map(int, sys.stdin.readline().split())
inl = lambda : list(inm())
ins = lambda : sys.stdin.readline().rstrip()
debug = lambda *a, **kw: print('\x1b[33m', *a, '\x1b[0m', **dict(file=sys.stderr, **kw))
N = ini()
(A, B) = ([], [])
for i in range(N):
	(a, b) = inm()
	A.append(a)
	B.append(b)

def solve():
	sa = sorted(A)
	sb = sorted(B)
	if N % 2 == 1:
		return sb[N // 2] - sa[N // 2] + 1
	else:
		return sb[N // 2] + sb[N // 2 - 1] - (sa[N // 2] + sa[N // 2 - 1]) + 1
print(solve())


N = int(input())
A = [0 for _ in range(N)]
B = [0 for _ in range(N)]
import statistics
for k in range(N):
	(A[k], B[k]) = map(int, input().split())
if N % 2 == 1:
	print(statistics.median(B) - statistics.median(A) + 1)
else:
	print(int((statistics.median(B) - statistics.median(A)) * 2 + 1))


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)


import sys
input = sys.stdin.readline
N = int(input())
AB = [tuple(map(int, input().split())) for i in range(N)]
A = []
B = []
for (a, b) in AB:
	A.append(a)
	B.append(b)
A.sort()
B.sort()
if N % 2 == 0:
	m = N // 2
	b = B[m] + B[m - 1]
	a = A[m] + A[m - 1]
	print(b - a + 1)
else:
	m = N // 2
	print(B[m] - A[m] + 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)
median_a = median(A)
median_b = median(B)
if N % 2 == 0:
	print(int((median_b - median_a) * 2) + 1)
else:
	print(int(median_b - median_a) + 1)


from statistics import median
N = int(input())
A = [0] * N
B = [0] * N
for c in range(N):
	(A[c], B[c]) = list(map(int, input().split()))
A_med = median(A)
B_med = median(B)
if N % 2 == 0:
	print(round(2 * (B_med - A_med) + 1))
else:
	print(B_med - A_med + 1)


from statistics import median

def main():
	n = int(input())
	a = [0] * n
	b = [0] * n
	for i in range(n):
		(a[i], b[i]) = list(map(int, input().split()))
	ans = median(b) - median(a)
	if n % 2 == 0:
		ans *= 2
	ans = int(ans)
	ans += 1
	print(ans)

def __starting_point():
	main()
__starting_point()


import statistics
from collections import Counter
N = int(input())
A = [list(map(int, input().split(' '))) for i in range(N)]
xMIN = []
xMAX = []
for i in range(N):
	xMIN.append(A[i][0])
for j in range(N):
	xMAX.append(A[j][1])
if N % 2 != 0:
	medianMIN = statistics.median(xMIN)
	medianMAX = statistics.median(xMAX)
	print(int(medianMAX - medianMIN + 1))
else:
	medianMIN_LOW = statistics.median_low(xMIN)
	medianMIN_HIGH = statistics.median_high(xMIN)
	medianMAX_LOW = statistics.median_low(xMAX)
	medianMAX_HIGH = statistics.median_high(xMAX)
	print(medianMAX_LOW + medianMAX_HIGH - (medianMIN_LOW + medianMIN_HIGH) + 1)


N = int(input())
l = []
for _ in range(N):
	(A, B) = list(map(int, input().split()))
	l.append((A, B))
t = N // 2
tl = sorted(l)
tr = sorted(l, key=lambda x: -x[1])
if N % 2:
	print(tr[t][1] - tl[t][0] + 1)
else:
	(a1, a2) = (tl[t - 1][0], tr[t][1])
	(a3, a4) = (tl[t][0], tr[t - 1][1])
	print(a4 - a3 + a2 - a1 + 1)


import sys
import bisect

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

def main():
	N = int(input())
	A = []
	B = []
	for i in range(N):
		(a, b) = list(map(int, input().split()))
		A.append(a)
		B.append(b)
	pass
	A.sort()
	B.sort()
	if N % 2 == 0:
		n = N // 2
		mini = (A[n] + A[n - 1]) / 2
		maxi = (B[n] + B[n - 1]) / 2
		print(int((maxi - mini) * 2) + 1)
	else:
		n = N // 2
		mini = A[n]
		maxi = B[n]
		print(maxi - mini + 1)

def __starting_point():
	main()
__starting_point()


N = int(input())
AB = []
for _ in range(N):
	AB.append(list(map(int, input().split())))
A_idx = [(AB[i][0], i) for i in range(N)]
B_idx = [(AB[i][1], i) for i in range(N)]
A_idx.sort(key=lambda e: e[0])
B_idx.sort(key=lambda e: e[0])
if N % 2 == 1:
	diff = B_idx[N // 2][0] - A_idx[N // 2][0]
	print(diff + 1)
else:
	l = N // 2 - 1
	u = N // 2
	diff = B_idx[l][0] + B_idx[u][0] - (A_idx[l][0] + A_idx[u][0])
	print(diff + 1)


n = int(input())
(a, b) = ([], [])
for _ in range(n):
	tmp = list(map(int, input().split()))
	a.append(tmp[0])
	b.append(tmp[1])
a.sort()
b.sort()
if n % 2:
	print(b[(n + 1) // 2 - 1] - a[(n + 1) // 2 - 1] + 1)
else:
	print(b[n // 2 - 1] + b[n // 2] - a[n // 2 - 1] - a[n // 2] + 1)


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

def median(x):
	l = len(x)
	if l % 2 == 0:
		return (x[l // 2 - 1] + x[l // 2]) / 2
	else:
		return x[l // 2]
if N % 2 == 1:
	print(median(B) - median(A) + 1)
else:
	print(int((median(B) - median(A)) * 2 + 1))


n = int(input())
A = []
B = []
for i in range(n):
	x = [int(i) for i in input().split()]
	A.append(x[0])
	B.append(x[1])
A = sorted(A)
B = sorted(B)
if n % 2:
	med_A = A[n // 2]
	med_B = B[n // 2]
	print(abs(med_A - med_B) + 1)
else:
	med_A = A[(n - 1) // 2] + A[n // 2]
	med_B = B[(n - 1) // 2] + B[n // 2]
	print(abs(med_A - med_B) + 1)


(n, *AB) = map(int, open(0).read().split())
a = sorted(AB[::2])
b = sorted(AB[1::2])
if n % 2 == 0:
	print(b[n // 2 - 1] + b[n // 2] - a[n // 2 - 1] - a[n // 2] + 1)
else:
	print(b[(n + 1) // 2 - 1] - a[(n + 1) // 2 - 1] + 1)


import math
n = int(input())
a = [0] * n
b = [0] * n
for i in range(n):
	(a[i], b[i]) = list(map(int, input().split()))
a.sort()
b.sort()
ans = 0
h = int(n / 2)
if n % 2 == 0:
	a_harf = a[h - 1] + a[h]
	b_harf = b[h - 1] + b[h]
	ans = b_harf - a_harf + 1
else:
	ans = b[h] - a[h] + 1
print(ans)


N = int(input())
aa = []
bb = []
for i in range(N):
	(a, b) = [int(x) for x in input().split()]
	aa.append(a)
	bb.append(b)
aa.sort()
bb.sort()
if N % 2 != 0:
	print(bb[N // 2] - aa[N // 2] + 1)
else:
	print(bb[N // 2] + bb[N // 2 - 1] - aa[N // 2] - aa[N // 2 - 1] + 1)


n = int(input())
a = []
b = []
for i in range(n):
	(h, m) = list(map(int, input().split()))
	a.append(h)
	b.append(m)
a.sort()
b.sort()
if n % 2:
	k = (n - 1) // 2
	print(b[k] - a[k] + 1)
else:
	k = n // 2
	print(b[k] + b[k - 1] - (a[k] + a[k - 1]) + 1)


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:
		b = A[N // 2]
		u = B[N // 2]
		return u - b + 1
	b1 = A[N // 2 - 1]
	b2 = A[N // 2]
	u1 = B[N // 2 - 1]
	u2 = B[N // 2]
	return u1 + u2 - b1 - b2 + 1
print(solve())


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)
if n % 2 == 1:
	print(abs(median(b) - median(a)) + 1)
else:
	print(int(abs(median(b) - median(a)) * 2) + 1)


n = int(input())
al = list()
bl = list()
for i in range(n):
	(a, b) = map(int, input().split())
	al.append(a)
	bl.append(b)
al.sort()
bl.sort()
l = n // 2
if n % 2 == 0:
	print(bl[l - 1] + bl[l] - al[l - 1] - al[l] + 1)
else:
	print(bl[l] - al[l] + 1)


import statistics
N = int(input())
A = []
B = []
for _ in range(N):
	(a, b) = map(int, input().split())
	A.append(a)
	B.append(b)
left = statistics.median(A)
right = statistics.median(B)
if N % 2 == 0:
	print(int(right * 2 - left * 2 + 1))
else:
	print(right - left + 1)


3
import numpy

def main():
	n = int(input())
	(la, lb) = ([], [])
	for _ in range(n):
		(a, b) = list(map(int, input().split()))
		la.append(a)
		lb.append(b)
	(la.sort(), lb.sort())
	if n % 2 == 0:
		s = (n - 1) // 2
		e = s + 2
		ma = sum(la[s:e]) / 2.0
		mb = sum(lb[s:e]) / 2.0
		print(int(2 * (mb - ma) + 1))
	if n % 2 == 1:
		ma = la[n // 2]
		mb = lb[n // 2]
		print(mb - ma + 1)

def __starting_point():
	main()
__starting_point()


import sys
(N, *AB) = map(int, sys.stdin.buffer.read().split())
A = sorted(AB[::2])
B = sorted(AB[1::2])
center = N // 2
if N % 2 == 1:
	print(B[center] - A[center] + 1)
else:
	print(B[center] + B[center - 1] - (A[center] + A[center - 1]) + 1)


n = int(input())
import bisect as bi
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:
	a = A[(n - 1) // 2]
	b = B[(n - 1) // 2]
	print(b - a + 1)
else:
	a = (A[n // 2 - 1] + A[n // 2]) / 2
	b = (B[n // 2 - 1] + B[n // 2]) / 2
	print(int((b - a) / 0.5) + 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:
	ma = A[N // 2]
	mb = B[N // 2]
	print(max(0, mb - ma + 1))
else:
	ma = A[N // 2] + A[N // 2 - 1]
	mb = B[N // 2] + B[N // 2 - 1]
	print(max(0, mb - ma + 1))


N = int(input())
t = N // 2
a_list = []
b_list = []
for i in range(N):
	ab = list(map(int, input().split()))
	a_list.append(ab[0])
	b_list.append(ab[1])
a_list = sorted(a_list)
b_list = sorted(b_list)
if N % 2 == 1:
	a_median = a_list[t]
	b_median = b_list[t]
	print(b_median - a_median + 1)
elif N % 2 == 0:
	a_median = (a_list[t - 1] + a_list[t]) / 2
	b_median = (b_list[t - 1] + b_list[t]) / 2
	print(int(2 * (b_median - a_median) + 1))


from statistics import median
n = int(input())
(a, b) = ([], [])
for i in range(n):
	(a_, b_) = map(int, input().split())
	a.append(a_)
	b.append(b_)
(am, bm) = (median(a), median(b))
print(int(max(0, bm - am) * 2) + 1 if n % 2 == 0 else int(max(0, bm - am)) + 1)


n = int(input())
A = [list(map(int, input().split())) for i in range(n)]
B = [[A[i][1], A[i][0]] for i in range(n)]
A.sort()
B.sort(reverse=True)
if n % 2 == 1:
	print(B[(n - 1) // 2][0] - A[(n - 1) // 2][0] + 1)
else:
	print(B[n // 2][0] + B[n // 2 - 1][0] - (A[n // 2][0] + A[n // 2 - 1][0]) + 1)


(n, *AB) = map(int, open(0).read().split())
(A, B) = map(sorted, [AB[::2], AB[1::2]])
mid = n // 2
if n % 2 == 0:
	(a0, a1) = (A[mid - 1], A[mid])
	(b0, b1) = (B[mid - 1], B[mid])
	print(b0 + b1 - (a0 + a1) + 1)
else:
	print(B[mid] - A[mid] + 1)


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


import statistics
N = int(input())
AB = [map(int, input().split()) for _ in range(N)]
(A, B) = [list(i) for i in zip(*AB)]
A_median = statistics.median(A)
B_median = statistics.median(B)
if N % 2 == 0:
	print(int((B_median - A_median) * 2) + 1)
else:
	print(B_median - A_median + 1)


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)


N = int(input())
AB = [[int(_) for _ in input().split()] for _ in range(N)]
A = sorted([a for (a, b) in AB])
B = sorted([b for (a, b) in AB])
ans = B[N // 2] + B[(N - 1) // 2] - (A[N // 2] + A[(N - 1) // 2])
if N % 2:
	ans //= 2
ans += 1
print(ans)


import statistics as st
import math
N = int(input())
A = [0] * N
B = [0] * N
for i in range(N):
	(A[i], B[i]) = map(int, input().split())
mA = st.median(A)
mB = st.median(B)
if N % 2 == 0:
	ans = (mB - mA) * 2 + 1
else:
	ans = mB - mA + 1
print(int(ans))


n = int(input())
a = [None] * n
b = [None] * n
for i in range(n):
	(a[i], b[i]) = map(int, input().split())
a.sort()
b.sort()
if n % 2 == 1:
	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)


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


N = int(input())
m = []
M = []
for i in range(N):
	(a, b) = map(int, input().split())
	m.append(a)
	M.append(b)
m.sort()
M.sort()
if N % 2 == 1:
	print(M[N // 2] - m[N // 2] + 1)
else:
	M1 = (M[N // 2 - 1] + M[N // 2]) / 2
	m1 = (m[N // 2 - 1] + m[N // 2]) / 2
	print(int((M1 - m1) * 2 + 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)
m_a = median(A)
m_b = median(B)
if n % 2 == 0:
	ans = (m_b - m_a) * 2 + 1
else:
	ans = m_b - m_a + 1
print(int(ans))


from statistics import median
N = int(input())
A = [0] * N
B = [0] * N
max = 0
min = 0
for c in range(N):
	(A[c], B[c]) = map(int, input().split())
med_A = median(A)
med_B = median(B)
if N % 2 == 0:
	print(int((med_B - med_A) * 2 + 1))
else:
	print(med_B - med_A + 1)


N = int(input())
(A, B) = ([], [])
for i in range(N):
	(a, b) = map(int, input().split())
	A.append(a)
	B.append(b)
(A, B) = map(sorted, (A, B))
if N % 2 == 1:
	(mA, mB) = (A[N // 2], B[N // 2])
	print(mB - mA + 1)
else:
	(mA, mB) = ((A[N // 2 - 1] + A[N // 2]) / 2, (B[N // 2 - 1] + B[N // 2]) / 2)
	print(int((mB - mA) / 0.5 + 0.5) + 1)