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



Sample input:
2
1 2
2 3


Sample output:
3

Submission status: Runtime Error

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

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

Submission status: Runtime Error

Solution code:
args = map(int, input().split())
N = args[0]
A = [a for (i,a) in enumerate(args[1:]) if i%2==1]
B = [b for (i,b) in enumerate(args[1:]) if i%2==0]

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

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

Submission status: Runtime Error

Solution code:
n = int(input())

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

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

#listをsortする
if n==2:
    a0 = [a[0]]
    b0 = [b[0]]
    if a[1]>=a[0]:
        a0.append(a[1])
    else:
        a0.insert(0,a[1])
    if b[1]>=a[0]:
        b0.append(b[1])
    else:
        b0.insert(0,b[1])
else:
    a0 = [a[0]]
    b0 = [b[0]]
    if a[1]>=a[0]:
        a0.append(a[1])
    else:
        a0.insert(0,a[1])
    if b[1]>=a[0]:
        b0.append(b[1])
    else:
        b0.insert(0,b[1])    
    for i in range(2,n):
        if a[i]>=a0[len(a0)-1]:
            a0.append(a[i])
        elif a[i]<=a0[0]:
            a0.insert(0,a[i])
        else:
            l = 0
            for j in range(len(a0)-1):
                if a0[j]<=a[i] and a[i]<=a0[j+1] and l==0:
                    a0.insert(j+1,a[i])
                    l = 1
        if b[i]>=b0[len(b0)-1]:
            b0.append(b[i])
        elif b[i]<=b0[0]:
            b0.insert(0,b[i])
        else:
            m = 0
            for j in range(len(b0)-1):
                if b0[j]<=b[i] and b[i]<=b0[j+1] and m==0:
                    b0.insert(j+1,b[i])
                    m = 1

                    
if n%2 == 1:
    a0cen = a0[(n-1)//2]
    b0cen = b0[(n-1)//2]
    nn = b0cen - a0cen + 1
else:
    a0cen1 = a0[(n-2)//2]+a0[n//2]
    b0cen1 = b0[(n-2)//2]+b0[n//2]
    nn = int(b0cen1 -a0cen1 +1)

print(nn)

Submission status: Runtime Error

Solution code:
n = int(input())

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

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

#listをsortする
if n==2:
    a0 = [a[0]]
    b0 = [b[0]]
    if a[1]>=a[0]:
        a0.append(a[1])
    else:
        a0.insert(0,a[1])
    if b[1]>=a[0]:
        b0.append(b[1])
    else:
        b0.insert(0,b[1])
else:
    a0 = [a[0]]
    b0 = [b[0]]
    if a[1]>=a[0]:
        a0.append(a[1])
    else:
        a0.insert(0,a[1])
    if b[1]>=a[0]:
        b0.append(b[1])
    else:
        b0.insert(0,b[1])    
    for i in range(2,n):
        if a[i]>=a0[len(a0)-1]:
            a0.append(a[i])
        elif a[i]<=a0[0]:
            a0.insert(0,a[i])
        else:
            for j in range(len(a0)-1):
                if a0[j]<=a[i] and a[i]<=a0[j+1]:
                    a0.insert(j+1,a[i])
        if b[i]>=b0[len(b0)-1]:
            b0.append(b[i])
        elif b[i]<=b0[0]:
            b0.insert(0,b[i])
        else:
            for j in range(len(b0)-1):
                if b0[j]<=b[i] and b[i]<=b0[j+1]:
                    b0.insert(j+1,b[i])

                    
if n%2 == 1:
    a0cen = a0[(n-1)//2]
    b0cen = b0[(n-1)//2]
    nn = b0cen - a0cen + 1
else:
    a0cen1 = a0[(n-2)//2]+a0[n//2]
    b0cen1 = b0[(n-2)//2]+b0[n//2]
    nn = int(b0cen1 -a0cen1 +1)

print(nn)

Submission status: Runtime Error

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

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

print(int(ans))

Submission status: Runtime Error

Solution code:
n = int(input())

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

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

#listをsortする
if n == 1:
    a0 = [a[0]]
    b0 = [b[0]]
elif n==2:
    a0 = [a[0]]
    b0 = [b[0]]
    if a[1]>=a[0]:
        a0.append(a[1])
    else:
        a0.insert(0,a[1])
    if b[1]>=a[0]:
        b0.append(b[1])
    else:
        b0.insert(0,b[1])
else:
    a0 = [a[0]]
    b0 = [b[0]]
    if a[1]>=a[0]:
        a0.append(a[1])
    else:
        a0.insert(0,a[1])
    if b[1]>=a[0]:
        b0.append(b[1])
    else:
        b0.insert(0,b[1])    
    for i in range(2,n):
        if a[i]>=a0[len(a0)-1]:
            a0.append(a[i])
        elif a[i]<=a0[0]:
            a0.insert(0,a[i])
        else:
            for j in range(len(a0)-1):
                if a0[j]<=a[i] and a[i]<=a0[j+1]:
                    a0.insert(j+1,a[i])
        if b[i]>=b0[len(b0)-1]:
            b0.append(b[i])
        elif b[i]<=b0[0]:
            b0.insert(0,b[i])
        else:
            for j in range(len(b0)-1):
                if b0[j]<=b[i] and b[i]<=b0[j+1]:
                    b0.insert(j+1,b[i])

                    
if n%2 == 1:
    a0cen = a0[int((n-1)/2)]
    b0cen = b0[int((n-1)/2)]
    nn = b0cen - a0cen + 1
else:
    a0cen1 = a0[int((n-2)/2)]+a0[int(n/2)]
    b0cen1 = b0[int((n-2)/2)]+b0[int(n/2)]
    nn = int(b0cen -a0cen +1)

print(nn)

Submission status: Runtime Error

Solution code:
# -*- coding: utf-8 -*-
# 整数の入力
import math
import numpy as np

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

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

        print(a)

Submission status: Runtime Error

Solution code:

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

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

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

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

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

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

Submission status: Runtime Error

Solution code:
n = input()
A = []
B = []
for i in range(n):
  a,b = 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)

Submission status: Runtime Error

Solution code:
n=int(input())
alis=[]
blis=[]
for i in range(n):
  a,b=map(int,input().split())
  alis.ppend(a)
  blis.append(b)
  
  
alis=sorted(alis)
blis=sorted(blis)
if n%2!=0:
  print(blis[int((n-1)/2)]-alis[int((n-1)/2)]+1)
else:
  bb=(blis[int(n/2)-1]+blis[int(n/2)])
  aa=(alis[int(n/2)-1]+alis[int(n/2)])
  print(bb-aa+1)

Submission status: Runtime Error

Solution code:
n=int(input())
alis=[]
blis=[]
for i in range(n):
  a,b=map(int,input().split())
  alis.ppend(a)
  blis.append(b)
  
  
alis=sorted(alis)
blis=sorted(blis)
if n%2!=0:
  print(blis[int((n-1)/2)]-alis[int((n-1)/2)+1]
else:
  bb=(blis[int(n/2)-1]+blis[int(n/2)])
  aa=(alis[int(n/2)-1]+alis[int(n/2)])
  print(bb-aa+1)

Submission status: Runtime Error

Solution code:
import sys
def input(): return sys.stdin.readline().rstrip()
def main():
    h,w,k=map(int,input().split())
    S=[input() for _ in range(h)]
    final_ans=10**10
    for row_lis in range(1<<(h-1)):
        lst=[0]*h
        q,ans=0,0
        for r in range(h-1):
            if (row_lis>>r)&1==0:
                lst[r+1]=q
            else:
                q+=1
                lst[r+1]=q
                ans+=1
        data=[0]*h
        for j in range(w):
            for i in range(h):
                data[lst[i]]+=int(S[i][j])
                if data[lst[i]]>k:
                    ans+=1
                    break
            else:
                continue
            data=[0]*h
            for i in range(h):
                data[lst[i]]+=int(S[i][j])
                if data[lst[i]]>k:
                    break
            else:
                continue
            break
        else:
            final_ans=min(final_ans,ans)
    print(final_ans)


if __name__=='__main__':
    main()

Submission status: Runtime Error

Solution code:
N = int(input())
A = [list(map(int, input().split())) for _ in range(N)]
AX = [A[i][0] for i in range(N)]
BX = [A[i][1] for i in range(N)]
AX.sort()
BX.sort()
if N % 2 == 1:
  L = AX[(N-1)//2]
  R = BX[(N-1)//2]
  print(R-L+1)
else:
  L = AX[N//2] + AX[N//2+1]
  R = BX[N//2] + BX[N//2+1]
  print(R-L+1)

Submission status: Runtime Error

Solution code:
def resolve():
    N = int(input())
    divs = make_divisors(N)
    divs.sort()
    count = 0
    pdivs = []
    while divs:
        pdivs.append(divs[0])
        divs = [i for i in divs if i % divs[0] != 0]

    count = 0
    for i in pdivs:
        x = i
        while N % x ==0:
            count +=1
            N //= x
            x *= i
    print(count)
resolve()

Submission status: Runtime Error

Solution code:
def main():
    N = int(input())
    A,B = [],[]
    for _ in range(N):
        a,b = [int(x) for x in input().split()]
        A.append(a)
        B.append(b)
    A.sort()
    B.sort()
    if N % 2 == 1:
        minMed = A[N/2]
        maxMed = B[N/2]
        print(int(maxMed-minMed)+1)
    else:
        minMed = A[N//2-1] + A[N//2]
        maxMed = B[N//2-1] + B[N//2]
        print(int(maxMed-minMed)+1)

if __name__ == '__main__':
    main()

Submission status: Runtime Error

Solution code:
def main():
    N = int(input())
    A,B = [],[]
    for _ in range(N):
        a,b = [int(x) for x in input().split()]
        A.append(a)
        B.append(b)
    A.sort()
    B.sort()
    if N % 2 == 1:
        minMed = A[N/2]
        maxMed = B[N/2]
        print(int(maxMed-minMed)+1)
    else:
        minMed = A[N//2-1] + A[N//2]
        maxMed = B[N//2-1] + B[N//2]
        print(minMed,maxMed)
        print(int(maxMed-minMed)+1)

if __name__ == '__main__':
    main()

Submission status: Runtime Error

Solution code:
n = int(input().strip())
nums = []
for _ in range(n):
    nums.append([int(i) for i in input().strip().split()])
a_sort = sorted(nums, key=lambda s:s[0])
b_sort = sorted(nums, key=lambda s:s[1])
if len(nums) % 2 == 1:
    a_mid = a_sort[len(a_sort) // 2][0]
    b_mid = b_sort[len(b_sort) // 2][1]
    print((b_mid - a_mid) * 2 + 1)
else:
    a_mid = (a_sort[len(a_sort) // 2][0] + a_sort[len(a_sort) // 2 - 1][0]) / 2
    b_mid = (b_sort[len(b_sort) // 2][1] + b_sort[len(b_sort) // 2 - 1][1]) / 2    
	print(b_mid - a_mid + 1)

Submission status: Runtime Error

Solution code:
N = int(input())
lower = []
upper = []
for i in range(N):
    a, b = map(int, input().split())
    lower.append(a)
    upper.append(b)
lower.sort()
upper.sort()
if N % 2 == 1:
    print(upper[(N+1)//2]-lower[(N+1)//2]+1)
else:
    print(upper[N//2 + 1]+upper[N//2]-lower[N//2 + 1]-lower[N//2]+1)

Submission status: Runtime Error

Solution code:
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]

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

Submission status: Runtime Error

Solution code:
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]+arr1[n//2+1]
  r=arr2[n//2]+arr2[n//2+1]
print(r-l+1)

Submission status: Runtime Error

Solution code:
n=int(input())
c=[list(map(int,input().split())) for _ in range(n)]
c.sort()
q,w=c[n//2][0],min(c[n//2][1],c[n//2+1][1])
c.sort(key=lambda x: x[1])
e,r=max(c[n//2][0],c[n//2-1][1]),c[n//2][1]
if n%2==0:
    print(r-q+1+e-w)
else:
    print(r-q+1)

Submission status: Runtime Error

Solution code:
n=int(input())
c=[list(map(int,input().split())) for _ in range(n)]
c.sort()
q,w=c[n//2][0],min(c[n//2][1],c[n//2+1][1])
c.sort(key=lambda x: x[1])
e,r=max(c[n//2][0],c[n//2-1][1]),c[n//2][1]
if n%2==0:
    print(max(w-q,r-e)+1)
else:
    print(r-q+1)

Submission status: Runtime Error

Solution code:
n=int(input())
c=[list(map(int,input().split())) for _ in range(n)]
c.sort()
q,w=c[n//2][0],min(c[n//2][1],c[n//2+1][1])
c.sort(key=lambda x: x[1])
e,r=max(c[n//2][0],c[n//2-1][1]),c[n//2][1]
# if w<=e:
#     print(max(w-q,r-e)+1)
# else:
print(r-q+1)

Submission status: Runtime Error

Solution code:
n = int(input())

mins = [0] * n
maxs = [0] * n
for i in range(n):
    a, b = map(int, input().split())
    mins[i] = a
    maxs[i] = b

mins = sorted(mins)
maxs = sorted(maxs)

if n % 2 != 0:
    print(maxs[((n+1)//2) - 1] - mins[((n+1)//2) - 1] + 1)
else:
    print(((maxs[n//2] - mins[(n//2) - 1] + 1) * 2)

Submission status: Runtime Error

Solution code:
import math
import decimal


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

a=[]
b=[]

for i in range(N):
    a.append(A[i][0])
    b.append(A[i][1])
a.sort()
b.sort()

if(N%2==0):
    #a_mid=(a[N//2-1]+a[N//2])/2
    #b_mid=(b[N//2-1]+b[N//2])/2
    a[N//2-1]=decimal.Decimal(a[N//2-1])
    a[N//2]=decimal.Decimal(a[N//2])
    b[N//2-1]=decimal.Decimal(b[N//2-1])
    b[N//2]=decimal.Decimal(b[N//2])
    a_mid=(a[N//2-1]+a[N//2])/decimal.Decimal(2)
    b_mid=(b[N//2-1]+b[N//2])/decimal.Decimal(2)
    #a_mid=decimal.Decimal((a[N//2-1]+a[N//2])/2)
    #b_mid=decimal.Decimal((b[N//2-1]+b[N//2])/2)
    if(a_mid-int(a_mid)<0.5):
        a_mid=int(a_mid)+0.5
    elif(0.5<a_mid-int(a_mid)):
        a_mid=math.ceil(a_mid)

    if(b_mid-int(b_mid)<0.5):
        b_mid=int(b_mid)+0.5
    elif(0.5<b_mid-int(b_mid)):
        b_mid=math.ceil(b_mid)



    sa=b_mid-a_mid
    print(int(sa)*2+1)


else:

    a_mid=a[int(N/2)]
    b_mid=b[int(N/2)]



    sa=b_mid-a_mid
    print(int(sa)+1)

Submission status: Runtime Error

Solution code:
import math
import decimal


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

a=[]
b=[]

for i in range(N):
    a.append(A[i][0])
    b.append(A[i][1])
a.sort()
b.sort()

if(N%2==0):

    a_mid=decimal.Decimal((a[N//2-1]+a[N//2])/2)
    b_mid=decimal.Decimal((b[N//2-1]+b[N//2])/2)
    if(a_mid-int(a_mid)<0.5):
        a_mid=int(a_mid)+0.5
    elif(0.5<a_mid-int(a_mid)):
        a_mid=math.ceil(a_mid)

    if(b_mid-int(b_mid)<0.5):
        b_mid=int(b_mid)+0.5
    elif(0.5<b_mid-int(b_mid)):
        b_mid=math.ceil(b_mid)


    sa=b_mid-a_mid
    print(int(sa)*2+1)


else:

    a_mid=a[int(N/2)]
    b_mid=b[int(N/2)]



    sa=b_mid-a_mid
    print(int(sa)+1)

Submission status: Runtime Error

Solution code:
import math
import Decimal


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

a=[]
b=[]

for i in range(N):
    a.append(A[i][0])
    b.append(A[i][1])
a.sort()
b.sort()

if(N%2==0):

    a_mid=Decimal.decimal((a[N//2-1]+a[N//2])/2)
    b_mid=Decimal.decimal((b[N//2-1]+b[N//2])/2)
    if(a_mid-int(a_mid)<0.5):
        a_mid=int(a_mid)+0.5
    elif(0.5<a_mid-int(a_mid)):
        a_mid=math.ceil(a_mid)

    if(b_mid-int(b_mid)<0.5):
        b_mid=int(b_mid)+0.5
    elif(0.5<b_mid-int(b_mid)):
        b_mid=math.ceil(b_mid)


    sa=b_mid-a_mid
    print(int(sa)*2+1)


else:

    a_mid=a[int(N/2)]
    b_mid=b[int(N/2)]



    sa=b_mid-a_mid
    print(int(sa)+1)

Submission status: Runtime Error

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

Submission status: Runtime Error

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

Submission status: Runtime Error

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

Submission status: Runtime Error

Solution code:
n = int(input())
x,y = map(int,input().split())
a = [x]
b = [y]
for i in range(n-1):
    x,y = map(int,input().split())
    if(a[-1] < x):
        a.append(x)
    elif(a[0] > x):
        a = [x] + a
    else:
        for j in range(len(a)):
            if(a[j] > x):
                a.insert(j,x)
                break
    if(b[-1] < y):
        b.append(y)
    elif(b[0] > y):
        b = [y] + b
    else:
        for j in range(len(b)):
            if(b[j] > y):
                b.insert(j,y)
                break
if(n%2 == 1):
    print(b[n//2]-a[n//2]+1)
else:
    print(b[n//2] + b[-1+n//2] - a[n//2] - a[-1+n//2]+1)

Submission status: Runtime Error

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

Submission status: Runtime Error

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

Submission status: Runtime Error

Solution code:
#include <bits/stdc++.h>

#define debug(x) cout <<"DEBUG"<<" "<< #x << ":" << x << '\n'
#define rep(i,n) for(int_fast32_t i = 0; i < ((int_fast32_t)(n)); i++)   // 0-indexed昇順
#define rep1(i,n) for(int_fast32_t i = 1; i <= ((int_fast32_t)(n)); i++) // 1-indexed昇順
#define rrep(i,n) for(int_fast32_t i = ((int_fast32_t)(n)-1); i >= 0; i--)  // 0-indexed降順
#define rrep1(i,n) for(int_fast32_t i = ((int_fast32_t)(n)); i >= 1; i--)   // 1-indexed降順
#define all(x) (x).begin(),(x).end()

using namespace std;

template<typename T>
using vec = vector<T>;
using i32 = int_fast32_t;
using i64 = int_fast64_t;
using u32 = uint_fast32_t;
using u64 = uint_fast64_t;
using ll = long long;
using ld = long double;
using vi = vec<int_fast32_t>;
using vl = vec<int_fast64_t>;
using vld = vec<ld>;
using vii = vec<vi>;  // 2次元配列
using PII = pair<int_fast32_t, int_fast32_t>;

template<class T>
using maxheap = std::priority_queue<T>;
template<class T>
using minheap = std::priority_queue<T, std::vector<T>, std::greater<T>>;

template<class T,class U> inline bool chmax(T &a, const U &b){if(a<b){a=b;return 1;}return 0;}
template<class T,class U> inline bool chmin(T &a, const U &b){if(a>b){a=b;return 1;}return 0;}

const ld Pi = std::acos(-1.0L);
constexpr ll infll = (1LL<<62)-1;
constexpr int inf = (1<<30)-1;
const int mod = 1000000007;
// const int mod = 998244353;


/*FUNCs=================================================*/


/*MAIN==================================================*/
signed main(){
    int START_TIME = clock();
    cin.tie(nullptr);
    ios::sync_with_stdio(false);   //cin cout 高速化
//    cout << fixed << setprecision(15);

    i32 n; cin >> n;
    vi a(n), b(n);
    rep(i,n) cin >> a[i] >> b[i];
    sort(all(a));
    sort(all(b));

    if(n&1) {
        i32 lb = a[n/2], ub = b[n/2];
        cout << ub - lb + 1 << '\n';
    }
    else {
        i32 lb1 = a[n/2], ub1 = b[n/2];
        i32 lb2 = a[(n-1)/2], ub2 = b[(n-1)/2];
        cout << (ub1+ub2) - (lb1+lb2) + 1 << '\n';
    }

    // printf("ExecutionTime: %d /ms\n",1000*(int)((clock()-START_TIME)/CLOCKS_PER_SEC));
}

Submission status: Runtime Error

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

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

Submission status: Runtime Error

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

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

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

Submission status: Runtime Error

Solution code:
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],reverse=True)
  down2 = sorted(ab,key=lambda a:a[1],reverse=True)
    r = (up[N//2][1]+up2[N//2][1])
    l = (down[N//2][0]+down2[N//2][0])
    print(r-l+1)

Submission status: Runtime Error

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

Submission status: Runtime Error

Solution code:
n = int(input())
A = []
B = []
for _ in range(n):
    a, b = tuple(map(int, input().split()))
    A.append(a)
    B.append(b)

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

if n%2==1:
    sa = AB_A[n//2]
    lb = AB_B[n//2]
    print(lb - sa + 1)
else:
    sal = AB_A[n//2-1]
    sar = AB_A[n//2]

    lbl = AB_B[n//2-1]
    lbr = AB_B[n//2]
    print((lbl + lbr) - (sal + sar) +1)

Submission status: Runtime Error

Solution code:
n = int(input())
a = [0 for _ in range(n)]
b = a[:]
for i in range(n):
    a[i],b[i] = map(int,input().split())
a.sort()
b.aort()

ans = 0
if n % 2 == 0:
    l = a[n//2-1] + a[n//2]
    h = b[n//2-1] + b[n//2]

    ans += h - l + 1
else:
    l = a[n//2]
    h = b[n//2]

    ans += h - l + 1



print(ans)

Submission status: Runtime Error

Solution code:
n = int(input())

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

aList.sort()
bList.sort()

half = n // 2
if not n % 2 == 0:
    print(bList[half] - aList[half] + 1)
else:
    print(bList[half] + bList[half+1] - aList[half] + aList[half+1] + 1)