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):
import sys
import  math
import fractions
from collections import defaultdict
stdin = sys.stdin
     
ns = lambda: stdin.readline().rstrip()
ni = lambda: int(stdin.readline().rstrip())
nm = lambda: map(int, stdin.readline().split())
nl = lambda: list(map(int, stdin.readline().split()))


N=int(input())
min_l=[]
max_l=[]
for k in range(N):
    A,B=nm()
    min_l.append(A)
    max_l.append(B)

min_l.sort()
max_l.sort()

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

import sys
import  math
import fractions
from collections import defaultdict
stdin = sys.stdin
     
ns = lambda: stdin.readline().rstrip()
ni = lambda: int(stdin.readline().rstrip())
nm = lambda: map(int, stdin.readline().split())
nl = lambda: list(map(int, stdin.readline().split()))


N=int(input())
min_l=[]
max_l=[]
for k in range(N):
    A,B=nm()
    min_l.append(A)
    max_l.append(B)

min_l.sort()
max_l.sort()

if(N%2==0):
    print(int(((max_l[N//2-1]+max_l[N//2])/2-(min_l[N//2-1]+min_l[N//2])/2)*2+1))    
else:
    print(((max_l[(N-1)//2])-(min_l[(N-1)//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 sys
sys.setrecursionlimit(10000000)
MOD = 10 ** 9 + 7
INF = 10 ** 15
  
def main():
    N = int(input())
    A = []
    B = []
    for _ in range(N):
        a,b = map(int,input().split())
        A.append(a)
        B.append(b)
    
    A.sort()
    B.sort()
    if N%2 == 0:
        L = (A[N//2 - 1] + A[N//2])/2
        R = (B[N//2 - 1] + B[N//2])/2
        ans = (R - L + 1) * 2 - 1
    else:
        L = A[N//2]
        R = B[N//2]
        ans = R - L + 1
    print(ans)
if __name__ == '__main__':
    main()

import sys
sys.setrecursionlimit(10000000)
MOD = 10 ** 9 + 7
INF = 10 ** 15
  
def main():
    N = int(input())
    A = []
    B = []
    for _ in range(N):
        a,b = map(int,input().split())
        A.append(a)
        B.append(b)
    
    A.sort()
    B.sort()
    if N%2 == 0:
        L = (A[N//2 - 1] + A[N//2])
        R = (B[N//2 - 1] + B[N//2])
        ans = (R - L + 1)
    else:
        L = A[N//2]
        R = B[N//2]
        ans = R - L + 1
    print(ans)
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):
def median(A,N):
    A.sort()
    if N % 2 == 1:
        return A[N//2]
    else:
        return (A[(N-1)//2] + A[(N-1)//2+1])/2

def main():
    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 == 1:
        ans = max(int(median(B,N)-median(A,N))+1,0)
    else:
        ans = max(2*int(median(B,N)-median(A,N))+1,0)
    print(median(B,N))
    print(median(A,N))
    print(ans)

if __name__ == "__main__":
    main()


def median(A,N):
    A.sort()
    if N % 2 == 1:
        return A[N//2]
    else:
        return A[(N-1)//2] + A[(N-1)//2+1]

def main():
    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)]

    ans = median(B,N) - median(A,N) + 1
    print(ans)

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())
s = []
zyogen = []
kagen = []
for i in range(n):
    k, z = map(int, input().split())
    kagen.append(k)
    zyogen.append(z)

kk = sorted(kagen)
zz = sorted(zyogen)
if(n % 2 == 0):
    aa = n // 2
    x = kk[aa-1] + kk[a]
    y = zz[aa-1] + zz[a]
    print(y-x+1)
else:
    aa = n // 2
    x = kk[aa]
    y = zz[aa]
    print(y-x+1)
    

n = int(input())
s = []
zyogen = []
kagen = []
for i in range(n):
    k, z = map(int, input().split())
    kagen.append(k)
    zyogen.append(z)

kk = sorted(k)
zz = sorted(z)
if(n % 2 == 0):
    aa = n // 2
    x = kk[aa-1]
    y = zz[aa]
    print(y-x+1)
else:
    aa = n // 2
    x = kk[aa]
    y = zz[aa]
    print(y-x+1)
    

n = int(input())
s = []
zyogen = []
kagen = []
for i in range(n):
    k, z = map(int, input().split())
    kagen.append(k)
    zyogen.append(z)

kk = sorted(k)
zz = sorted(z)
if(n % 2 == 0):
    aa = n // 2
    x = kk[aa-1] + kk[a]
    y = zz[aa-1] ++ + zz[a]
    print(y-x+1)
else:
    aa = n // 2
    x = kk[aa]
    y = zz[aa]
    print(y-x+1)
    

n = int(input())
s = []
zyogen = []
kagen = []
for i in range(n):
    k, z = map(int, input().split())
    kagen.append(k)
    zyogen.append(z)

kk = sorted(k)
zz = sorted(z)
if(n % 2 == 0):
    aa = n // 2
    x = kk[aa-1] + kk[a]
    y = zz[aa-1] + zz[a]
    print(y-x+1)
else:
    aa = n // 2
    x = kk[aa]
    y = zz[aa]
    print(y-x+1)
    

n = int(input())
s = []
zyogen = []
kagen = []
for i in range(n):
    k, z = map(int, input().split())
    kagen.append(k)
    zyogen.append(z)

kk = sorted(k)
zz = sorted(z)
if(n % 2 == 0):
    aa = n // 2
    x = kk[aa-1]
    y = zz[aa]
    print(y-x+1)
else:
    aa = n // 2
    x = kk[aa]
    y = zz[aa]
    print(y-x+1)
    

n = int(input())
s = []
zyogen = []
kagen = []
for i in range(n):
    k, z = map(int, input().split())
    kagen.append(k)
    zyogen.append(z)

kk = sorted(kagen)
zz = sorted(zyogen)
if(n % 2 == 0):
    aa = n // 2
    x = kk[aa-1] + kk[aa]
    y = zz[aa-1] + zz[aa]
    print(y-x+1)
else:
    aa = n // 2
    x = kk[aa]
    y = zz[aa]
    print(y-x+1)
    

Verdicts: Runtime Error

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):
N = int(input())
lower = []
upper = []
for i in range(N):
    a, b = map(int, input().split())
    lower.append(a)
    upper.append(b)
lower.sort()
upper.sort()
if N % 2 == 1:
    print(upper[(N+1)//2]-lower[(N+1)//2]+1)
else:
    print(upper[N//2 + 1]+upper[N//2]-lower[N//2 + 1]-lower[N//2]+1)

N = int(input())
lower = []
upper = []
for i in range(N):
    a, b = map(int, input().split())
    lower.append(a)
    upper.append(b)
lower.sort()
upper.sort()
if N % 2 == 1:
    print(upper[(N-1)//2]-lower[(N-1)//2]+1)
else:
    print(upper[N//2]+upper[N//2 - 1]-lower[N//2]-lower[N//2 - 1]+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):
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)



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)



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

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 sys

sys.setrecursionlimit(10 ** 7)

read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines

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

LINE = []
for a, b in AB:
    LINE.append((a, 0))
    LINE.append((b + 1, 1))

LINE.sort()

ans = 0

small = 0
small_able = 0
prevx = -1


if N % 2 == 1:

    mn = 10 ** 10
    mx = 0

    flg = False

    for x, p in LINE:
        if p == 0:
            small_able += 1
        elif p == 1:
            small += 1

        if (small_able - small) >= ((N + 1) // 2):
            flg = True
            mn = min(mn, x)

        if flg and not (small_able - small) >= ((N + 1) // 2):
            mx = max(mx, x - 1)
            flg = False

else:
    mn_0 = 10 ** 10
    mn_1 = 10 ** 10
    mx_0 = 0
    mx_1 = 0

    flg_0 = False
    flg_1 = False

    for x, p in LINE:
        if p == 0:
            small_able += 1
        elif p == 1:
            small += 1

        # N // 2
        if (small_able - small) >= ((N) // 2):
            flg_0 = True
            mn_0 = min(mn_0, x)

        if flg_0 and not (small_able - small) >= ((N) // 2):
            mx_0 = max(mx_0, x - 1)
            flg_0 = False

        # N // 2 + 1
        if (small_able - small) >= ((N // 2) + 1):
            flg_1 = True
            mn_1 = min(mn_1, x)

        if flg_1 and not (small_able - small) >= ((N // 2) + 1):
            mx_1 = max(mx_1, x - 1)
            flg_1 = False

    mn = mn_0 + mn_1
    mx = mx_0 + mx_1

    print(mn, mx)


print(mx - mn + 1)


import sys
from collections import defaultdict

sys.setrecursionlimit(10 ** 7)

read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines

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

LINE = defaultdict(lambda: [0, 0])
for a, b in AB:
    LINE[a][0] += 1
    LINE[b + 1][1] += 1

LINE = list(LINE.items())
LINE.sort()

ans = 0

small = 0
small_able = 0
prevx = -1


if N % 2 == 1:

    mn = 10 ** 10
    mx = 10 ** 10

    flg = False

    for x, p in LINE:
        small_able += p[0]
        small += p[1]

        if small < (N + 1) // 2 and ((N + 1) // 2) <= small_able:
            mn = min(x, mn)

        if (N + 1) // 2 <= small:
            mx = min(mx, x - 1)
            break


else:
    mn_0 = 10 ** 10
    mn_1 = 10 ** 10
    mx_0 = 10 ** 10
    mx_1 = 10 ** 10

    flg_0 = False
    flg_1 = False

    for x, p in LINE:
        small_able += p[0]
        small += p[1]

        if small < N // 2 and (N // 2) <= small_able:
            mn_0 = min(x, mn_0)

        if N // 2 <= small:
            mx_0 = min(mx_0, x - 1)

        if small < (N // 2) + 1 and (N // 2) + 1 <= small_able:
            mn_1 = min(x, mn_1)

        if (N // 2) + 1 <= small:
            mx_1 = min(mx_1, x - 1)
            break

    mn = mn_0 + mn_1
    mx = mx_0 + mx_1


print(mx - mn + 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 sys
import math
from collections import deque

sys.setrecursionlimit(1000000)
MOD = 10 ** 9 + 7
input = lambda: sys.stdin.readline().strip()
NI = lambda: int(input())
NMI = lambda: map(int, input().split())
NLI = lambda: list(NMI())
SI = lambda: input()


def make_grid(h, w, num): return [[int(num)] * w for _ in range(h)]



def make_adjlist_d(n, edges):
    res = [[] for _ in range(n + 1)]
    for edge in edges:
        res[edge[0]].append(edge[1])
        res[edge[1]].append(edge[0])
    return res


def make_adjlist_nond(n, edges):
    res = [[] for _ in range(n + 1)]
    for edge in edges:
        res[edge[0]].append(edge[1])
    return res


#nCr
def cmb(n, r):
    return math.factorial(n) // math.factorial(r) // math.factorial(n - r)


def main():
    N = NI()
    A = []
    B = []
    for i in range(N):
        a, b = NMI()
        A.append(a)
        B.append(b)
    A.sort()
    B.sort()

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

    ll = A[N//2-1]
    lr = A[N//2]
    rl = B[N//2-1]
    rr = B[N//2]
    l = (ll+lr)/2
    r = (rl+rr)/2
    gap = r-l
    print(gap*2+1)



if __name__ == "__main__":
    main()

import sys
import math
from collections import deque

sys.setrecursionlimit(1000000)
MOD = 10 ** 9 + 7
input = lambda: sys.stdin.readline().strip()
NI = lambda: int(input())
NMI = lambda: map(int, input().split())
NLI = lambda: list(NMI())
SI = lambda: input()


def make_grid(h, w, num): return [[int(num)] * w for _ in range(h)]



def make_adjlist_d(n, edges):
    res = [[] for _ in range(n + 1)]
    for edge in edges:
        res[edge[0]].append(edge[1])
        res[edge[1]].append(edge[0])
    return res


def make_adjlist_nond(n, edges):
    res = [[] for _ in range(n + 1)]
    for edge in edges:
        res[edge[0]].append(edge[1])
    return res


#nCr
def cmb(n, r):
    return math.factorial(n) // math.factorial(r) // math.factorial(n - r)


def main():
    N = NI()
    A = []
    B = []
    for i in range(N):
        a, b = NMI()
        A.append(a)
        B.append(b)
    A.sort()
    B.sort()

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

    ll = A[N//2-1]
    lr = A[N//2]
    rl = B[N//2-1]
    rr = B[N//2]
    l = (ll+lr)/2
    r = (rl+rr)/2
    gap = r-l
    print(int(gap*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())
A = [0 for _ in range(N)]
B = [0 for _ in range(N)]
import statistics
for k in range(N):
  A[k], B[k] = map(int, input().split())

if N%2 == 1:
  print(statistics.median(B) - statistics.median(A) +1)
else:
  print((statistics.median(B) - statistics.median(A))*2 +1)

N = int(input())
A = [0 for _ in range(N)]
B = [0 for _ in range(N)]
import statistics
for k in range(N):
  A[k], B[k] = map(int, input().split())

if N%2 == 1:
  print(statistics.median(B) - statistics.median(A) +1)
else:
  print(int((statistics.median(B) - statistics.median(A))*2 +1))

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


import sys
read = sys.stdin.read
readline = sys.stdin.readline
readlines = sys.stdin.readlines

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

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

    A.sort()
    B.sort()

    if N % 2 == 0:
        a1, a2 = A[N // 2 - 1], A[N // 2]
        b1, b2 = B[N // 2 - 1], B[N // 2]

        ans = b1 + b2 - (a1 + a2) + 1
    
    else:
        a = A[N // 2]
        b = B[N // 2]
        
        ans = b - a + 1
    
    print(ans)


if __name__ == "__main__":
    main()


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 statistics import median

n = int(input())

a = []
b = []

for _ in range(n):
    x, y = map(int, input().split())
    a.append(x)
    b.append(y)

print(median(b) - median(a) + 1)


n = int(input())

a = []
b = []

for _ in range(n):
    x, y = map(int, input().split())
    a.append(x)
    b.append(y)

a.sort()
b.sort()

x, y = 0, 0

if n % 2 == 1:
    x = b[n//2]
    y = a[n//2]
else:
    x = b[n//2] + b[n//2-1]
    y = a[n//2] + a[n//2-1]

print(x-y+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):
    tm, p = map(int, input().split())
    A.append(tm), B.append(p)
A.sort(), B.sort()

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


N = int(input())
A, B = [], []
for i in range(N):
    tm, p = map(int, input().split())
    A.append(tm), B.append(p)
A.sort(), B.sort()

a = A[N // 2] * 2 if N % 2 == 1 else A[N // 2 - 1] + A[N // 2]
b = B[N // 2] * 2 if N % 2 == 1 else B[N // 2 - 1] + B[N // 2]

print((b - a) // 2 + 1 if N % 2 == 1 else b - a + 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())
AB = [int(input().split()) for _ in range(n)]
 
A = AB[::2]
B = AB[1::2]
 
A.sort()
B.sort()
 
if N % 2 == 0:
    n = N // 2
    med1 = A[n - 1] + A[n]
    med2 = B[n - 1] + B[n]
    x = med2 - med1 + 1
else:
    n = N // 2
    med1 = A[n]
    med2 = B[n]
    x = med2 - med1 + 1
 
print(x)

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


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())
x = [[int(i) for i in input().split()] for _ in range(n)]
x.sort(key=lambda x:x[0])
y = sorted(x,key=lambda x:x[1],reverse=True)
if n%2 == 1:
    c = n//2
    if x[c][1] >= y[c][0]:
        ans = y[c][1] - x[c][0] + 1
    else:
        ans = x[c][1] - x[c][0] + y[c][1] - y[c][0] + 2
    print(ans)
else:
    cl = n//2-1
    cr = n//2-1
    lr = x[cl][1]
    rl = y[cr][0]
    print(lr,rl)
    for i in range(n):
        if x[i][0] <= x[cl][0] <= x[i][1]:
            lr = max(lr,x[i][1])
        if x[i][0] <= x[cr][1] <= x[i][1]:
            rl = min(rl, x[i][0])
    print(lr,rl)
    if rl > lr:
        ans = (lr - x[cl][0] + 1)*(y[cr][1]-rl+1)
    else:
        ans = (y[cr][1]-x[cl][0]+1)*(y[cr][1]-x[cl][0])//2
    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 == 1:
    m = n//2
    ans = b[m] - a[m] + 1
else:
    ml = n//2-1
    mr = n//2
    ma = (a[ml] + a[mr])/2 
    mb = (b[ml] + b[mr])/2
    ans = int((mb - ma)*2 + 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 = []
B = []
for _ in range(N):
    a,b = map(int,input().split())
    A.append(a)
    B.append(b)
A.sort()
B.sort()
from statistics import median
Am = median(A)
Bm = median(B)
if N%2==1:
    ans = Bm-Am+1
else:
    ans = int(Bm-Am)*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()
from statistics import median
Am = median(A)
Bm = median(B)
if N%2==1:
    ans = Bm-Am+1
else:
    ans = int((Bm-Am)*2+1)

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

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

ls = []
rs = []
for _ in range(n):
    x, y = map(int, input().split())
    ls.append(x)
    rs.append(y)

if n % 2 == 1:
    print(rs[len(rs)//2] - ls[len(ls)//2] + 1)
else:
    a = (rs[len(rs)//2-1] * 10 + rs[len(rs)//2] * 10) / 2
    b = (ls[len(ls)//2-1] * 10 + ls[len(ls)//2] * 10) / 2
    print((a - b) // 5 + 1)

n = int(input())

ls = []
rs = []
for _ in range(n):
    x, y = map(int, input().split())
    ls.append(x)
    rs.append(y)

ls = sorted(ls)
rs = sorted(rs)

if n % 2 == 1:
    print(rs[len(rs)//2] - ls[len(ls)//2] + 1)
else:
    a = (rs[len(rs)//2-1] * 10 + rs[len(rs)//2] * 10) // 2
    b = (ls[len(ls)//2-1] * 10 + ls[len(ls)//2] * 10) // 2
    print((a - b) // 5 + 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):
# -*- coding:utf-8 -*-

def solve():
    N = int(input())
    Ls, Rs = [], []
    for i in range(N):
        a, b = list(map(int, input().split()))
        Ls.append(a), Rs.append(b)

    ans = 0
    if N%2 == 0:
        
        l = Ls[N//2]
        r = Rs[N//2]
        ans = r-l+1
    else:
        
        l2 = Ls[N//2-1]+Ls[N//2]
        r2 = Rs[N//2-1]+Rs[N//2]
        ans = r2-l2+1

    print(ans)


if __name__ == "__main__":
    solve()


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

def solve():
    N = int(input())
    Ls, Rs = [], []
    for i in range(N):
        a, b = list(map(int, input().split()))
        Ls.append(a), Rs.append(b)
    Ls.sort(), Rs.sort()

    ans = 0
    if N%2 == 1:
        
        l = Ls[N//2]
        r = Rs[N//2]
        ans = r-l+1
    else:
        
        l2 = Ls[N//2-1]+Ls[N//2]
        r2 = Rs[N//2-1]+Rs[N//2]
        ans = r2-l2+1

    print(ans)


if __name__ == "__main__":
    solve()


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())
l = []
for _ in range(N):
    A, B = map(int, input().split())
    l.append((A, B))

t = N//2
tl = sorted(l)
tr = sorted(l, key=lambda x:-x[1])

if N%2:
    print(tr[t][1]-tl[t][0]+1)
else:
    print(1)


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


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 bisect
n = int(input())
a = []
b = []

for i in range(n):
    m, p = map(int, input().split())
    a.append(m)
    b.append(p)
a.sort()
b.sort()
middle = n // 2
if n % 2:
    print(b[middle] - a[middle] + 1)
else: 
    a_m = ( a[middle] + a[middle - 1] ) / 2
    b_m = ( b[middle] + b[middle - 1] ) / 2
    print((b_m - a_m) * 2 + 1)






import bisect
n = int(input())
a = []
b = []

for i in range(n):
    m, p = map(int, input().split())
    a.append(m)
    b.append(p)
a.sort()
b.sort()
middle = n // 2
if n % 2:
    print(b[middle] - a[middle] + 1)
else: 
    a_m = ( a[middle] + a[middle - 1] ) / 2
    b_m = ( b[middle] + b[middle - 1] ) / 2
    print(int((b_m - a_m) * 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 ):
  a, b = map( int, input().split() )
  A.append( a )
  B.append( b )

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

if n % 2 == 0:
  i1 = n // 2 - 1
  i2 = n // 2
  print( (( B[ i2 ] + A[ i2 ] ) - ( B[ i1 ] + A[ i1 ] )) // 2 + 1 )
else:
  i = ( n + 1 ) // 2 - 1
  print( B[ i ] - A[ i ] + 1 )
  


n = int( input())
A = []
B = []

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

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

if n % 2 == 0:
  i1 = n // 2 - 1
  i2 = n // 2
  print( ( B[ i2 ] - A[ i2 ] ) * ( B[ i1 ] - A[ i1 ] ) )
else:
  i = ( n + 1 ) // 2 - 1
  print( B[ i ] - A[ i ] + 1 )
  


n = int( input())
A = []
B = []

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

sorted( A )
sorted( B )

if n % 2 == 0:
  i1 = n // 2 - 1
  i2 = n // 2
  print( (( B[ i2 ] + A[ i2 ] ) - ( B[ i1 ] + A[ i1 ] )) // 2 + 1 )
else:
  i = ( n + 1 ) // 2 - 1
  print( B[ i ] - A[ i ] + 1 )
  


n = int( input() )
A = []
B = []

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

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

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

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

ret = 0
if n % 2 == 0:
  i = n // 2 - 1
  ret = B[ i + 1 ] + B[ i ] - ( A[ i + 1 ] + A[ i ] ) + 1
else:
  i = ( n + 1 ) // 2 - 1
  ret = B[ i ] - A[ i ] + 1
  
print( ret )

Verdicts: 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):
n = int(input())
ab = [list(map(int, input().split())) for _ in range(n)]
ab.sort()
l = ab[(n+1)//2-1][0]
ab.sort(key=lambda x:x[1], reverse=True)
r = ab[(n+1)//2-1][1]

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

n = int(input())
ab = [list(map(int, input().split())) for _ in range(n)]
ab.sort()
l = ab[(n+1)//2-1][0]
ab.sort(key=lambda x:x[1], reverse=True)
r = ab[(n+1)//2-1][1]

print(l,r)
print(r-l+1)

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

if n % 2:

    ab.sort()
    l = ab[(n+1)//2-1][0]

    ab.sort(key=lambda x:x[1], reverse=True)
    r = ab[(n+1)//2-1][1]

    print(r-l+1)

else:

    a = [ai for ai, bi in ab]
    b = [bi for ai, bi in ab]

    a.sort()
    b.sort()

    ll = a[n//2-1]
    lr = b[n//2-1]

    rl = a[n//2]
    rr = b[n//2]


    print((lr+rr) - (ll+rl) + 1)

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


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


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())
AB = [tuple(map(int, input().split())) for i in range(n)]
A = [AB[i][0] for i in range(n)]
B = [AB[i][1] for i in range(n)]



A.sort()
B.sort()

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

print(A, B)

if n % 2 == 0:
    # x = abs(A[n // 2 - 1] + B[n // 2])
    
    # print(x, y)
    # print(abs(x - y) + 1)

    # print(x, y)
    a = A[n // 2] + A[n // 2 - 1]
    b = B[n // 2] + B[n // 2 - 1]
    print(b-a+1)
    # print(a, b)
    # print(B[n // 2] - A[n // 2 - 1] + 1)


n = int(input())
AB = [tuple(map(int, input().split())) for i in range(n)]
A = [AB[i][0] for i in range(n)]
B = [AB[i][1] for i in range(n)]



A.sort()
B.sort()

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

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


n = int(input())
AB = [tuple(map(int, input().split())) for i in range(n)]
A = [AB[i][0] for i in range(n)]
B = [AB[i][1] for i in range(n)]



A.sort()
B.sort()

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


if n % 2 == 0:
    # x = abs(A[n // 2 - 1] + B[n // 2])
    
    # print(x, y)
    # print(abs(x - y) + 1)

    # print(x, y)
    a = A[n // 2] + A[n // 2 - 1]
    b = B[n // 2] + B[n // 2 - 1]
    print(b - a + 1)
    # print(a, b)
    # print(B[n // 2] - A[n // 2 - 1] + 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())
a = []
b = []
for i in range(n):
    a[i],b[i] = map(int, input().split())
a.sort()
b.sort()
if n%2 == 1:
    	print(b[(n+1)//2]-a[(n+1)//2]+1)
else:
	print(b[n//2]-a[n//2]+b[n//2+1]-a[n//2+1]+1)

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

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):
def main(N, lines):
    a = sorted(map(lambda line: line[0], lines))
    b = sorted(map(lambda line: line[1], lines))

    if N % 2 == 1:
        mi = a[N // 2]
        ma = b[N // 2]
        print(ma - mi + 1)
    else:
        mi = (a[N // 2 - 1] + a[N // 2]) / 2
        ma = (b[N // 2 - 1] + b[N // 2]) / 2
        print(int(ma - mi + 1))


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


import math


def main(N, lines):
    a = sorted(map(lambda line: line[0], lines))
    b = sorted(map(lambda line: line[1], lines))

    if N % 2 == 1:
        mi = a[N // 2]
        ma = b[N // 2]
    else:
        mi = math.floor((a[N // 2 - 1] + a[N // 2]) / 2)
        ma = math.ceil((b[N // 2 - 1] + b[N // 2]) / 2)
        print(a, b, mi, ma)
        print(int(ma - mi + 1))


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


def main(N, lines):
    a = sorted(map(lambda line: line[0], lines))
    b = sorted(map(lambda line: line[1], lines))

    if N % 2 == 1:
        mi = a[N // 2]
        ma = b[N // 2]
    else:
        mi = (a[N // 2 - 1] + a[N // 2]) / 2
        ma = (b[N // 2 - 1] + b[N // 2]) / 2
        print(a, b, mi, ma)
        print(int(ma - mi + 1 + 1))


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


def main(N, lines):
    a = sorted(map(lambda line: line[0], lines))
    b = sorted(map(lambda line: line[1], lines))

    if N % 2 == 1:
        mi = a[N // 2]
        ma = b[N // 2]
        print(int(ma - mi + 1))
    else:
        mi = (a[N // 2 - 1] + a[N // 2])
        ma = (b[N // 2 - 1] + b[N // 2])
        print(int(ma - mi + 1))


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


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

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)


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

N = len(alist)
alist.sort()
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
    ans = (bmedian-amedian)*2+1

else:
    median = (N + 1) / 2
    median = int(median) - 1
    amedian = alist[median]
    bmedian = blist[median]
    ans = bmedian-amedian+1
print(int(ans))


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):
# Count median
N=int(input())
m=[]
M=[]
for i in range(N):
    x,y=map(int,input().split())
    m.append(x)
    M.append(y)
m.sort()
M.sort(reverse=True)

if N%2!=0:
    mini=m[N//2]
    maxi=M[-N//2]
    print(maxi-mini+1)
else:
    mini=m[N//2-1]
    maxi=M[-N//2-1]
    if maxi>=mini:
        print((maxi-mini)*2+1)
    else:
        print(0)


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

else:
    x = a[N//2]
    y = b[N//2]
    print(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):
import sys
def input(): return sys.stdin.readline().rstrip()
def main():
    h,w,k=map(int,input().split())
    S=[input() for _ in range(h)]
    final_ans=10**10
    for row_lis in range(1<<(h-1)):
        lst=[0]*h
        q,ans=0,0
        for r in range(h-1):
            if (row_lis>>r)&1==0:
                lst[r+1]=q
            else:
                q+=1
                lst[r+1]=q
                ans+=1
        data=[0]*h
        for j in range(w):
            for i in range(h):
                data[lst[i]]+=int(S[i][j])
                if data[lst[i]]>k:
                    ans+=1
                    break
            else:
                continue
            data=[0]*h
            for i in range(h):
                data[lst[i]]+=int(S[i][j])
                if data[lst[i]]>k:
                    break
            else:
                continue
            break
        else:
            final_ans=min(final_ans,ans)
    print(final_ans)


if __name__=='__main__':
    main()

import sys
def input(): return sys.stdin.readline().rstrip()
def main():
    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==1:
        print(B[n//2]-A[n//2]+1)
    else:
        print(int(((B[n//2-1]+B[n//2])/2-(A[n//2-1]+A[n//2])/2)*2)+1)

if __name__=='__main__':
    main()

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):
import sys
import math
import itertools
import collections
import heapq
import numpy as np

rl = sys.stdin.readline
n = int(rl())
a = []
b = []
for _ in range(n):
    aa, bb = map(int, rl().split())
    a.append(aa)
    b.append(bb)

def heapsort(iterable):
    h = []
    for value in iterable:
        heapq.heappush(h, value)
    return [heapq.heappop(h) for i in range(len(h))]
a = heapsort(a)
b = heapsort(b)
if n&1:
    ans = b[n//2] - a[n//2] + 1
else:
    c = a[n//2] - a[n//2 - 1]
    d = b[n//2] - b[n//2 - 1]
    ans = (c/2 + d/2) / 0.5 + 1
print(ans)

import sys
import math
import itertools
import collections
import heapq
import numpy as np

rl = sys.stdin.readline
n = int(rl())
a = []
b = []
for _ in range(n):
    aa, bb = map(int, rl().split())
    a.append(aa)
    b.append(bb)

def heapsort(iterable):
    h = []
    for value in iterable:
        heapq.heappush(h, value)
    return [heapq.heappop(h) for i in range(len(h))]
a = heapsort(a)
b = heapsort(b)
if n&1:
    ans = b[n//2] - a[n//2] + 1
else:
    c = a[n//2] - a[n//2 - 1]
    d = b[n//2] - b[n//2 - 1]
    ans = (d/2 - c/2) / 0.5 + 1
print(ans)

import sys
import math
import itertools
import collections
import heapq
import numpy as np

rl = sys.stdin.readline
n = int(rl())
a = []
b = []
for _ in range(n):
    aa, bb = map(int, rl().split())
    a.append(aa)
    b.append(bb)

def heapsort(iterable):
    h = []
    for value in iterable:
        heapq.heappush(h, value)
    return [heapq.heappop(h) for i in range(len(h))]
a = heapsort(a)
b = heapsort(b)
if n&1:
    ans = b[n//2] - a[n//2] + 1
else:
    c = a[n//2] + a[n//2 - 1]
    d = b[n//2] + b[n//2 - 1]
    ans = (d/2 - c/2) / 0.5 + 1
print(int(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):
import math

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

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

ans = 0
if isinstance(mid_a, float):
    if not mid_a.is_integer():
        ans += 1
        mid_a = math.ceil(mid_a)
if isinstance(mid_b, float):
    if not mid_b.is_integer():
        ans += 1
        mid_b = math.floor(mid_b)
print(mid_b - mid_a + 1)


N = int(input())
A = [0] * N
B = [0] * N

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

A.sort()
B.sort()

if N % 2 == 1:
    mid_a = A[(N + 1) // 2 - 1]
    mid_b = B[(N + 1) // 2 - 1]
    print(mid_b - mid_a + 1)
else:
    mid_a = (A[N // 2 - 1] + A[N // 2]) / 2
    mid_b = (B[N // 2 - 1] + B[N // 2]) / 2
    print(int((mid_b - mid_a) * 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,*ab = map(int,open(0).read().split())
a = ab[::2]
b = ab[1::2]
a.sort()
b.sort(reverse=True)

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

print(ans)

n,*ab = map(int,open(0).read().split())
a = ab[::2]
b = ab[1::2]
a.sort()
b.sort(reverse=True)

if n%2 == 1:
    med_min = a[(n-1)//2]
    med_max = b[(n-1)//2]
    ans = med_max - med_min + 1
else:
    med_min = (a[n//2-1] + a[n//2] ) /2
    med_max = (b[n//2-1] + b[n//2] ) /2
    ans = (med_max - med_min)*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):
from statistics import median
N=int(input())
a,b=[],[]
#print(map(int,input().split())
for i in range(N):
  i,j=map(int,input().split())
  a.append(i)
  b.append(j)
amed,bmed=median(a),median(b)
  
if N%2==1:
  print(bmed-amed+1)
else:
  print(2*(bmed-amed)+1)

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

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):
  a,b = map(input().split())
  A.append(a)
  B.append(b)

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

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

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

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

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

med_A = median(A)
med_B = median(B)

if N%2==0:
    print((med_B-med_A)*2+1)
else:
    print(med_B-med_A+1)

from statistics import median

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

med_A = median(A)
med_B = median(B)

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

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 sys

# import re
import math
import collections

import bisect
import itertools
import fractions
# import functools
import copy
import heapq
import decimal
# import statistics
import queue

sys.setrecursionlimit(10000001)
INF = 10 ** 16
MOD = 10 ** 9 + 7

ni = lambda: int(sys.stdin.readline())
ns = lambda: map(int, sys.stdin.readline().split())
na = lambda: list(map(int, sys.stdin.readline().split()))


# ===CODE===


def main():
    n = ni()
    a = []
    b = []
    d = []
    for _ in range(n):
        ai, bi = ns()
        a.append(ai)
        b.append(bi)
        d.append((ai, bi))

    a.sort()
    b.sort()

    odd = n % 2 == 1
    even = n % 2 == 0
    min_choice = a[n // 2 - even]
    max_choice = b[n // 2]

    kouho = []
    for ai, bi in d:
        tmp = range(max(ai, min_choice), min(bi, max_choice))
        if len(tmp) > 0:
            kouho.append(tmp)

    dic_even = dict()
    dic_odd = dict()

    for k in kouho:
        for t in k:
            dic_even[t] = 0

    for i in range(len(kouho)):
        for t in kouho[i]:
            for j in range(i + 1, len(kouho)):
                for l in kouho[j]:
                    dic_odd[(t + l) / 2] = 0
    
    e = set(dic_even.keys())
    o = set(dic_odd.keys())
    
    ans = e+o
    print(len(ans))


if __name__ == '__main__':
    main()


import sys

# import re
import math
import collections

import bisect
import itertools
import fractions
# import functools
import copy
import heapq
import decimal
# import statistics
import queue
import numpy as np

sys.setrecursionlimit(10000001)
INF = 10 ** 16
MOD = 10 ** 9 + 7

ni = lambda: int(sys.stdin.readline())
ns = lambda: map(int, sys.stdin.readline().split())
na = lambda: list(map(int, sys.stdin.readline().split()))


# ===CODE===


def main():
    n = ni()
    a = []
    b = []
    for _ in range(n):
        ai, bi = ns()
        a.append(ai)
        b.append(bi)

    a.sort()
    b.sort()

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


if __name__ == '__main__':
    main()


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):
def main():
    n = int(input())
    nums = []
    for _ in range(n):
        a, b = map(int, input().split())
        if a == b:
            nums.append(a)
        else:
            nums.append(a)
            nums.append(b)
    sn = list(sorted(nums))
    kukans = []
    old = sn[0]
    for si in sn[1:]:
        kukans.append(si-old+1)
        old = si
    size = len(kukans)
    # if size%2:
    
    
        
    middle1 = kukans[size//2-1]
    middle2 = kukans[size//2]
    if n%2:
        print(middle1+middle2-1)
    else:
        print(middle1+middle2-1)
        

if __name__ == "__main__":
    main()

def main():
    n = int(input())
    al = []
    bl = []
    for _ in range(n):
        a, b = map(int, input().split())
        al.append(a)
        bl.append(b)
    als = list(sorted(al))
    bls = list(sorted(bl))
    if n%2:
        print(bls[n//2]-als[n//2]+1)
    else:
        print(bls[n//2-1]+bls[n//2]-als[n//2]-als[n//2-1]+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())
listA = [0] * N
listB = [0] * N
idx = 0
for i in range(N):
  listA[idx],listB[idx] = map(int, input().split())
  idx += 1

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

print(int(ans))

import statistics
import math

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

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

print(int(ans))

Verdicts: Runtime Error

Accepted