TnT/Multi_CodeNet4Repair huggingface dataset:
Problem: 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.

Submission attempts (in order):
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)
print(min)

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)

Verdicts: Wrong Answer

Accepted
Problem: 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.

Submission attempts (in order):
import math


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


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

import math


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


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


import math


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


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


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


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)
print(y - x + 1)

Verdicts: Wrong Answer

Runtime Error

Wrong Answer

Accepted
Problem: 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.

Submission attempts (in order):

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)
    


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)
    

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


Verdicts: Wrong Answer

Wrong Answer

Accepted
Problem: 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.

Submission attempts (in order):
# E
N = int(input())
AandB = [list(map(int, input().split())) for _ in range(N)]
A = [AandB[i][0] for i in range(N)]
B = [AandB[i][1] for i in range(N)]

A_sorted = sorted(A)
B_sorted = sorted(B)

if N % 2 != 0:
    n = N // 2
    a = A_sorted[n]
    b = B_sorted[-(n+1)]
    print(b-a+1)
else:
    n = N // 2
    a = A_sorted[n-1]
    b = B_sorted[-n]

# E
N = int(input())
AandB = [list(map(int, input().split())) for _ in range(N)]
A = [AandB[i][0] for i in range(N)]
B = [AandB[i][1] for i in range(N)]

A_sorted = sorted(A)
B_sorted = sorted(B)

if N % 2 != 0:
    n = N // 2
    a = A_sorted[n]
    b = B_sorted[-(n+1)]
    print(b-a+1)
else:
    n = N // 2
    a1 = A_sorted[n-1]
    a2 = A_sorted[n]
    b1 = B_sorted[-n]
    b2 = B_sorted[-n-1]
    a = (a1 + a2) / 2
    b = (b1 + b2) / 2
    print(int((a-b)*2 + 1))

# E
N = int(input())
AandB = [list(map(int, input().split())) for _ in range(N)]
A = [AandB[i][0] for i in range(N)]
B = [AandB[i][1] for i in range(N)]

A_sorted = sorted(A)
B_sorted = sorted(B)

if N % 2 != 0:
    n = N // 2
    a = A_sorted[n]
    b = B_sorted[-(n+1)]
    print(b-a+1)
else:
    n = N // 2
    a1 = A_sorted[n-1]
    a2 = A_sorted[n]
    b1 = B_sorted[-n]
    b2 = B_sorted[-n-1]
    a = (a1 + a2) / 2
    b = (b1 + b2) / 2
    print(int((b-a)*2 + 1))

Verdicts: Wrong Answer

Wrong Answer

Accepted
Problem: 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.

Submission attempts (in order):
n = int(input())
la = []
lb = []

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

la.sort()
lb.sort()

if n % 2 == 1:
    lr = (n + 1) // 2
    ma = la[lr-1]
    mb = lb[lr-1]
    print(mb-ma+1)
else:
    l = n // 2
    r = n // 2 + 1
    ma = (la[l-1] + la[r-1]) / 2
    mb = (lb[l - 1] + lb[r - 1]) / 2
    print((mb-ma)*2+1)


n = int(input())
la = []
lb = []

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

la.sort()
lb.sort()

if n % 2 == 1:
    lr = (n + 1) // 2
    ma = la[lr-1]
    mb = lb[lr-1]
    print(mb-ma+1)
else:
    l = n // 2
    r = n // 2 + 1
    ma = (la[l-1] + la[r-1]) / 2
    mb = (lb[l - 1] + lb[r - 1]) / 2
    print(int((mb-ma)*2+1))


Verdicts: Wrong Answer

Accepted
Problem: 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.

Submission attempts (in order):
n = int(input())
a,b = [], []
for _ in range(n):
  i = input().split()
  a.append(int(i[0]))
  b.append(int(i[1]))
a.sort()
b.sort()
if n%2:
  l = a[n//2]
  h = b[n//2]
  print(l-h+1)
else :
  l = (a[n//2-1]+a[n//2]) / 2
  h = (b[n//2-1]+b[n//2]) / 2
  print(int((l-h)*2) +1)
           

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

Verdicts: Wrong Answer

Accepted
Problem: 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.

Submission attempts (in order):
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)
print(Y-X+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)))

Verdicts: Wrong Answer

Accepted
Problem: 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.

Submission attempts (in order):
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)

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]
    miner += lister[n//2][0]
    lister.sort(key=lambda x:x[1])
    maxer = lister[n//2][1]
    maxer += lister[n//2 - 1][1]
    print(1 + (maxer- miner))


Verdicts: Wrong Answer

Accepted
Problem: 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.

Submission attempts (in order):
from statistics import median

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

a = [ab[i][0] for i in range(n)]
b = [ab[i][1] for i in range(n)]

if n % 2 == 0:
    ma, mb = median(a), median(b)
    print(ma,mb)
    print(int(mb - ma) * 2 + 1)
if n % 2 == 1:
    ma, mb = median(a), median(b)
    print(int(mb - ma + 1))




from statistics import median

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

a = [ab[i][0] for i in range(n)]
b = [ab[i][1] for i in range(n)]
ma, mb = median(a), median(b)

if n % 2 == 0:
    print(int(2 * mb - 2 * ma + 1))
if n % 2 == 1:
    print(int(mb - ma + 1))


Verdicts: Wrong Answer

Accepted
Problem: 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.

Submission attempts (in order):
#!/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)



#!/usr/bin/env python3
import statistics

n = int(input())

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

a_median = statistics.median(a_list)
b_median = statistics.median(b_list)

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


Verdicts: Runtime Error

Accepted
Problem: 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.

Submission attempts (in order):
N=int(input())
A=[]
B=[]
for i in range(N):
    a,b=map(int,input().split())
    A.append(a)
    B.append(b)
A.sort()
B.sort()
if N%2!=0:
    n=(N+1)//2
    ans=B[n-1]-A[n-1]+1
else:
    n=N//2
    ans1=(A[n-1]+A[n])/2
    ans2=(B[n-1]+B[n])/2
    ans=(ans2-ans1)*2+1
print(ans)

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

Verdicts: Wrong Answer

Accepted
Problem: 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.

Submission attempts (in order):
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()

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

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

Verdicts: Wrong Answer

Wrong Answer

Accepted
Problem: 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.

Submission attempts (in order):
from sys import stdin
input = stdin.readline

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

ab.sort()

ran = []

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

ran.sort()

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


from sys import stdin
input = stdin.readline

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

ab.sort()

ran = []

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

ran.sort()

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


from sys import stdin
input = stdin.readline

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

A = []
B = []
for a, b in ab:
    A.append(a)
    B.append(b)

A.sort()
B.sort()

if N % 2 == 0:
    a1 = A[N // 2 - 1]
    b1 = B[N // 2 - 1]
    a2 = A[N // 2]
    b2 = B[N // 2]
    xa = (a2 + a1) / 2
    xb = (b2 + b1) / 2
    print(int((xb - xa) * 2 + 1))
    print("dummy")
else:
    xa = A[N // 2]
    xb = B[N // 2]
    print(xb - xa + 1)


from sys import stdin
input = stdin.readline

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

ab.sort()

ran = []

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

ran.sort()

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


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:
    xa, xb = ab[N // 2]
    print(xb - xa + 1)


from sys import stdin
input = stdin.readline

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

A = []
B = []
for a, b in ab:
    A.append(a)
    B.append(b)

A.sort()
B.sort()

if N % 2 == 0:
    a1 = A[N // 2 - 1]
    b1 = B[N // 2 - 1]
    a2 = A[N // 2]
    b2 = B[N // 2]
    xa = (a2 + a1) / 2
    xb = (b2 + b1) / 2
    print(int((xb - xa) * 2 + 1))
else:
    xa = A[N // 2]
    xb = B[N // 2]
    print(xb - xa + 1)


Verdicts: Wrong Answer

Wrong Answer

Wrong Answer

Wrong Answer

Wrong Answer

Accepted
Problem: 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.

Submission attempts (in order):
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)


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 = sorted(A)
B = sorted(B)
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)


Verdicts: Runtime Error

Accepted
Problem: 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.

Submission attempts (in order):
N = int(input())
L = list()
As, Bs= list(),list()
for i in range(N):
    A,B = map(int,input().split())
    L.append([A,B])
    As.append(A)
    Bs.append(B)

As.sort()
Bs.sort()
if N % 2 == 0:
    mins = (As[N//2] + As[N//2-1]) / 2.0
    maxs = (Bs[N//2] + Bs[N//2-1]) / 2.0
else:
    mins,maxs = As[N//2], Bs[N//2]

print(int(maxs-mins)+1)


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

As.sort()
Bs.sort()
if N % 2 == 0:
    mins = (As[N//2] + As[N//2-1]) / 2.0
    maxs = (Bs[N//2] + Bs[N//2-1]) / 2.0
    print(int((maxs-mins)/0.5)+1)
else:
    mins,maxs = As[N//2], Bs[N//2]

    print(int(maxs-mins)+1)

Verdicts: Wrong Answer

Accepted
Problem: 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.

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


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

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

l = sorted(ab, key=lambda x: x[0])
r = sorted(ab, key=lambda x: x[1])

if N % 2 == 0:
    maxab = ab[(N // 2) - 1][1]
    minab = ab[N // 2][0]
    x1 = (l[(N // 2) - 1][0] + l[N // 2][0])
    x2 = (r[(N // 2) - 1][1] + r[N // 2][1])
    print(x2 - x1 + 1)

else:
    print(r[N // 2][1] - l[N // 2][0] + 1)

Verdicts: Wrong Answer

Accepted
Problem: 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.

Submission attempts (in order):
import numpy as np
N = int(input())
A = np.zeros(N)
B = np.zeros(N)
for i in range(N):
    A[i], B[i] = map(int, input().split())

am = np.median(A)
bm = np.median(B)

if n % 2 == 0:
    print(int((bm - am) * 2 + 1))
else:
    print(int((bm - am) + 1))

n = int(input())
A = []
B = []
for _ in range(n):
    A[i], B[i] = map(int, input().split())

if n / 2 == 0:
    Am = (A[N / 2] + A[(N / 2) + 1]) / 2
    Bm = (B[N / 2] + B[(N / 2) + 1]) / 2
    print((Bm - Am) * 2 + 1)
else:
    Am = A[(N + 1) / 2]
    Bm = B[(N + 1) / 2]
    print(Bm - Am + 1)

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

if n / 2 == 0:
    Am = (A[N / 2] + A[(N / 2) + 1]) / 2
    Bm = (B[N / 2] + B[(N / 2) + 1]) / 2
    print((Bm - Am) * 2 + 1)
else:
    Am = A[(N + 1) / 2]
    Bm = B[(N + 1) / 2]
    print(Bm - Am + 1)

import numpy as np
N = int(input())
A = []
B = []
for _ in range(N):
    A[i], B[i] = map(int, input().split())

A = np.array(A)
B = np.array(B)
am = np.median(A)
bm = np.median(B)

if n % 2 == 0:
    print((bm - am) * 2 + 1)
else:
    print((bm - am) + 1)

import numpy as np
N = int(input())
A = np.zeros(N)
B = np.zeros(N)
for i in range(N):
    A[i], B[i] = map(int, input().split())

am = np.median(A)
bm = np.median(B)

if N % 2 == 0:
    print(int((bm - am) * 2 + 1))
else:
    print(int((bm - am) + 1))

Verdicts: Runtime Error

Runtime Error

Runtime Error

Runtime Error

Accepted
Problem: 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.

Submission attempts (in order):
from statistics import median

N = int(input())
A = [0] * N
B = [0] * N
for c in range(N):
    A[c], B[c] = map(int, input().split())

A_med = median(A)
B_med = median(B)

if N % 2 == 0:
    print(2 * (B_med - A_med) + 1)
else:
    print(B_med - A_med + 1)


from statistics import median

N = int(input())
A = [0] * N
B = [0] * N
for c in range(N):
    A[c], B[c] = 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)


Verdicts: Wrong Answer

Accepted
Problem: 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.

Submission attempts (in order):
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_list = []
    for x in range(A[N_q - 1], B[N_q - 1] + 1, 1):
        for y in range(A[N_q], B[N_q] + 1, 1):
            ans_list.append((x + y) / 2)
    c = collections.Counter(ans_list)
    values, counts = zip(*c.most_common())
    print(values)
    ans = len(values)
print(ans)

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)

Verdicts: Wrong Answer

Accepted
Problem: 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.

Submission attempts (in order):
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()

print(A, B)
if N % 2 == 0:
    n1 = N // 2 - 1
    n2 = N // 2
    ans = B[n1] - A[n1] + B[n2] - A[n2] + 1
    print(ans)

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

if N % 2 == 0:
    n1 = N // 2 - 1
    n2 = N // 2
    ans = B[n1] - A[n1] + B[n2] - A[n2] + 1
    print(ans)

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

Verdicts: Wrong Answer

Accepted
Problem: 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.

Submission attempts (in order):
def median_cal(data):
    num = len(data)
    data.sort()
    if num % 2 == 0:
        median1 = int(num / 2)
        median2 = int(num / 2 - 1)
        median = (data[median1] + data[median2]) / 2.0
        return median
    else:
        median = int((num + 1) / 2 - 1)
        median = data[median]
        return median

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
if n % 2 == 0:
    print(median_cal(B)*2 - median_cal(A)*2 + 1)
else:
    print(median_cal(B) - median_cal(A) + 1)

def median_cal(data):
    num = len(data)
    data.sort()
    if num % 2 == 0:
        median1 = int(num / 2)
        median2 = int(num / 2 - 1)
        median = (data[median1] + data[median2]) / 2.0
        return median
    else:
        median = int((num + 1) / 2 - 1)
        median = data[median]
        return median

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
if n % 2 == 0:
    print(int(median_cal(B)*2 - median_cal(A)*2 + 1))
else:
    print(median_cal(B) - median_cal(A) + 1)

Verdicts: Wrong Answer

Accepted
Problem: 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.

Submission attempts (in order):
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)

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)

Verdicts: Runtime Error

Accepted
Problem: 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.

Submission attempts (in order):
# -*- 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)
    


# -*- coding: utf-8 -*-

import math
import numpy as np

if __name__ == "__main__":
    N = int(input())
    AB = []
    for i in range(N):
        AB.append(list(map(int, input().split())))

    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(i, j, a,b )
        print(b - a + 1)
    else:
        i = N // 2
        a = AB[i][1] - AB[i][0] + 1

        print(a)
    
    print('end')

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

        print(a)
    


# -*- coding: utf-8 -*-

import math
import numpy as np

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

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

    print(a)



Verdicts: Runtime Error

Wrong Answer

Wrong Answer

Accepted
Problem: 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.

Submission attempts (in order):
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)


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 = A[n//2]
    lb = B[n//2]
    print(lb - sa + 1)
else:
    sal = A[n//2-1]
    sar = A[n//2]

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


Verdicts: Runtime Error

Accepted
Problem: 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.

Submission attempts (in order):
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:
    ans = Decimal(sum(B))/Decimal(2) - Decimal(sum(A))/Decimal(2)
    ans /= Decimal(0.5)
    print(int(ans))
else:
    ans = B[N//2] - A[N//2] + 1
    print(ans)

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

from sys import stdin
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:
    ans = (sum(A)/2 - sum(B)/2)
    ans /= 0.5
    print(int(ans))
else:
    ans = B[N//2] - A[N//2] + 1
    print(ans)

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

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

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

Verdicts: Wrong Answer

Runtime Error

Wrong Answer

Wrong Answer

Wrong Answer

Accepted
Problem: 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.

Submission attempts (in order):
n=int(input())
ab=[list(map(int, input().split())) for _ in range(n)]
a=[]
b=[]
for a_i, b_i in ab:
    a.append(a_i)
    b.append(b_i)
a.sort()
b.sort()

import statistics
a_med=statistics.median(a)
b_med=statistics.median(b)

if n%2==0:
    ans=2*b_med-2*a_med+1
else:
    ans=b_med-a_med+1
print(ans)

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

import statistics
a_med=statistics.median(a)
b_med=statistics.median(b)

if n%2==0:
    ans=2*b_med-2*a_med+1
else:
    ans=b_med-a_med+1
print(int(ans))

Verdicts: Wrong Answer

Accepted
Problem: 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.

Submission attempts (in order):
n = int(input())
a, b = [], []
for i in range(n):
    x, y = map(int, input().split())
    a.append(x)
    b.append(y)
a.sort()
b.sort()
if n%2==0:
    p = n//2
    right = (a[p]+a[p-1])/2 -1
    left = (b[p]+b[p-1])/2
    r = left-right
    if int(r)==r:
        print(int(r)*2)
    else:
        print(int(r)*2 +1)
else:
    p = n//2
    right = a[p]
    left = b[p]
    print(int(left-right)+1)

n = int(input())
ab = [list(map(int, input().split())) for _i in range(n)]
x, y = [], []
for i, j in ab:
    x.append(i)
    y.append(j)
x.sort()
y.sort()
p = n//2
if n%2==0:
    p -= 1
    result = (x[p+1]-x[p]+1)*(y[p+1]-y[p]+1)
else:
    result = x[p+1]-x[p]+y[p]-y[p-1]
    if x[p+1]==y[p-1]:
        result += 1
    else:
        result += 2
print(result)

n = int(input())
a, b = [], []
for i in range(n):
    x, y = map(int, input().split())
    a.append(x)
    b.append(y)
a.sort()
b.sort()
if n%2==0:
    p = n//2
    right = (a[p]+a[p-1])/2 - 0.5
    left = (b[p]+b[p-1])/2
    r = left-right
    if int(r)==r:
        print(int(r)*2)
    else:
        print(int(r)*2 +1)
else:
    p = n//2
    right = a[p]
    left = b[p]
    print(int(left-right)+1)

Verdicts: Wrong Answer

Wrong Answer

Accepted
Problem: 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.

Submission attempts (in order):
import statistics

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

if N % 2 == 0:
    print(round(2 * Bm - Am) + 1)
else:
    print(Bm - Am + 1)

import statistics
import math

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)

print(Am)
print(Bm)

if N % 2 == 0:
    print(2 * round(Bm - Am) + 1)
else:
    print(round(Bm - Am) + 1)

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)

Verdicts: Wrong Answer

Wrong Answer

Accepted
Problem: 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.

Submission attempts (in order):
arr = []
a,b = [],[]
for _ in range(int(input())):
    x,y = list(map(int,input().split()))
    a.append(x)
    b.append(y)
    arr.append([x,y])
arr.sort()
n = len(arr)
if n%2!=0:
    x = n//2
    print(arr[x][1]-arr[x][0]+1)
else:
    x = n//2
    y = x-1
    minn = (arr[x][0]+arr[y][0])/2
    maxx = (arr[x][1]+arr[y][1])/2
    print(minn,maxx)
    ans = (maxx-minn)/0.5
    print(int(ans)+1)

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


Verdicts: Wrong Answer

Accepted
Problem: 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.

Submission attempts (in order):
import numpy as np

N = int(input())
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])

if N%2 == 1:
    a_median = np.median(a_list)
    b_median = np.median(b_list)
    print(b_median-a_median+1)
elif N%2 == 0:
    a_median = np.median(a_list)
    b_median = np.median(b_list)
    print(2*(b_median-a_median)+1)

from decimal import Decimal

N = Decimal(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])

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

import numpy as np

N = int(input())
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])

if N%2 == 1:
    a_median = np.median(a_list).astype('int')
    b_median = np.median(b_list).astype('int')
    print(b_median-a_median+1)
elif N%2 == 0:
    a_median = np.median(a_list).astype('int')
    b_median = np.median(b_list).astype('int')
    print(2*(b_median-a_median+1))

N = int(input
med = 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])

if N%2 == 1:
    a_med = a_list[t]
    b_median = b_list[t]
    print(b_list-a_list+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))


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

Verdicts: Wrong Answer

Runtime Error

Wrong Answer

Runtime Error

Accepted
Problem: 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.

Submission attempts (in order):
def main():
    n = int(input())
    a = [None]*n
    b = [None]*n
    for i in range(n):
        a[i],b[i] = map(int, input().split())
    a.sort()
    b.sort()    
    if n&1:
        print(b[n//2]-a[n//2]+1)
    else:
        print(b[n//2-1]+b[n//2]-a[n//2]+1)
            
if __name__ == "__main__":
    main()

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])
            
if __name__ == "__main__":
    main()

Verdicts: Wrong Answer

Accepted
Problem: 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.

Submission attempts (in order):
# E

N = int(input())

ab = []

for i in range(N):
  ab.append(tuple(map(int,input().split())))

ab.sort()
  
import statistics
import math

am = statistics.median([i[0] for i in ab])
bm = statistics.median([i[1] for i in ab])

print(am,bm)
if am%0.5 != 0:
  print(bm-am+1)
else:
  print(int(bm-am+2))


# E

N = int(input())

ab = []

for i in range(N):
  ab.append(tuple(map(int,input().split())))

ab.sort()
  
import statistics
import math

am = statistics.median([i[0] for i in ab])
bm = statistics.median([i[1] for i in ab])

if N%2 != 0:
  print(bm-am+1)
else:
  print(int((bm-am)*2+1))


Verdicts: Wrong Answer

Accepted
Problem: 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.

Submission attempts (in order):
n=int(input(""))
a=[]
b=[]
for i in range(n):
    cc=input("").split(" ")
    a+=[int(cc[0])]
    b+=[int(cc[1])]
s=0
a.sort()
b.sort()
if (n%2==0):
    s=(a[n/2]+a[n/2-1]-b[n/2]-b[n/2-1])/2
else:
    s=a[int((n+1)/2)]-b[int((n+1)/2)]
print(-s+1)


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


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

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


Verdicts: Runtime Error

Runtime Error

Runtime Error

Accepted
Problem: 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.

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

aa, ba, aidx = zip(*sorted(zip(a, b, range(n))))  
bb, ab, bidx = zip(*sorted(zip(b, a, range(n))))  

if n % 2:
    print(bb[n // 2] - aa[n // 2] + 1)
else:
    if aidx[n // 2 - 1] == bidx[n // 2]:
        ans = 0
        vis = []
        for i in range(aa[n // 2 - 1], bb[n // 2 - 1] + 1):
            for j in range(aa[n // 2], bb[n // 2] + 1):
                if i + j not in vis:
                    ans += 1
                    vis.append(i + j)
    else:
        ans = 0
        vis = []
        for i in range(aa[n // 2 - 1], bb[n // 2 - 1] + 1):
            for j in range(aa[n // 2], bb[n // 2 - 1] + 1):
                if i + j not in vis:
                    ans += 1
                    vis.append(i + j)
    print(ans)


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



Verdicts: Wrong Answer

Accepted
Problem: 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.

Submission attempts (in order):
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)

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)

Verdicts: Runtime Error

Accepted
Problem: 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.

Submission attempts (in order):

#!/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)



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

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

A.sort()
B.sort()

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)


Verdicts: Wrong Answer

Accepted
Problem: 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.

Submission attempts (in order):
from statistics import median


def main():
    N = int(input())
    A = [None] * N
    B = [None] * N
    for i in range(N):
        A[i], B[i] = map(int, input().split())
    min_median = median(A)
    max_median = median(B)
    if N % 2 == 1:
        print(max_median - min_median + 1)
    else:
        print(max_median, min_median)
        print(round((max_median-min_median)*2)+1)


if __name__ == "__main__":
    main()


from statistics import median


def main():
    N = int(input())
    A = [None] * N
    B = [None] * N
    for i in range(N):
        A[i], B[i] = map(int, input().split())
    min_median = median(A)
    max_median = median(B)
    if N % 2 == 1:
        print(max_median - min_median + 1)
    else:
        print(round((max_median-min_median)*2)+1)


if __name__ == "__main__":
    main()


Verdicts: Wrong Answer

Accepted
Problem: 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.

Submission attempts (in order):
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)

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)

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

Verdicts: Runtime Error

Runtime Error

Accepted
Problem: 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.

Submission attempts (in order):
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+2]-b[n//2+1]) - (a[n//2+2]-a[n//2+1]) +1)



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)


Verdicts: Runtime Error

Accepted