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:
import sys 
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines

N = int(input())
A = [0]*N
B = [0]*N
i = 0
for line in readlines():
    A[i], B[i] = map(int, line.rstrip().decode('utf-8').split())
    i+=1
sA = sorted(A)
sB = sorted(B)
if N % 2 == 0:
    ans = ((sB[(N//2)-1]+sB[(N//2)]) - (sA[(N//2)-1]+sA[(N//2)])) + 1
else:
    ans = (sB[(N-1)//2]-sA[(N-1)//2]) + 1
print(ans)

Submission status: Runtime Error

Solution code:
n=int(input())
T=[list(map(int,input().split())) for i in range(n)]
#print(T)

def dfs(i,group):
    center=[]
    if i==n:
        group.sort()
        if n%2==1:
            center+=[group[int((n-1)/2)]]
        else:
            center+=[group[int(n/2)]+group[int((n/2-1)/2)]]
    s=T[i][0]
    g=T[i][1]
    for j in range(s,g+1):
        print(i,group)
        dfs(i+1,group+[j])
dfs(0,[])
print(len(set(center)))

Submission status: Runtime Error

Solution code:
n = int(input())

ab_list = []
for i in range(n):
  a, b = list(map(int, input().split()))
  ab_list.append([a,b])
l_ab = sorted(ab_list, key=lambda r: r[0])
h_ab = sorted(ab_list, key=lambda r: r[1])

# 奇数の場合
med_cands = set()
if n%2==1:
    center = n//2
    
    l_center_ab = l_ab[center]
    left1, right1 = l_center_ab[0], \
    	min(l_center_ab[1], l_ab[center+1][1])+1
    
    h_center_ab = h_ab[center]
    left2, right2 = max(h_center_ab[0], h_ab[center+1][0]), \
    	h_center_ab[1]+1
# 偶数の場合
else:
    center1, center2 = n//2-1, n//2
    
    l_center1_ab, l_center2_ab = l_ab[center1], l_ab[center2]
    left1, right1 = l_center1_ab[0]+l_center2_ab[0], \
        min(l_center1_ab[1], l_ab[center2+1][1]) + min(l_center2_ab[1], l_ab[center2+1][1])+1
    
    h_center1_ab, h_center2_ab = h_ab[center1], h_ab[center2]
    left2, right2 = max(h_center1_ab[0], h_ab[center2+1][0]) + max(h_center2_ab[0], h_ab[center2+1][0]), \
        h_center1_ab[1]+h_center2_ab[1]+1
    
print(max(right1, right2) - min(left1, left2))

Submission status: Runtime Error

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

Submission status: Runtime Error

Solution code:
n = int(input())

ab_list = []
for i in range(n):
  a, b = list(map(int, input().split()))
  ab_list.append([a,b])
l_ab = sorted(ab_list, key=lambda r: r[0])
h_ab = sorted(ab_list, key=lambda r: r[1])
print('l_ab', l_ab)
print('h_ab', h_ab)

# 奇数の場合
med_cands = set()
if n%2==1:
    center = n//2
    
    l_center_ab = l_ab[center]
    left1, right1 = l_center_ab[0], \
    	min(l_center_ab[1], l_ab[center+1][1])+1
    
    h_center_ab = h_ab[center]
    left2, right2 = max(h_center_ab[0], h_ab[center+1][0]), \
    	h_center_ab[1]+1
# 偶数の場合
else:
    center1, center2 = n//2-1, n//2
    
    l_center1_ab, l_center2_ab = l_ab[center1], l_ab[center2]
    left1, right1 = l_center1_ab[0]+l_center2_ab[0], \
        min(l_center1_ab[1], l_ab[center2+1][1]) + min(l_center2_ab[1], l_ab[center2+1][1])+1
    
    h_center1_ab, h_center2_ab = h_ab[center1], h_ab[center2]
    left2, right2 = max(h_center1_ab[0], h_ab[center2+1][0]) + max(h_center2_ab[0], h_ab[center2+1][0]), \
        h_center1_ab[1]+h_center2_ab[1]+1
    
print(max(right1, right2) - min(left1, left2))

Submission status: Runtime Error

Solution code:
    N = int(input(""))

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

    medians = []
    for a in A:
        for b in B:
            # Xs = [i for i in range(a, b+1)]
            # n = len(Xs)
            n = (b - a) + 1
            if n % 2 == 0:
                indx = int(n / 2)
                # med = (Xs[indx-1] + Xs[indx]) / 2
                med = (a+indx-1+a+indx) / 2
            else:
                indx = int((n+1)/2)
                med = a + indx-1
            
            medians.append(med)

    medians = set(medians)
    print(len(medians))

Submission status: Runtime Error

Solution code:
from heapq import heappush, heappop, heapify
from collections import deque, defaultdict, Counter
import itertools
from itertools import permutations, combinations, accumulate, product, combinations_with_replacement
import sys
import bisect
import string
import math
import time


def I(): return int(input())
def S(): return input()
def MI(): return map(int, input().split())
def MS(): return map(str, input().split())
def LI(): return [int(i) for i in input().split()]
def LI_(): return [int(i)-1 for i in input().split()]
def StoI(): return [ord(i)-97 for i in input()]
def ItoS(nn): return chr(nn+97)
def input(): return sys.stdin.readline().rstrip()
def list2d(a, b, c): return [[c] * b for i in range(a)]
def list3d(a, b, c, d): return [[[d] * c for j in range(b)] for i in range(a)]
def list4d(a, b, c, d, e): return [[[[e] * d for j in range(c)] for j in range(b)] for i in range(a)]
def print_matrix(mat):
    for i in range(len(mat)):
        print(*['IINF' if v == IINF else "{:0=4}".format(v) for v in mat[i]])


yn = {False: 'No', True: 'Yes'}
YN = {False: 'NO', True: 'YES'}
MOD = 10**9+7
inf = float('inf')
IINF = 10**19
l_alp = string.ascii_lowercase
u_alp = string.ascii_uppercase
ts = time.time()
sys.setrecursionlimit(10**6)
nums = ['1', '2', '3', '4', '5', '6', '7', '8', '9', '10']
show_flg = False
# show_flg = True

def gcd(a, b):
    if b == 0:
        return a
    return gcd(b, a % b)


def main():
    N = I()
    AB = [None] * N
    BA = [None] * N
    ans = 0
    BA_B_IDX = 0
    BA_A_IDX = 1
    AB_A_IDX = 0
    AB_B_IDX = 1

    for i in range(N):
        a, b = MI()
        AB[i] = (a, b, i)
        BA[i] = (b, a, i)

    BA = sorted(BA, reverse=True)
    AB = sorted(AB)

    if N % 2 == 1:
        mid = N // 2
        mx = BA[mid][BA_B_IDX]
        mn = AB[mid][AB_A_IDX]

        # print(mx, mn, mid, AB)

        mn2 = AB[mid][AB_A_IDX]
        mx2 = BA[mid][AB_B_IDX]

        # print(mx2, mn2, mid, AB)

        if mn2 > mx or mn > mx2:
            print(1 / 0)
            ans = mx - mn + 1 + mx2 - mn2 + 1
            print(ans)
        else:
            print(max(mx, mx2) - min(mn, mn2) + 1)
    else:
        mid = N // 2 - 1
        mx = BA[mid][BA_B_IDX]
        mn = AB[mid][AB_A_IDX]

        # print(mx, mn, mid, AB)

        mn2 = AB[mid][AB_A_IDX]
        mx2 = BA[mid][AB_B_IDX]

        # print(mx2, mn2, mid, AB)

        if mn2 > mx or mn > mx2:
            print(1 / 0)
            ans = mx - mn + 1 + mx2 - mn2 + 1
            print(ans)
        else:
            print(max(mx, mx2) - min(mn, mn2) + 1)


if __name__ == '__main__':
    main()

Submission status: Runtime Error

Solution code:
#!/usr/bin/env python3
# -*- coding: utf-8 -*-
from collections import defaultdict


def main():
    n = int(input().strip())

    diff_a = defaultdict(int)
    diff_b = defaultdict(int)
    for _ in range(n):
        a, b = map(int, input().split())
        diff_a[a] += 1
        diff_b[b] += 1

    cur = 0
    for i in sorted(diff_a):
        cur += diff_a[i]
        if cur == n // 2 + 1:
            b1 = i
            break
    cur = 0
    for i in sorted(diff_b, reverse=True):
        cur += diff_b[i]
        if cur == n // 2 + 1:
            e1 = i
            break

    if n % 2 == 1:
        print(e1 - b1 + 1)
        return

    cur = 0
    for i in sorted(diff_a):
        cur += diff_a[i]
        if cur == n // 2:
            b2 = i
            break
    cur = 0
    for i in sorted(diff_b, reverse=True):
        cur += diff_b[i]
        if cur == n // 2:
            e2 = i
            break
    ans = e2 + e1 - (b1 + b2) + 1
    print(ans)


if __name__ == '__main__':
    main()

Submission status: Runtime Error

Solution code:
n = int(input())
a, b = map(list, zip(*(map(int, input().split()) for _ in range(n))))
a.sort()
a = a[::-1]
b.sort()
i = 0
while a[i] >= b[i]:
    i += 1
print(b[i]-a[i]+1)

Submission status: Runtime Error

Solution code:
import numpy as np
INT = lambda: int(input())
INTM = lambda: map(int,input().split())
STRM = lambda: map(str,input().split())
STR = lambda: str(input())
LIST = lambda: list(map(int,input().split()))
LISTS = lambda: list(map(str,input().split()))

def do():
    imos1=np.array([0]*(10**9))
    imos2=np.array([0]*(10**9))
    n=INT()

    for i in range(n):
        a,b=INTM()
        b=10**9+1-b
        imos1[a-1:]+=1
        imos2[b-1:]+=1
        
    if n%2==1:
        for i in range(n//2+1,n+1):
            if (i in imos1) and (i in imos2): 
                ta=imos1.index(i)+1
                tb=10**9-imos2.index(i)
                break
            else:
                pass
        print(tb-ta+1)
    else:
        for i in range(n//2,n+1):
            if (i in imos1) and (i in imos2): 
                for k in range(i+1,n+1):
                    if (k in imos1) and (k in imos2):
                        ta1=imos1.index(i)+1
                        ta2=imos1.index(k)+1
                        tb1=10**9-imos2.index(i)
                        tb2=10**9-imos2.index(k)
                        avea=(ta1+ta2)/2
                        ave=b(tb1+tb2)/2
                        print(int((aveb-avea)*2)+1)
                        break
                        break
                    else:
                        pass
            else:
                pass
        
        
    
if __name__ == '__main__':
    do()

Submission status: Runtime Error

Solution code:
N = int(input())
X = []
for i in range(N):
  X.append(list(map(int,input().split())))
X = sorted(X)

if N%2 == 1:
  print(X[((N+1)//2)-1][1] - X[((N+1)//2)-1][0] + 1)
else:
  import numpy as np
  Y = np.arange(X[(N//2)-1][0],X[(N//2)-1][1]+1)  
  Z = np.arange(X[(N//2)][0],X[(N//2)][1]+1) 
  L = []
  for y in range(len(Y)):
    for z in range(len(Z)):
      if Y[y] <= Z[z]:
        L.append((Y[y]+Z[z])/2)
  print(len(set(L)))

Submission status: Runtime Error

Solution code:
N = int(input(""))

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

medians = []
for a in A:
  for b in B:
    # Xs = [i for i in range(a, b+1)]
    # n = len(Xs)
    n = (b - a) + 1
    if n % 2 == 0:
      indx = n//2
      # med = (Xs[indx-1] + Xs[indx]) / 2
      med = (a+indx-1+a+indx) / 2
    else:
      indx = (n+1)//2
      med = a + indx-1

      medians.append(med)

      medians = set(medians)
print(len(medians))

Submission status: Runtime Error

Solution code:
n = int(input())

ab_list = []
for i in range(n):
  a, b = list(map(int, input().split()))
  ab_list.append([a,b])
l_ab = sorted(ab_list, key=lambda r: r[0])
h_ab = sorted(ab_list, key=lambda r: r[1])

# 奇数の場合
med_cands = set()
if n%2==1:
    center = n//2
    
    l_center_ab = l_ab[center]
    med_cands |= set(range(
        l_center_ab[0], 
        min(l_center_ab[1], l_ab[center+1][1])+1))
    
    h_center_ab = h_ab[center]
    med_cands |= set(range(
        max(h_center_ab[0], h_ab[center+1][0]), 
        h_center_ab[1]+1))
# 偶数の場合
else:
    center1, center2 = n//2-1, n//2
    
    l_center1_ab, l_center2_ab = l_ab[center1], l_ab[center2]
    med_cands |= set(range(
        l_center1_ab[0]+l_center2_ab[0], 
        min(l_center1_ab[1], l_ab[center2+1][1]) + min(l_center2_ab[1], l_ab[center2+1][1])+1))
    
    h_center1_ab, h_center2_ab = h_ab[center1], h_ab[center2]
    med_cands |= set(range(
        max(h_center1_ab[0], h_ab[center2+1][0]) + max(h_center2_ab[0], h_ab[center2+1][0]), 
        h_center1_ab[1]+h_center2_ab[1]+1))
    
print(len(med_cands))

Submission status: Runtime Error

Solution code:
from bisect import bisect_right
import sys
read = sys.stdin.read
readline = sys.stdin.readline
readlines = sys.stdin.readlines

def main():
    N,*ab = map(int, read().split())

    AB = []
    for a, b in zip(*[iter(ab)]*2):
        AB.append((a, b))

    ans = 0
    AB.sort()
    a, b = AB[N // 2]
    ans += bisect_right(list(range(a, b+1)), AB[min(N // 2 + 1, N-1)][1])
    
    AB.sort(key=lambda x: x[1])
    a, b = AB[N // 2]
    ans += b - a + 1 - bisect_right(list(range(a, b+1)), AB[N // 2 - 1][0])
    
    print(ans)


if __name__ == "__main__":
    main()

Submission status: Runtime Error

Solution code:
n = int(input())
l = []
for _ in range(n):
    a,b = map(int,input().split())
    l.append(a)
    l.append(b)
l2 = sorted(list(set(l)))
length = len(l2)
print(l2[length// 2 + 1] - l2[length//2 - 1] + 1)

Submission status: Runtime Error

Solution code:
N = int(input())
X = []
for i in range(N):
  X.append(list(map(int,input().split())))
X = sorted(X)

if N%2 == 1:
  print(X[(N)//2][1] - X[(N)//2][0] + 1)
else:
  import numpy as np
  Y = np.arange(X[(N//2)-1][0],X[(N//2)-1][1]+1)  
  Z = np.arange(X[(N//2)][0],X[(N//2)][1]+1) 
  L = []
  for y in range(len(Y)):
    for z in range(len(Z)):
      if Y[y] <= Z[z]:
        L.append((Y[y]+Z[z])/2)
  print(len(set(L)))

Submission status: Runtime Error

Solution code:
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()
if N % 2 == 0:
    C = A+B
    C.sort()
    ans = 2 * sum(C[::-1][:N]) - 2 * sum(C[:N])
    print(ans//2+1)
else:
    ans = B[N//2] - A[N//2] + 1
    print(ans

Submission status: Runtime Error

Solution code:
n = int(input())
l = []
for _ in range(n):
    a,b = map(int,input().split())
    l.append(a)
    l.append(b)
l2 = sorted(list(set(l)))
length = len(l2)
print(l2[length//2+1] - l2[length//2-1] + 1)

Submission status: Runtime Error

Solution code:
def main():

    A, B = input().split()
    A = int(A)
    B = float(B)
    f = B - int(B)
    v = int(A * f)
    v += int(B) * int(A)
    return v

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

Submission status: Runtime Error

Solution code:
from statistics import median
import math
n=int(input())
A,B = [],[]
for _ in range(n):
  a,b=map(int,input().split())
  A.append(a)
  B.append(b)
a1,b2 = int(median(A)),math.ceil(median(B))
b1 = max([B[i] for i,v in enumerate(A) if v == a1])
a2 = max([A[i] for i,v in enumerate(B) if v == b2])
#print(a1,b1,a2,b2)
if b1<a2:
  print(b1-a1+b2-a2+1)
  exit()
print(b2-a1+1)

Submission status: Runtime Error

Solution code:
from bisect import bisect_right
import sys
read = sys.stdin.read
readline = sys.stdin.readline
readlines = sys.stdin.readlines

def main():
    N,*ab = map(int, read().split())

    AB = []
    for a, b in zip(*[iter(ab)]*2):
        AB.append((a, b))

    ans = 0
    AB.sort()
    a, b = AB[N // 2]
    ans += bisect_right(list(range(a, b+1)), AB[min(N // 2 + 1, N-1)][1])
    
    AB.sort(key=lambda x: x[1])
    a, b = AB[N // 2]
    ans += b - a + 1 - bisect_right(list(range(a, b+1)), AB[max(N // 2 - 1, 0)][1])
    
    print(ans)


if __name__ == "__main__":
    main()

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, tan, asin, acos, atan, radians, degrees, log2, gcd, floor
from itertools import accumulate, permutations, combinations, combinations_with_replacement, product, groupby
from operator import itemgetter, mul
from copy import deepcopy
from string import ascii_lowercase, ascii_uppercase, digits
from bisect import bisect, bisect_left, insort
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(float, 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
#import numpy as np
#from decimal import *

N = INT()
AB = [LIST() for _ in range(N)]

lim = 2*10**9

left = []
right = []

for l, r in AB:
	left.append(l)
	right.append(r)

right.sort()
left.sort()

#print(right)
#print(left)

if N%2:
	print(right[N//2] - left[N//2] +1)
else:
	M = set()
	m1 = list(range(left[N//2-1], right[N//2-1]+1))
	m2 = list(range(left[N//2], right[N//2]+1))
	for x in m1:
		for y in m2:
			M.add(x+y)

	print(len(M))

Submission status: Runtime Error

Solution code:
from bisect import bisect_right, bisect_left
N = int(input())
l = -1
r = 10**10
als = [0]*N
bls = [0]*N
for i in range(N):
  a,b = map(int, input().split())
  als[i] = a
  bls[i] = b
if N%2==0:
  l = -1
  r = 10**10
  while l+1<r:
    s = (l+r)//2
    i = bisect_right(als,s)
    if i>=N//2:
      r = s
    else:
      l = s
  A1 = r
  x = als.index(A1)
  B1 = als[x+1]
  l = -1
  r = 10**10
  while l+1<r:
    s = (l+r)//2
    i = bisect_right(bls,s)
    if i>=N//2:
      r = s
    else:
      l = s
  A2 = r
  x = bls.index(r)
  B2 = bls[x+1]
  ans = B2+A2-A1-B1+1
  print(ans)
else:
  l = -1
  r = 10**10
  while l+1<r:
    s = (l+r)//2
    i = bisect_left(als,s)
    if i>N//2:
      r = s
    else:
      l = s
  A = l
  l = -1
  r = 10**10
  while l+1<r:
    s = (l+r)//2
    i = bisect_left(bls,s)
    j = N-i
    if j>N//2:
      l = s
    else:
      r = s
  B = l
  print(B-A+1)

Submission status: Runtime Error

Solution code:
#!/usr/bin/env python3
import statistics.median()

n = int(input())

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

a_median = statistics.median(a)
b_median = statistics.median(b)

if n % 2 == 0:
    print(b_median-a_median+1)
else:
    print(b_median*2-a_median*2+1)

Submission status: Runtime Error

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

print(a,b)

Submission status: Runtime Error

Solution code:
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] - a[n//2] +1)
else:
  print((b[n//2][1] - a[n//2-1][0]+1)*(b[n//2][1] - a[n//2-1][0])//2)

Submission status: Runtime Error

Solution code:
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)
  arr1 = list(range(AB[k1][0], AB[k1][1] + 1))
  arr2 = list(range(AB[k2][0], AB[k2][1] + 1))
  pattern = list(itertools.product(arr1, arr2))
  ans = set()
  for p in pattern:
    ans.add(sum(p))
  print(len(ans))
else:
  k = int((N+1)/2)-1
  A = AB[k][0]
  B = AB[k][1]
  print(B-A+1)

Submission status: Runtime Error

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

Submission status: Runtime Error

Solution code:
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i = 0; i < n; i++)
#define per(i,n) for(int i = n-1; i >= 0; i--)
typedef long long ll;
typedef pair<int, int> P;
typedef pair<long long, long long> Pll;
typedef vector<int> vi;
typedef vector<ll> vll;
const long long mod = 1000000007LL;

int main() {
  ll n;
  cin >> n;
  vll a(n), b(n);
  rep(i,n) cin >> a[i] >> b[i];
  sort(a.begin(),a.end());
  sort(b.begin(),b.end());
  ll minm, maxm;
  if(n%2==0) {
    minm = a[n/2-1]+a[n/2];
    maxm = b[n/2-1]+b[n/2];
  }
  else {
    minm = a[(n+1)/2-1];
    maxm = b[(n+1)/2-1];
  }
  cout << maxm-minm+1 << endl;
  return 0;
}

Submission status: Runtime Error

Solution code:
#include<bits/stdc++.h>
using namespace std;using ll=long long;using vi=vector<int>;using vvi=vector<vi>;using vl=vector<ll>;using vvl=vector<vl>;using P=pair<int,int>;using PL=pair<ll,ll>;using vp=vector<P>;using vpl=vector<PL>;
#define pqueue priority_queue
template<typename T>constexpr auto inf=numeric_limits<T>::max()/2;constexpr int INF=inf<int>,MOD=1000000007;constexpr ll LINF=inf<ll>;
#define _ol3(_1,_2,_3,name,...)name
#define _rep(i,n)_repi(i,0,n)
#define _repi(i,a,b)for(int i=a,i##_l=(b);i<i##_l;++i)
#define REP(...)_ol3(__VA_ARGS__,_repi,_rep,)(__VA_ARGS__)
#define REPR(i,n)for(int i=n-1;i>=0;--i)
#define REPA(i,v)REP(i,(v).size())
#define all(v)(v).begin(),(v).end()
#define rall(v)(v).rbegin(),(v).rend()
#define bit(n)(1ll<<(n))
#define F first
#define S second
#define endl '\n'
void _print(ostream&){}template<class T,class...U>void _print(ostream&s,const T&t,const U&...u){s<<t<<(sizeof...(u)?' ':'\n');_print(s,u...);}
template<class...T>void print(const T&...t){_print(cout,t...);}template<class...T>void dprint(const T&...t){_print(cerr,t...);}
#ifndef LOCAL
struct osd{template<class T>osd&operator<<(const T&t){return*this;}};osd cer_;
#define dprint(...)
#define cerr cer_
#endif
#define dbg(x) dprint("@l",__LINE__,':',#x,'=',x)
#define cho(n,a,b)print((n)?a:b)
void YES(int n){cho(n,"YES","NO");}void Yes(int n){cho(n,"Yes","No");}void Poss(int n){cho(n,"Possible","Impossible");}
template<class T, class U>bool chmax(T&a,const U&b){bool x=a<b;x?a=b:b;return x;}template<class T, class U>bool chmin(T&a,const U&b){bool x=a>b;x?a=b:b;return x;}
template<class T, class U>auto max(const T&a,const U&b){return a<b?b:a;}template<class T, class U>auto min(const T&a,const U&b){return a<b?a:b;}
template<class T,class U>ostream&operator<<(ostream&o,const pair<T,U>&p){return o<<p.F<<' '<<p.S;}template<class T,class U>istream&operator>>(istream&i,pair<T,U>&p){return i>>p.F>>p.S;}
template<class T>class iterable{static false_type c(string v);template<class U>static auto c(U v)->decltype(all(v),true_type());static false_type c(...);public:const static bool value=decltype(c(declval<T>()))::value;};
template<class T,enable_if_t<iterable<T>::value,int> =0>ostream&operator<<(ostream&o,const T&v){for(auto&&i:v)o<<i<<' ';return o;}
template<class T>istream&operator>>(istream&i,vector<T>&v){for(T&j:v)i>>j;return i;}template<class T>vector<T>&operator<<(vector<T>&v,const T&t){v.push_back(t);return v;}
template<class T,class U>queue<T,U>&operator<<(queue<T,U>&v, const T&t){v.push(t);return v;}template<class T,class U>queue<T,U>&operator>>(queue<T,U>&v, T&t){t=v.front();v.pop();return v;}
template<class T,class U,class V>pqueue<T,U,V>&operator<<(pqueue<T,U,V>&v, const T&t){v.push(t);return v;}template<class T,class U,class V>pqueue<T,U,V>&operator>>(pqueue<T,U,V>&v, T&t){t=v.front();v.pop();return v;}
template<class T,class U>stack<T,U>&operator<<(stack<T,U>&v, const T&t){v.push(t);return v;}template<class T,class U>stack<T,U>&operator>>(stack<T,U>&v, T&t){t=v.front();v.pop();return v;}
template<class T,class U,class V>set<T,U,V>&operator<<(set<T,U,V>&v,const T&t){v.insert(t);return v;}template<class T,class U,class V>multiset<T,U,V>&operator<<(multiset<T,U,V>&v,const T&t){v.insert(t);return v;}
template<class T,enable_if_t<is_integral<T>::value,int> =0>T mod(T a, T b){if(a>0)return a%b;return b-(-a%b);}template<class T,enable_if_t<is_floating_point<T>::value,int> =0>T mod(T a, T b){if(a>0)return fmod(a,b);return b-fmod(-a,b);}
template<class T,class U>pair<T,U>&operator+=(pair<T,U>&a, const pair<T,U>&b){a.F+=b.F;a.S+=b.S;return a;}template<class T,class U>pair<T,U> operator+(const pair<T,U>&a, const pair<T,U>&b){auto r=a;return r+=b;}
template<class T,class U>pair<T,U>&operator-=(pair<T,U>&a, const pair<T,U>&b){a.F-=b.F;a.S-=b.S;return a;}template<class T,class U>pair<T,U> operator-(const pair<T,U>&a, const pair<T,U>&b){auto r=a;return r-=b;}
template<class T,class U>pair<T,U> operator-(const pair<T,U>&a){return {-a.F, -a.S};}
template<class T,class U>double norm(const pair<T,U>&p){return norm(p.F)+norm(p.S);}template<class T,class U>double abs(const pair<T,U>&p){return sqrt(norm(p));}

int main(){
    cin.tie(0);ios::sync_with_stdio(0);
    cout<<fixed<<setprecision(10);
    int n;
    cin>>n;
    vp a(n);
    cin>>a;
    vi mi(n);
    vi ma(n);
    REP(i,n){
        mi[i] = a[i].F;
        ma[i] = a[i].S;
    }
    sort(all(mi));
    sort(all(ma));

    int k = 2 - (n % 2);

    int mim = mi[(n-1)/2] + mi[n/2];
    int mam = ma[(n-1)/2] + ma[n/2];

    if(k==1){
        mim/=2;
        mam/=2;
    }

    sort(all(a));
    vp b;
    REP(i,n){
        if(b.empty())b<<P(a[i].F*k, a[i].S*k);
        else {
            auto& e = *b.rbegin();
            if(e.S >= a[i].F*k) {
                chmax(e.S, a[i].S*k);
            }else{
                b<<P(a[i].F*k, a[i].S*k);
            }
        }
    }
    dbg(mim);
    dbg(mam);
    dbg(b);
    ll ans = 0;
    REPA(i,b){
        ans += b[i].S - b[i].F + 1;
        if(b[i].F <= mim && mim <= b[i].S) {
            ans -= mim - b[i].F;
        }
        if(b[i].F <= mam && mam <= b[i].S) {
            ans -= b[i].S - mam;
        }
    }
    cout<<ans<<endl;
    
    
}

Submission status: Runtime Error

Solution code:
N=int(input())
A=[list(map(int,input().split())) for i in range(N)]
if N%2==1:
    flat=set([j for i in A for j in i])
    flat=sorted(list(flat))
    if flat[-2]==flat[1]:
        print(1)
    else:
        print(flat[-2]-flat[1]+1)
else:
    flat=set([j for i in A for j in i])
    flat=sorted(list(flat))
    if flat[-2]==flat[1]:
        print(3)
    else:
        print((flat[-2]-flat[1])*2+1)

Submission status: Runtime Error

Solution code:
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)
  arr1 = list(range(AB[k1][0], AB[k1][1] + 1))
  arr2 = list(range(AB[k2][0], AB[k2][1] + 1))
  pattern = list(itertools.product(arr1, arr2))
  ans = set()
  for p in pattern:
    ans.add(sum(p))
  print(len(ans))
  

else:
  k = int((N+1)/2)-1
  A = AB[k][0]
  B = AB[k][1]
  print(B-A+1)

Submission status: Runtime Error

Solution code:

blist.sort()
# 偶数の場合
if N % 2 == 0:
    median1 = N/2
    median2 = N/2 + 1
    median1 = int(median1) - 1
    median2 = int(median2) - 1
    amedian = (alist[median1] + alist[median2]) / 2
    bmedian = (blist[median1] + blist[median2]) / 2
    print(bmedian-amedian+1)
# 奇数の場合
else:
    median = (N + 1) / 2
    median = int(median) - 1
    amedian = alist[median]
    bmedian = blist[median]
    print((bmedian-amedian)*2+1)

Submission status: Runtime Error

Solution code:
import math
a, b = input().split()
A = int(a)
B = float(b)
print(int(A*B))

Submission status: Runtime Error

Solution code:
package main

import (
	"bufio"
	"fmt"
	"os"
	"sort"
	"strconv"
)

var sc = bufio.NewScanner(os.Stdin)

func Scanner() string {
	sc.Scan()
	return sc.Text()
}

func intScanner() int {
	n, _ := strconv.Atoi(Scanner())
	return n
}

func floatScanner() float64 {
	n, _ := strconv.ParseFloat(Scanner(), 64)
	return n
}
func stringToInt(s string) int {
	n, _ := strconv.Atoi(s)
	return n
}
func stringSliceScanner(n int) []string {
	a := make([]string, n)
	for i := 0; i < n; i++ {
		a[i] = Scanner()
	}
	return a
}
func intSliceScanner(n int) []int {
	a := make([]int, n)
	for i := 0; i < n; i++ {
		a[i] = intScanner()
	}
	return a
}

var mod int

func main() {
	mod = 1000000007
	buf := make([]byte, 0)
	sc.Buffer(buf, mod)
	sc.Split(bufio.ScanWords)
	n := intScanner()
	a := make([]int, n)
	b := make([]int, n)
	for i := 0; i < n; i++ {
		a[i] = intScanner() * 2
		b[i] = intScanner() * 2
	}
	sort.Ints(a)
	sort.Ints(b)
	am, bm := 0, 0
	if n%2 == 0 {
		am = (a[n/2] + a[n/2-1]) / 2
		bm = (b[n/2] + b[n/2-1]) / 2
	} else {
		am = a[n/2] / 2
		bm = b[n/2] / 2
	}
	fmt.Println(bm - am + 1)
}

Submission status: Runtime Error

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

if n%2 == 0:
    nec = n//2
else:
    nec = n//2+1

lbuf = buf.copy()
rbuf = buf.copy()

lbuf.sort(key=lambda x:x[0])
rbuf.sort(key=lambda x:x[1])

rind = 0
lbods = []

pos = 0
fix = 0
for i in range(n):
    temp = lbuf[i][0]
    pos += 1
    while rbuf[rind][1] <= temp:
        fix += 1
        rind += 1
        if rind == n:
            break

    lbods.append([temp,pos-fix,fix])



lbuf.sort(key=lambda x: -x[0])
rbuf.sort(key=lambda x: -x[1])

lind = 0
rbods = []

pos = 0
fix = 0
for i in range(n):
    temp = rbuf[i][1]
    pos += 1
    while lbuf[lind][0] >= temp:
        fix += 1
        lind += 1
        if lind == n:
            break

    rbods.append([temp, pos , fix])

# print(lbods)
# print(rbods)

lb = 0
rb = 0
for i in range(n):
    if lbods[i][1] == nec:
        lb = lbods[i][0]
        break

for i in range(n):
    if rbods[i][1] == nec:
        rb = rbods[i][0]

print(rb-lb+1)

Submission status: Runtime Error

Solution code:
a, b = map(float, input().split())
print(int(a * b))

Submission status: Runtime Error

Solution code:
#include <bits/stdc++.h>
#pragma GCC target("avx")
#pragma GCC optimize("O3")
#pragma GCC optimize("unroll-loops")    
using namespace std;
#define lli long long int
#define uli unsigned long long int
#define INF 999999999999
#define rep(i,m,n) for(lli i = m;i < n;i++)
#define rrep(i,m,n) for(lli i=m-1;i>=n;i--)
#define pb(n) push_back(n)
#define UE(N) N.erase(unique(N.begin(),N.end()),N.end());
#define Sort(n) sort(n.begin(), n.end())
#define Rev(n) reverse(n.begin(),n.end())
#define Out(S) cout << S << endl
#define NeOut(S) cout << S
#define HpOut(S) cout << setprecision(50) << S << endl
#define Vec(K,L,N,S) vector<L> K(N,S)
#define DV(K,L,N,M,S) vector<vector<L>> K(N,vector<L>(M,S))
#define TV(K,L,N,M,R,S) vector<vector<vector<L>>> K(N,vector<vector<L>>(M,vector<L>(R,S)))
#define pint pair<lli,lli>
#define paf(L,R) pair<L,R>
#define mod 998244353
#define MAX 10000000
#define ALL(a)  a.begin(),a.end()
#define chmax(a, b) a = (((a)<(b)) ? (b) : (a))
#define chmin(a, b) a = (((a)>(b)) ? (b) : (a))
int main(){
  ios::sync_with_stdio(false);
  cin.tie(0);
  lli A,B,C,D,E,H,W,M,K,L,R,N,num=0,sum=0,flag=0;string S,T;
  cin >> N;
  map<lli,lli>mp;
  rep(i,0,N){
    cin >> A >> B;
    mp[A]++;
    if(mp.find(B+1)==mp.end())mp[B+1]=-1;
    else mp[B+1]--;
  }
  Vec(Q,pint,0,pint(0,0));
  for(auto v:mp)Q.pb(v);
  K=Q.size();
  rep(i,1,K)Q[i].second+=Q[i-1].second;
  if(N&1)M=N/2+1;
  else M=N/2;
  rep(i,0,K)if(Q[i].second==M){
    A=(Q[i].first);
    break;
  }
  rrep(i,K,0)if(Q[i].second==M-1){
    B=(Q[i].first);
    break;
  }
  Out(B-A);
}

Submission status: Runtime Error

Solution code:
import math
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]))//2)