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: Wrong Answer

Solution code:
from operator import itemgetter, attrgetter
from collections import defaultdict
n = int(input())
l = defaultdict(int)
a = []
b = []
ll = []
ans = 0
for i in range(n):
    ta,tb = map(int,input().split())
    ll.append([ta,tb,i])
    a.append(ta)
    b.append(tb)
A = sorted(ll, key=itemgetter(0))
B = sorted(ll, key=itemgetter(1))
a.sort()
b.sort()
if n%2==0:
    a,b,c=A[n//2-1]
    d,e,f = B[n//2-1+(n%2==0)]
    ans = e-a+1
else:
    a,b,c=A[n//2]
    d,e,f = B[n//2]
    ans = b-a+1
print(ans)
# else:

Submission status: Wrong Answer

Solution code:
from sys import stdin
input = stdin.readline

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

ab.sort()

ran = []

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

ran.sort()

if N % 2 == 0:
    a1, b1 = ab[N // 2 - 1]
    a2, b2 = ab[N // 2]
    xa = (a2 - a1) / 2
    xb = (b2 - b1) / 2
    print((xb - xa) * 2 - 1)
else:
    print(ran[N // 2])

Submission status: Wrong Answer

Solution code:
from sys import stdin
input = stdin.readline
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 == 0:
    temp = N//2
    m = (A[temp]+A[temp-1])/2
    M = (B[temp]+B[temp-1])/2
    print(int(M-m+1)*2-1)
else:
    temp = N//2
    print(B[temp]-A[temp]+1)

Submission status: Wrong Answer

Solution code:
from operator import itemgetter, attrgetter
from collections import defaultdict
n = int(input())
l = defaultdict(int)
a = []
b = []
ll = []
print(l)
ans = 0
for i in range(n):
    ta,tb = map(int,input().split())
    ll.append([ta,tb,i])
    a.append(ta)
    b.append(tb)
A = sorted(ll, key=itemgetter(0))
B = sorted(ll, key=itemgetter(1))
a.sort()
b.sort()
if n%2==0:
    a,b,c=A[n//2-1]
    d,e,f = B[n//2-1+(n%2==0)]
    ans = e-a+1
else:
    a,b,c=A[n//2]
    d,e,f = B[n//2]
    ans = b-a+1
print(ans)
# else:

Submission status: Wrong Answer

Solution code:



N = int(input())
A = []
B = []
ans = 0
min_a = 10**10
max_b = 0
for _ in range(N):
    a, b = map(int, input().split())
    min_a = min(a, min_a)
    max_b = max(b, max_b)
    A.append(a)
    B.append(b)

# AB = [[int(x) for x in input().split()] for _ in range(N)]

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

else:
    A.sort()
    B.sort()
    ans = B[N//2] - A[N//2 - 1]
    ans *= 2
    ans -= 1
print(ans)

Submission status: Wrong Answer

Solution code:
from operator import itemgetter

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

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

else:
    info = sorted(info)
    l, lmax = info[n // 2 - 1]
    info = sorted(info, reverse=True, key=itemgetter(1))
    rmin, r = info[n // 2 - 1]
    length = []
    for i in range(n):
        length.append(min(r, info[i][1]) - max(l, info[i][0]) + 1)

    length = sorted(length, reverse=True)
    print(length[0] + length[1] - 1)

Submission status: Wrong Answer

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

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

else:
    info = sorted(info)
    l, lmax = info[n // 2 - 1]
    info = sorted(info, reverse=True)
    rmin, r = info[n // 2 - 1]
    length = []
    for i in range(n):
        length.append(min(r, info[i][1]) - max(l, info[i][0]) + 1)

    length = sorted(length, reverse=True)
    print(length[0] + length[1] - 1)

Submission status: Wrong Answer

Solution code:
import sys
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines
sys.setrecursionlimit(10 ** 7)

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

Submission status: Wrong Answer

Solution code:
from collections import deque
n=int(input())
ab=deque([])
abox=[]
bbox=[]
if n%2==1:
    saidai=0
    saisyou=10**9
    for i in range(n):
        a,b=map(int,input().split())
        if a<saisyou:
            saisyou=a
        if b>saidai:
            saidai=b
        abox.append(a)
        bbox.append(b)
        ab.append([a,b])
    abox.sort()
    bbox.sort()
    print(abs(abox[(n+1)//2-1]-bbox[(n+1)//2-1])+1)
else:
    saidai=0
    saisyou=10**9
    for i in range(n):
        a,b=map(int,input().split())
        if a<saisyou:
            saisyou=a
        if b>saidai:
            saidai=b
        abox.append(a)
        bbox.append(b)
        ab.append([a,b])
    abox.sort()
    bbox.sort()
    print(abs(abox[(n+1)//2-1]-bbox[(n+1)//2])+1)

Submission status: Wrong Answer

Solution code:
from sys import stdin
input = stdin.readline

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

ab.sort()

ran = []

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

ran.sort()

if N % 2 == 0:
    print(ran[N // 2] * 2 - 1)

else:
    print(ran[N // 2])

Submission status: Wrong Answer

Solution code:
#####################################
from operator import itemgetter, attrgetter
from collections import defaultdict
n = int(input())
l = defaultdict(int)
a = []
b = []
ll = []
ans = 0
for i in range(n):
    ta,tb = map(int,input().split())
    ll.append([ta,tb,i])
    a.append(ta)
    b.append(tb)
A = sorted(ll, key=itemgetter(0))
B = sorted(ll, key=itemgetter(1))
a.sort()
b.sort()
if n%2==0:
    a,b,c=A[n//2-1]
    d,e,f = B[n//2-1+(n%2==0)]
    ans = e-a+1
    ans*=2
else:
    a,b,c=A[n//2]
    d,e,f = B[n//2]
    ans = b-a+1
print(ans)

Submission status: Wrong Answer

Solution code:
n = int(input())
lister = []
for i in range(n):
    lister.append([int(i) for i in input().split()])
 
if n % 2 == 1:
    lister.sort(key=lambda x:x[0])
    miner = lister[n//2][0]
    lister.sort(key=lambda x:x[1])
    maxer = lister[n//2][1]
    print(maxer- miner + 1)
else:
    lister.sort(key=lambda x:x[0])
    miner = lister[n//2 - 1][0]
    lister.sort(key=lambda x:x[1])
    maxer = lister[n//2][1]
    print(1 + (maxer- miner) ** 2)

Submission status: Wrong Answer

Solution code:
import heapq as hp
n = int(input())
if n%2 ==0:
    m = n//2 + 1
else:
    m = (n+1) //2
a,b = [],[]
for i in range(0,n):
    c = list(map(int, input().split()))
    a.append(c[0])
    b.append(c[1])
print(a,b)
la = hp.nlargest(m,a)
lb = hp.nlargest(m,b)
if n%2 == 0:
    c = la[-1] + la[-2] 
    d = lb[-1] + lb[-2] 
    print(d-c+1)
else:
    print(lb[-1]-la[-1]+1)

Submission status: Wrong Answer

Solution code:
#####################################
from operator import itemgetter, attrgetter
from collections import defaultdict
n = int(input())
l = defaultdict(int)
a = []
b = []
ll = []
print(l)
ans = 0
for i in range(n):
    ta,tb = map(int,input().split())
    ll.append([ta,tb,i])
    a.append(ta)
    b.append(tb)
A = sorted(ll, key=itemgetter(0))
B = sorted(ll, key=itemgetter(1))
a.sort()
b.sort()
if n%2==0:
    a,b,c=A[n//2-1]
    d,e,f = B[n//2-1+(n%2==0)]
    ans = e-a+1
    ans*=2
else:
    a,b,c=A[n//2]
    d,e,f = B[n//2]
    ans = b-a+1
print(ans)

Submission status: Wrong Answer

Solution code:
import sys
import math
import heapq
sys.setrecursionlimit(10**7)
INTMAX = 9223372036854775807
INTMIN = -9223372036854775808
DVSR = 1000000007
def POW(x, y): return pow(x, y, DVSR)
def INV(x, m=DVSR): return pow(x, m - 2, m)
def DIV(x, y, m=DVSR): return (x * INV(y, m)) % m
def LI(): return [int(x) for x in sys.stdin.readline().split()]
def LF(): return [float(x) for x in sys.stdin.readline().split()]
def LS(): return sys.stdin.readline().split()
def II(): return int(sys.stdin.readline())
def FLIST(n):
    res = [1]
    for i in range(1, n+1): res.append(res[i-1]*i%DVSR)
    return res

N=II()
AS=[]
BS=[]
for i in range(N):
    A,B=LI()
    AS.append(A)
    BS.append(B)
AS.sort()
BS.sort()
if N % 2:
    print(BS[N//2]-AS[N//2]+1)
else:
    print((BS[N//2-1]-AS[N//2-1])*2+1)

Submission status: Wrong Answer

Solution code:

#!/usr/bin/python
# -*- coding: utf-8 -*-

import statistics

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

A = []
B = []

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

print(statistics.median(B)-statistics.median(A)+1)

Submission status: Wrong Answer

Solution code:
def main():
    import sys
    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:
        ma = (A[n//2]+A[n//2-1])/2
        mb = (B[n//2]+B[n//2-1])/2
        ans = int(2*(mb-ma) - 1)
        print(ans)
    else:
        ma = A[n//2]
        mb = B[n//2]
        ans = (mb-ma) +1
        print(ans)
        
        
if __name__ == '__main__':
    main()

Submission status: Wrong Answer

Solution code:
import numpy as np
N = int(input())
AB = np.array([list(map(int, input().split())) for i in range(N)])
AB_T = AB.T
A = AB_T[0].tolist()
B = AB_T[1].tolist()
if N == 2:
  X_1 = min(A)
  Y_1 = max(B)
  A.remove(min(A))
  B.remove(max(B))
  X_2 = min(A)
  Y_2 = max(B)
  X = X_2 - X_1
  Y = Y_1 - Y_2 +1
  print(X+Y)
elif N%2 == 0:
  for i in range(int(N//2)):
    A.remove(min(A))
    B.remove(max(B))
    if i == int(N//2)-1:
      X_1 = min(A)
      Y_1 = max(B)
      A.remove(min(A))
      B.remove(max(B))
      X_2 = min(A)
      Y_2 = max(B)
      X = X_2 - X_1
      Y = Y_1 - Y_2 +1
      print(X+Y)
      break
else:
  for i in range(int((N+1)//2)-1):
    A.remove(min(A))
    B.remove(max(B))
    if i == int((N+1)//2)-2:
      L_1 = min(A)
      M_1 = max(B)
      A.remove(min(A))
      B.remove(max(B))
      L_2 = min(A)
      M_2 = max(B)
      L = L_2 - L_1
      M = M_1 - M_2 +1
      print(L+M)
      break

Submission status: Wrong Answer

Solution code:
def main():
    import sys
    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:
        ma = (A[n//2]+A[n//2-1])/2
        mb = (B[n//2]+B[n//2-1])/2
        ans = 2*(mb-ma) - 1
        print(ans)
    else:
        ma = A[n//2]
        mb = B[n//2]
        ans = int((mb-ma) +1)
        print(ans)
        
        
if __name__ == '__main__':
    main()

Submission status: Wrong Answer

Solution code:
import statistics
n = int(input())
a_list = [0 for i in range(n)]
b_list = [0 for i in range(n)]
x_list = [(0,0) for i in range(n)]

for i in range(n):
  a,b = map(int,input().split())
  a_list[i] = a
  b_list[i] = b
  x_list[i] = (a,b)
  
a_sort = sorted(a_list)
b_sort = sorted(b_list)

a_med = statistics.median_low(a_list)
b_med = statistics.median_high(b_list)
print(b_med-a_med+1)

Submission status: Wrong Answer

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()
a = (A[(N-1)//2] + A[N//2]+1)//2
b = (B[(N-1)//2] + B[N//2])//2
print(b-a+1)

Submission status: Wrong Answer

Solution code:
import sys
sys.setrecursionlimit(10**7)

readline = sys.stdin.buffer.readline
def readstr():return readline().rstrip().decode()
def readstrs():return list(readline().decode().split())
def readint():return int(readline())
def readints():return list(map(int,readline().split()))
def printrows(x):print('\n'.join(map(str,x)))
def printline(x):print(' '.join(map(str,x)))


n = readint()
a = []
b = []
for i in range(n):
    x,y = readints()
    a.append(x)
    b.append(y)

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

Submission status: Wrong Answer

Solution code:
n=int(input())
import statistics
import math
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==0:
    am=statistics.mean(a)
    bm=statistics.mean(b)
    print(math.floor((bm-am)*2)+1)
else:
    aM=statistics.median(a)
    bM=statistics.median(b)
    print(bM-aM+1)

Submission status: Wrong Answer

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

a = (A[(N-1)//2] + A[N//2])//2
b = (B[(N-1)//2] + B[N//2])//2
print(b-a+1)

Submission status: Wrong Answer

Solution code:
import statistics
n = int(input())
a_list = [0 for i in range(n)]
b_list = [0 for i in range(n)]
x_list = [(0,0) for i in range(n)]

for i in range(n):
  a,b = map(int,input().split())
  a_list[i] = a
  b_list[i] = b
  x_list[i] = (a,b)
  
a_sort = sorted(a_list)
b_sort = sorted(b_list)

if n%2 == 1:
  a_med = statistics.median(a_list)
  b_med = statistics.median(b_list)
  print(b_med-a_med+1)
  
else:
  a_med = a_sort[int(n/2)-1]
  b_med = b_sort[int(n/2)]
  v = int(((b_med-a_med+1)*(b_med-a_med))/2)
  v = max(v,1)
  a_flg = True
  b_flg = True
  ab_flg = True
  for x in x_list:
    if x[0] == a_med and x[1] == b_med:
      if ab_flg == False:
        a_flg = False
        b_flg = False
      else:
      	ab_flg = False
      continue
      
    elif x[0] == a_med:
      a_flg = False
    
    elif x[1] == b_med:
      b_flg = False
  
  if a_flg and b_flg:
    v = v - (a_list[int(n/2)] + a_list[int(n/2)-1])*(b_list[int(n/2)] + b_list[int(n/2)-1])
  elif a_flg:
    v = v - a_list[int(n/2)] + a_list[int(n/2)-1]
  elif b_flg:
    v = v - b_list[int(n/2)] + b_list[int(n/2)-1]
      
  print(v)

Submission status: Wrong Answer

Solution code:
import math


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


N = int(input())
A, B = [], []
for _ in range(N):
    a, b = map(int, input().split())
    A.append(a)
    B.append(b)
A.sort()
B.sort()
x = median(A)
y = median(B)
if N % 2:
    print(y - x + 1)
else:
    temp = math.floor(y) - math.floor(x)
    print(2 * temp + 1)

Submission status: Wrong Answer

Solution code:
import sys

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

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

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

if N % 2 != 0:
    print(max(0, right - left + 1))
else:
    print(max(0, (right - left) * 2 - 1))

Submission status: Wrong Answer

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():
    n=INT()
    A=[]
    B=[]
    for i in range(n):
        a,b=INTM()
        A.append(a)
        B.append(b)
        #print(A,B)
    B=sorted(B,reverse=True)
    if n%2==1:
        ta=A[n//2]
        tb=B[n//2]
        print(tb-ta+1)
    else:
        ta1=A[n//2-1]
        ta2=A[n//2]
        tb1=B[n//2-1]
        tb2=B[n//2]
        avea=(ta1+ta2)/2
        aveb=(tb1+tb2)/2
        print(int((aveb-avea)*2)+1)
        
        
    
if __name__ == '__main__':
    do()

Submission status: Wrong Answer

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==0:
    sca=scb=N//2-1
    lca=lcb=N//2
    x=A[lca]+A[sca]
    y=B[lcb]+B[scb]
    print(x-y+1)
    
    
else:
    ca=cb=N//2
    ans=B[cb]-A[ca]+1
    print(ans)

Submission status: Wrong Answer

Solution code:
from collections import deque
n=int(input())
ab=deque([])
abox=[]
bbox=[]
if n%2==1:
    saidai=0
    saisyou=10**9
    for i in range(n):
        a,b=map(int,input().split())
        if a<saisyou:
            saisyou=a
        if b>saidai:
            saidai=b
        abox.append(a)
        bbox.append(b)
        ab.append([a,b])
    abox.sort()
    bbox.sort()
    print(abs(abox[(n+1)//2-1]-bbox[(n+1)//2-1])+1)
else:
    saidai=0
    saisyou=10**9
    for i in range(n):
        a,b=map(int,input().split())
        if a<saisyou:
            saisyou=a
        if b>saidai:
            saidai=b
        abox.append(a)
        bbox.append(b)
        ab.append([a,b])
    abox.sort()
    bbox.sort()
    print(abs(abox[(n+1)//2-1]-bbox[(n+1)//2-1])+1)

Submission status: Wrong Answer

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==0:
    sca=scb=N//2-1
    lca=lcb=N//2
    x=A[lca]+A[sca]
    y=B[lcb]+B[lcb]
    print(x-y+1)
    
    
else:
    ca=cb=N//2
    ans=B[cb]-A[ca]+1
    print(ans)

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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


if N % 2 == 0:
    maxab = ab[(N // 2) - 1][1]
    minab = ab[N // 2][0]
    x1 = ab[(N // 2) - 1][1] - ab[(N // 2) - 1][0] + 1
    x2 = ab[N // 2][1] - ab[N // 2][0] + 1
    if maxab < minab:
        print(x1 * x2)
    else:
        print(x1 * x2 - (abs(maxab - minab) + 1))
else:
    print(ab[N // 2][1] - ab[N // 2][0] + 1)

Submission status: Wrong Answer

Solution code:
import statistics
n = int(input())
a_list = [0 for i in range(n)]
b_list = [0 for i in range(n)]
x_list = [(0,0) for i in range(n)]

for i in range(n):
  a,b = map(int,input().split())
  a_list[i] = a
  b_list[i] = b
  x_list[i] = (a,b)
  
a_sort = sorted(a_list)
b_sort = sorted(b_list)

if n%2 == 1:
  a_med = statistics.median(a_list)
  b_med = statistics.median(b_list)
  print(b_med-a_med+1)
  
else:
  a_med = a_sort[int(n/2)-1]
  b_med = b_sort[int(n/2)]
  v = int(((b_med-a_med+1)*(b_med-a_med))/2)
  v = max(v,1)
  a_flg = True
  b_flg = True
  ab_flg = True
  for x in x_list:
    if x[0] == a_med and x[1] == b_med:
      if ab_flg == False:
        a_flg = False
        b_flg = False
      else:
      	ab_flg = False
      continue
      
    elif x[0] == a_med:
      a_flg = False
    
    elif x[1] == b_med:
      b_flg = False
  
  if a_flg:
    v = v - a_list[int(n/2)] + a_list[int(n/2)-1]
  if b_flg:
    v = v - b_list[int(n/2)] + b_list[int(n/2)-1]
      
  print(v)

Submission status: Wrong Answer

Solution code:

import statistics
import math

n = int(input())

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

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

Submission status: Wrong Answer

Solution code:
import sys
input = sys.stdin.buffer.readline

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()
#print(A)
#print(B)

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

Submission status: Wrong Answer

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

if n%2==0:
    print(int((x[(n//2)][-1]-x[(n//2)-1][0])//0.5)-1)
else:
    tmp = x[n//2]
    print(len(range(tmp[0], tmp[-1]+1)))

Submission status: Wrong Answer

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

ans=0
if(n%2==0):
    absort=sorted(ab,key=lambda x:x[0])
    ind=(n//2)-1
    a11=absort[ind][0]
    a12=absort[ind+1][0]

    bs=absort[ind:]
    b11=min([bs[i][1] for i in range(len(bs))])

    bs=absort[ind+1:]
    b12=min([bs[i][1] for i in range(len(bs))])

#    print(a1,b1)
#    print(a2,b2)

    absort=sorted(ab,key=lambda x:x[1])
    ind=(n//2)-1
    b21=absort[ind][1]
    b22=absort[ind+1][1]

    aas=absort[:ind+1]
    a21=max((aas[i][0] for i in range(len(aas))))

    aas=absort[:ind+2]
    a22=max([aas[i][0] for i in range(len(aas))])

    if(a21+b21<=a12+b12):
        ans+=(a22+b22)-(a11+b11)+1
    else:
        ans+=(a22+b22)-(a21+b21)+1
        ans+=(a12+b12)-(a11+b11)+1
    print(ans)

else:
    absort=sorted(ab,key=lambda x:x[0])
    ind=((n+1)//2)-1
    a1=absort[ind][0]

    bs=absort[ind:]
    b1=min([bs[i][1] for i in range(len(bs))])
#    print(a1,b1)

    absort=sorted(ab,key=lambda x:x[1])
    ind=((n+1)//2)-1
    b2=absort[ind][1]

    aas=absort[:ind+1]
    a2=max([aas[i][0] for i in range(len(aas))])
#    print(a2,b2)
    if(a2<=b1):
        ans+=b2-a1+1
    else:
        ans+=b1-a1+1
        ans+=b2-a2+1
    print(ans)

Submission status: Wrong Answer

Solution code:
import sys
sys.setrecursionlimit(10**6)
from math import floor,ceil,sqrt,factorial,log
from heapq import heappop, heappush, heappushpop
from collections import Counter,defaultdict,deque
from itertools import accumulate,permutations,combinations,product,combinations_with_replacement
from bisect import bisect_left,bisect_right
from copy import deepcopy
from operator import itemgetter
from fractions import gcd
mod = 10 ** 9 + 7
inf = float('inf')
ninf = -float('inf')
 
#整数input
def ii(): return int(sys.stdin.readline().rstrip()) #int(input())
def mii(): return map(int,sys.stdin.readline().rstrip().split())
def limii(): return list(mii()) #list(map(int,input().split()))
def lin(n:int): return [ii() for _ in range(n)]
def llint(n: int): return [limii() for _ in range(n)]
#文字列input
def ss(): return sys.stdin.readline().rstrip() #input()
def mss(): return sys.stdin.readline().rstrip().split()
def limss(): return list(mss()) #list(input().split())
def lst(n:int): return [ss() for _ in range(n)]
def llstr(n: int): return [limss() for _ in range(n)]

#本当に貪欲法か？ DP法では？？
#本当に貪欲法か？ DP法では？？
#本当に貪欲法か？ DP法では？？

n=ii()

amax=0
bmin=10**100
arra=[]
arrb=[]
for i in range(n):
    a,b=mii()
    arra.append(a)
    arrb.append(b)

arra.sort()
arrb.sort()

if n%2==1:
    p=arra[n//2 ]
    q=arrb[n//2 ]

    print(q-p+1)
else:
    p=(arra[n//2 -1]+arra[n//2])/2
    q=(arrb[n//2 -1]+arra[n//2])/2
    #print(p,q,arra[n//2-1])
    print(int((q-p+1)*2))

Submission status: Wrong Answer

Solution code:
import heapq as hp
n = int(input())
if n%2 ==0:
    m = n//2 + 1
else:
    m = (n+1) //2
a,b = [],[]
for i in (0,n):
    c = list(map(int, input().split()))
    a.append(c[0])
    b.append(c[1])
la = hp.nlargest(m,a)
lb = hp.nlargest(m,b)
if n%2 == 0:
    c = la[-1] + la[-2] 
    d = lb[-1] + lb[-2] 
    print(d-c+1)
else:
    print(lb[-1]//2-la[-1]//2+1)

Submission status: Wrong Answer

Solution code:
class Combination:
    def __init__(self, n, mod):
        fact = [0]*(n+1)
        ifact = [0]*(n+1)
        fact[0] = 1
        for i in range(1, n+1):
            fact[i] = (fact[i-1]*i) % mod
        # 1/n!を逆元で求める
        ifact[n] = pow(fact[n], mod-2, mod)
        for i in range(n, 0, -1):
            ifact[i-1] = (ifact[i]*i) % mod

        self.n = n
        self.mod = mod
        self.fact = fact
        self.ifact = ifact

    def choose(self, n, r):
        if r < 0 or r > n:
            return 0
        ret = (self.fact[n]*self.ifact[r]) % self.mod
        return (ret*self.ifact[n-r]) % self.mod


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
    print(ans)
else:
    na = len(set(A[N//2-1:]))
    nb = len(set(B[:N//2+1]))
    nc = len(set(A[N//2-1:]+B[:N//2+1]))
    m = (na+nb-nc)
    ans = na*nb-m*m
    print(ans)

Submission status: Wrong Answer

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():
    n=INT()
    A=[]
    B=[]
    for i in range(n):
        a,b=INTM()
        A.append(a)
        B.append(b)
        B=sorted(B,reverse=True)
        #print(A,B)
    if n%2==1:
        ta=A[n//2]
        tb=B[n//2]
        print(tb-ta+1)
    else:
        ta1=A[n//2-1]
        ta2=A[n//2]
        tb1=B[n//2-1]
        tb2=B[n//2]
        avea=(ta1+ta2)/2
        aveb=(tb1+tb2)/2
        print(int((aveb-avea)*2)+1)
        
        
    
if __name__ == '__main__':
    do()

Submission status: Wrong Answer

Solution code:
import heapq as hp
n = int(input())
if n%2 ==0:
    m = n//2 + 1
else:
    m = (n+1) //2
a,b = [],[]
for i in (0,n):
    c = list(map(int, input().split()))
    a.append(c[0])
    b.append(c[1])
print(a,b)
la = hp.nlargest(m,a)
lb = hp.nlargest(m,b)
if n%2 == 0:
    c = la[-1] + la[-2] 
    d = lb[-1] + lb[-2] 
    print(d-c+1)
else:
    print(lb[-1]//2-la[-1]//2+1)

Submission status: Wrong Answer

Solution code:
n=int(input())
ab,ba=[],[]
for i in range(n):
    a,b=map(int,input().split())
    ab.append([a,b])
    ba.append([b,a])
ab.sort()
ba.sort(reverse=True)
ans=0
if n%2==1:
    s=ab[n//2][0]
    g=ba[n//2][0]
    ans=g-s+1
else:
    s=ab[n//2-1][0]
    g=ba[n//2-1][0]
    ans=(g-s+1)*(g-s)//2
print(ans)

Submission status: Wrong Answer

Solution code:
class Combination:
    def __init__(self, n, mod):
        fact = [0]*(n+1)
        ifact = [0]*(n+1)
        fact[0] = 1
        for i in range(1, n+1):
            fact[i] = (fact[i-1]*i) % mod
        # 1/n!を逆元で求める
        ifact[n] = pow(fact[n], mod-2, mod)
        for i in range(n, 0, -1):
            ifact[i-1] = (ifact[i]*i) % mod

        self.n = n
        self.mod = mod
        self.fact = fact
        self.ifact = ifact

    def choose(self, n, r):
        if r < 0 or r > n:
            return 0
        ret = (self.fact[n]*self.ifact[r]) % self.mod
        return (ret*self.ifact[n-r]) % self.mod


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

Submission status: Wrong Answer

Solution code:
import sys

sys.setrecursionlimit(10 ** 7)
rl = sys.stdin.readline


class LazySegmentTree:
    def __init__(self, init_value: list, segfunc, ide_ele=0, lazy_ide_ele=0):
        self.ide_ele = ide_ele
        self.lazy_ide_ele = lazy_ide_ele
        self.segfunc = segfunc
        n = len(init_value)
        self.N0 = 1 << (n - 1).bit_length()
        self.data = [self.ide_ele] * (2 * self.N0)
        self.lazy = [self.lazy_ide_ele] * (2 * self.N0)
        
        for i, x in enumerate(init_value):
            self.data[i + self.N0 - 1] = x
        for i in range(self.N0 - 2, -1, -1):
            self.data[i] = segfunc(self.data[2 * i + 1], self.data[2 * i + 2])
    
    def gindex(self, left, right):
        L = left + self.N0
        R = right + self.N0
        lm = (L // (L & -L)) >> 1
        rm = (R // (R & -R)) >> 1
        while L < R:
            if R <= rm:
                yield R
            if L <= lm:
                yield L
            L >>= 1
            R >>= 1
        while L:
            yield L
            L >>= 1
    
    def propagates(self, *ids):
        for i in reversed(ids):
            idx = i - 1
            v = self.lazy[idx]
            if v == self.lazy_ide_ele:
                continue
            ################################################################
            self.data[2 * idx + 1] += v
            self.data[2 * idx + 2] += v
            self.lazy[2 * idx + 1] += v
            self.lazy[2 * idx + 2] += v
            ################################################################
            self.lazy[idx] = self.lazy_ide_ele
    
    def update(self, left, right, x):
        ids = tuple(self.gindex(left, right))
        ################################################################
        self.propagates(*ids)
        ################################################################
        L = self.N0 + left
        R = self.N0 + right
        
        while L < R:
            if R & 1:
                R -= 1
                ################################################################
                self.lazy[R - 1] += x
                self.data[R - 1] += x
                ################################################################
            if L & 1:
                ################################################################
                self.lazy[L - 1] += x
                self.data[L - 1] += x
                ################################################################
                L += 1
            L >>= 1
            R >>= 1
        
        for i in ids:
            idx = i - 1
            self.data[idx] = self.segfunc(self.data[2 * idx + 1], self.data[2 * idx + 2]) + self.lazy[idx]
    
    def query(self, left, right):
        self.propagates(*self.gindex(left, right))
        L = left + self.N0
        R = right + self.N0
        res = self.ide_ele
        ################################################################
        a, b = [], []
        while L < R:
            if L & 1:
                a.append(L - 1)
                L += 1
            if R & 1:
                R -= 1
                b.append(R - 1)
            L >>= 1
            R >>= 1
        for i in a + b[::-1]:
            res = self.segfunc(res, self.data[i])
        ################################################################
        return res


def solve():
    N = int(rl())
    A, B = [0] * N, [0] * N
    if N % 2 == 0:
        for i in range(N):
            ai, bi = map(int, rl().split())
            ai, bi = ai * 2, bi * 2
            A[i], B[i] = ai, bi
    else:
        for i in range(N):
            A[i], B[i] = map(int, rl().split())
    
    sorted_ab = sorted(set(A + B))
    M = len(sorted_ab)
    val_to_idx = {val: idx for idx, val in enumerate(sorted_ab)}
    
    imos = [0] * (M + 1)
    for i in range(N):
        ai, bi = A[i], B[i]
        imos[val_to_idx[ai]] += 1
        imos[val_to_idx[bi] + 1] -= 1
    for i in range(M):
        imos[i + 1] += imos[i]
    
    s = -1
    for i in range(M):
        if imos[i] == (N + 1) // 2:
            s = i
            break
    if s == -1:
        print(0)
        return
    
    t = -1
    for i in range(M, -1, -1):
        if imos[i] == (N + 1) // 2:
            t = i
            break
    if t == s:
        print(0)
        return
    ans = sorted_ab[t] - sorted_ab[s] + 1
    if N % 2 == 0:
        ans -= 2
    print(ans)


if __name__ == '__main__':
    solve()