Harryxun/GPT-100-sft-dataset huggingface dataset:
Problem p02712 (python)

Fixed submission:
n = int(input())
ans = 0
for i in range(1,n+1):
  if i%3 != 0 and i%5 != 0:
    ans +=  i
print(ans)

Buggy submission (verdict: Runtime Error):
n = int(input())
ans = 0
for i in range(n+1):
  if i%3 = 0 or i%5 != 0:
    ans +=  i
print(ans)

Buggy submission (verdict: Runtime Error):
n = int(input())
ans = 0
for i in range(1,n+1):
  if i%3 = 0 or i%5 != 0:
    ans +=  i
print(ans)
Problem p02725 (python)

Fixed submission:
k,n=map(int,input().split())
l=list(map(int,input().split()))
v=[k-l[-1]+l[0]]
for i in range(n-1):
  v.append(l[i+1]-l[i])
v.sort()
print(k-v[-1])

Buggy submission (verdict: Runtime Error):
k,n=map(int,input.split())
l=list(map(int,input.split()))
v=[k-l[-1]+l[0]]
for i in range(n-1):
  v.append(l[i+1]-l[i])
v.sort()
print(k-v[-1])

Buggy submission (verdict: Runtime Error):
k,n=map(int,input())
l=list(map(int,input()))
v=[k-l[-1]+l[0]]
for i in range(n-1):
  v.append(l[i+1]-l[i])
v.sort()
print(k-v[-1])
Problem p02766 (python)

Fixed submission:
n,k=map(int,input().split())
i=0
while k**i<=n:
  i+=1
print(i)

Buggy submission (verdict: Runtime Error):
n,k=map(int,input().split())
i=0
while k**i<n:
  i+=1
print i
Problem p02785 (python)

Fixed submission:
N,K=map(int,input().split())
H=list(map(int,input().split()))
I=sorted(H)
s=0
if N<=K:
  print(0)
else:
  for i in range(N-K):
    s+=I[i]
  print(s)

Buggy submission (verdict: Runtime Error):
N,K=map(int,input().split())
H=list(map(int,input().split()))
s=0
if N<=K:
  print(0)
else:
  for i in range(H-N):
    s+=H[i]
  print(s)

Buggy submission (verdict: Runtime Error):
N,K=map(int,input().split())
H=list(map(int,input().split()))
print(N)
print(K)
s=0
if N<=K:
  print(0)
else:
  for i in range(H-N)
    s+=H[i]
  print(s)

Buggy submission (verdict: Runtime Error):
N,K=map(int,input().split())
H=list(map(int,input().split())
print(N)
print(K)
s=0
if N<=K:
  print(0)
else:
  for i in range(H-N)
    s+=H[i]
  print(s)
Problem p02790 (python)

Fixed submission:
a,b=map(int,input().split())
if a>=b:
  tmp=a
  a=b
  b=tmp
print(a*((10**b-1)//9))

Buggy submission (verdict: Runtime Error):
a,b=map(int,input().split())
if a>=b:
  tmp=a
  a=b
  b=tmp
return a*((10**b-1)/9)
Problem p02835 (python)

Fixed submission:
a,b,c=map(int,input().split())
if a+b+c>=22:
  print('bust')
else:
  print('win')

Buggy submission (verdict: Runtime Error):
a,b,c=map(int(input().split()))
if a+b+c>=22:
  print("bust")
else:
  print("win")
Problem p03073 (python)

Fixed submission:
l=str(input())
n=0
for i in range(len(l)):
  if i%2==0 and l[i]=='0':
    n+=1
  if i%2==1 and l[i]=='1':
    n+=1
print(min(n,len(l)-n))

Buggy submission (verdict: Runtime Error):
l=str(input())
n=0
for i in range(len(l)):
  if i%2==0,l[i]==0:
    n+=1
  if i%2==1,l[i]==1:
    n+=1
print(min(n,len(l)-n))
Problem p03834 (python)

Fixed submission:
s=list(str(input()))
s[5]=' '
s[13]=' '
print(''.join(s))

Buggy submission (verdict: Runtime Error):
s=list(str(input()))
s[5]=' '
s[13]=' '
print('',join(s))

Buggy submission (verdict: Runtime Error):
k,s=map(int,input().split())
c=0
for i in range(k+1):
  for j in range(k+1):
    for l in range(k+1):
      if i+j+l==s:
        c+=1
        break
print(c)
Problem p02990 (python)

Fixed submission:
import sys
input = sys.stdin.readline
from math import factorial

MAX_V = 10**9 + 7

from math import factorial


def nCr(n, r):
    if n < r:
        return 0
    return factorial(n) // (factorial(n - r) * factorial(r))

'''
def nCr(n, r):
    numerator = 1
    denominator = 1

    p = r if r < n-r else n-r

    for i in reversed(range(n-p+1, n+1)):
        numerator *= i

    for i in reversed(range(1, p+1)):
        denominator *= i

    return int(numerator / denominator)
'''

n, b_k = map(int, input().split())
r_k = n-b_k
spot = r_k+1

min_k = min(b_k, spot)

#for i in range(1, min_k+1):
for i in range(1, b_k+1):
    c = nCr(spot, i) * nCr(b_k-1, i-1)
    print(c % MAX_V)

Buggy submission (verdict: Runtime Error):
import sys
input = sys.stdin.readline
from math import factorial

MAX_V = 10**9 + 7

from math import factorial


'''
def nCr(n, r):
    if n < r:
        return 0
    return factorial(n) // (factorial(n - r) * factorial(r))

'''
def nCr(n, r):
    numerator = 1
    denominator = 1

    p = r if r < n-r else n-r

    for i in reversed(range(n-p+1, n+1)):
        numerator *= i

    for i in reversed(range(1, p+1)):
        denominator *= i

    return int(numerator / denominator)


n, b_k = map(int, input().split())
r_k = n-b_k
spot = r_k+1

min_k = min(b_k, spot)

#for i in range(1, min_k+1):
for i in range(1, b_k+1):
    c = nCr(spot, i) * nCr(b_k-1, i-1)
    print(c % MAX_V)

Buggy submission (verdict: Runtime Error):
import sys
input = sys.stdin.readline

MAX_V = 10**9 + 7


def nCr(n, r):
    numerator = 1
    denominator = 1

    p = r if r < n-r else n-r

    for i in reversed(range(n-p+1, n+1)):
        numerator *= i

    for i in reversed(range(1, p+1)):
        denominator *= i

    return int(numerator / denominator)


n, b_k = map(int, input().split())
r_k = n-b_k
spot = r_k+1

min_k = min(b_k, spot)

for i in range(1, min_k+1):
    c = nCr(spot, i) * nCr(b_k-1, i-1)
    print(c % MAX_V)
Problem p02712 (python)

Fixed submission:
n = int(input())

ans = 0
for i in range(n+1):
    if i % 3 != 0 and i % 5 != 0:
        ans += i
print(ans)

Buggy submission (verdict: Runtime Error):
print(sum([n for n in range(1, int(inpt())) if (n%3!=0) and (n%5!=0)]))

Buggy submission (verdict: Runtime Error):
sum([n for n in range(1, int(inpt())) if (n%3!=0) and (n%5!=0)])

Buggy submission (verdict: Runtime Error):
N = input()
print(sum([n for n in range(1, N) if (n%3!=0) and (n%5!=0)]))

Buggy submission (verdict: Runtime Error):
N = input()
print(sum([n for n in range(1, N) if (n%3!=0) and (n%5!=0)]))
Problem p02987 (python)

Fixed submission:
S = raw_input()
arr = []

for i in range(4):
     if S[i] not in arr:
         arr.append(S[i])

if len(arr) != 2:
    print "No"
else:
    a = 0
    b = 0
    for i in range(4):
        if S[i] == arr[0]:
            a = a + 1
        elif S[i] == arr[1]:
            b = b + 1
    if a == 2 and b == 2:
        print"Yes"
    else:
        print "No"

Buggy submission (verdict: Runtime Error):
s = raw_input
ans = 0
for i in range(3):
    if s[i] == s[i+1]:
        ans = 1
if ans == 1:
    print "Bad"
else:
    print "Good"
Problem p02847 (python)

Fixed submission:
S = ["SUN","MON","TUE","WED","THU","FRI","SAT"]
s = input()
print(7 - S.index(s))

Buggy submission (verdict: Runtime Error):
n = int(input())
s = [{0} for i in range(n)]

ans = [0] * n
a = 0
b = 0
sp = {i for i in range(n)}
for i in range(1,n):
    a,b = list(map(int,input().split()))
    ans[i] = min(sp-(s[a-1]|s[b-1]))

    s[a-1].add(ans[i])
    s[b-1].add(ans[i])

print(max(ans))
for i in range(1,n):
    print(ans[i])

Buggy submission (verdict: Runtime Error):
S = ["SUN","MON","TUE","WED","TUR","FRI","SAT"]
s = input()
print(7 - S.index(s))
Problem p03617 (python)

Fixed submission:
def main():
    rt = 0
    Q,H,S,D = map(int,input().split(" "))
    N = float(input())
    count_1 = N//2
    count_2 = (N-count_1*2)//1
    count_3 = (N-count_1*2-count_2)*100//50
    count_4 = (((N-count_1*2-count_2)*100)-50*count_3)//25
    if count_1:
        rt+=int(count_1)*min(2*S,D,4*H,8*Q)
    if count_2:
        rt+=int(count_2)*min(S,2*H,4*Q)
    if count_3:
        rt+=min(H,2*Q)*int(count_3)
    if count_4:
        rt+=Q*int(count_4)
    print(int(rt))

if __name__=="__main__":
    main()

Buggy submission (verdict: Runtime Error):
def main():
    rt = 0
    Q,H,S,D = map(int,input())
    N = float(input())
    count_1 = N//2
    count_2 = (N-count_1)//1
    count_3 = (N-count_1-count_2)*100//50
    count_4 = (((N-count_1-count_2)*100)-50*count_3)//25
    if count_1:
       rt+=count_1*min(2*S,D,4*H,8*Q)
    if count_2:
        rt+=count_2*min(S,2*H,4*Q)
    if count_3:
        rt+=min(2*H,Q)*count_3
    if count_4:
        rt+=Q*count_4
    print(rt)

if __name__=="__main__":
    main()
Problem p03186 (python)

Fixed submission:
import math, string, itertools, fractions, heapq, collections, re,  array, bisect, sys, random, time, copy, functools


sys.setrecursionlimit(10**7)
inf = 10 ** 20
eps = 1.0 / 10**10
mod = 10**9+7
dd = [(-1, 0), (0, 1), (1, 0), (0, -1)]
ddn = [(-1, 0), (-1, 1), (0, 1), (1, 1), (1, 0), (1, -1), (0, -1), (-1, -1)]


def LI(): return [int(x) for x in sys.stdin.readline().split()]
def LI_(): return [int(x)-1 for x in sys.stdin.readline().split()]
def LF(): return [float(x) for x in sys.stdin.readline().split()]
def LS(): return sys.stdin.readline().split()
def I(): return int(sys.stdin.readline())
def F(): return float(sys.stdin.readline())
def S(): return input()
def pf(s): return print(s, flush=True)

A,B,C = LI()


if B > C:
    print(B + C)
else:
    # 毒入りの方が多い
    result = B * 2
    C -= B
    if A >= C:
        result += C
        print(result)
    else:
        # 毒のほうが多い
        result += A + 1
        print(result)

Buggy submission (verdict: Runtime Error):
N = input()
a_list = list(map(int, input().split()))
b_list = list(map(int, input().split()))

if all([a >= b for a, b in zip(a_list, b_list)]):
    # すべての準備度が必要度を上回っている場合
    print(0)
else:
    # 準備度が足りていない試験がある場合
    if sum(a_list) < sum(b_list):
        # そもそも準備度の総量が足りない場合
        print(-1)
    else:
        # 準備度を移動すれば受かる場合
        # 一番数の大きいところから足りていないところに割り振る戦略
        # a_listをcopy
        c_list = [a for a in a_list]
        # 準備度の余裕をリストに格納
        diff_list = [c - b for c, b in zip(c_list, b_list)]
        # 一度減算し始めたら対象が0になるまで続ける
        selected_biggest_idx = diff_list.index(max(diff_list))
        while not all([c >= b for c, b in zip(c_list, b_list)]):
            if diff_list[selected_biggest_idx] == 0:
                selected_biggest_idx = diff_list.index(max(diff_list))
            min_idx = diff_list.index(min(diff_list))
            # 最大と最小で移し替えを行う
            if diff_list[selected_biggest_idx] < abs(diff_list[min_idx]):
                # 足りていない値のほうが大きい場合
                c_list[selected_biggest_idx] -= diff_list[selected_biggest_idx]
                c_list[min_idx] += diff_list[selected_biggest_idx]
            else:
                # 足りていない値のほうが小さい場合
                c_list[selected_biggest_idx] -= abs(diff_list[min_idx])
                c_list[min_idx] += abs(diff_list[min_idx])
            # diff_listを更新
            diff_list = [c - b for c, b in zip(c_list, b_list)]
        result_count = len([1 for a, c in zip(a_list, c_list) if a != c])
        print(result_count)
Problem p02954 (python)

Fixed submission:
s = list(input())
n = len(s)
children = [0]*n

def runlength(word):
    last_word = ''
    res = []
    for s in word:
        if last_word == s:
            res[-1] += 1
        else:
            res.append(s)
            res.append(1)
            last_word = s
    return res

cur_total = 0
runlengthed = runlength(s)
for i in range(0, len(runlengthed), 4):
    r_cnt = int(runlengthed[i+1])
    l_cnt = int(runlengthed[i+3])
    first_idx = cur_total+r_cnt-1
    second_idx = first_idx+1
    children[first_idx] = (r_cnt+1)//2+l_cnt//2
    children[second_idx] = r_cnt//2+(l_cnt+1)//2
    cur_total = cur_total + r_cnt + l_cnt

print(' '.join(list(map(str, children))))

Buggy submission (verdict: Runtime Error):
s = list(input())
n = len(s)
children = [0]*n

def runlength(word):
    last_word = ''
    res = []
    for s in word:
        if last_word == s:
            res[-1] += 1
        else:
            res.append(s)
            res.append(1)
            last_word = s
    return ''.join(list(map(str, res)))

cur_total = 0
runlengthed = runlength(s)
for i in range(0, len(runlengthed), 4):
    r_cnt = int(runlengthed[i+1])
    l_cnt = int(runlengthed[i+3])
    first_idx = cur_total+r_cnt-1
    second_idx = first_idx+1
    from_idx = cur_total
    to_idx = cur_total + l_cnt + r_cnt - 1
    children[first_idx] = (r_cnt+1)//2+l_cnt//2
    children[second_idx] = r_cnt//2+(l_cnt+1)//2
    cur_total = cur_total + r_cnt + l_cnt

print(' '.join(list(map(str, children))))
Problem p02984 (python)

Fixed submission:
import sys
from bisect import *
from collections import *
from copy import deepcopy
from heapq import *
from itertools import *
from math import *
from operator import *
import numpy as np

sys.setrecursionlimit(10**8)

input = sys.stdin.readline

def main():
    """ main """
    N = int(input())
    dams = list(map(int, input().split()))
    S = sum(dams)
    res = [0]*N
    res[0] = S - 2*sum(dams[1:N:2])
    for i in range(1,N):
        res[i] = 2*dams[i-1]-res[i-1]
    print(*res)

if __name__ == '__main__':
    main()

Buggy submission (verdict: Runtime Error):
import sys
from bisect import *
from collections import *
from copy import deepcopy
from heapq import *
from itertools import *
from math import *
from operator import *
import numpy as np

sys.setrecursionlimit(10**8)

input = sys.stdin.readline

def main():
    """ main """
    N = int(input())
    dams = list(map(int, input().split()))
    smallest_idx = 0
    for i in range(1,N):
        if dams[i] < dams[smallest_idx]:
            smallest_idx = i
    dams = dams[smallest_idx:] + dams[:smallest_idx]

    for i in range(0, dams[0]*2+1, 2):
        mts = [0]*N
        mts[0] = i
        for j in range(1,N):
            mts[j] = (dams[j-1]-mts[j-1]//2)*2
            if mts[j] < 0:
                break
        else:
            if mts[0]//2 + mts[N-1]//2 == dams[N-1]:
                mts = mts[N-smallest_idx:] + mts[:N-smallest_idx]
                print(*mts)
                return 0

if __name__ == '__main__':
    main()
Problem p02990 (python)

Fixed submission:
import sys
from bisect import *
from collections import *
from copy import deepcopy
from heapq import *
from itertools import *
from math import *
from operator import *
import numpy as np

sys.setrecursionlimit(10**8)

input = sys.stdin.readline

def main():
    """ main """
    N,K = map(int, input().split())
    MOD = 10**9+7

    for i in range(1,K+1):
        if N-K+1-i < 0:
            print(0)
        else:
            a = factorial(N-K+1)//(factorial(N-K+1-i)*factorial(i))
            b = factorial(K-1)//(factorial(K-i)*factorial(i-1))
            print(a*b % MOD)

if __name__ == '__main__':
    main()

Buggy submission (verdict: Runtime Error):
import sys
from bisect import *
from collections import *
from copy import deepcopy
from heapq import *
from itertools import *
from math import *
from operator import *
import numpy as np

sys.setrecursionlimit(10**8)

input = sys.stdin.readline

def main():
    """ main """
    N,K = map(int, input().split())
    MOD = 10**9+7

    for i in range(1,K+1):
        ans = 0
        a = factorial(N-K+1)//(factorial(N-K+1-i)*factorial(i))
        b = factorial(K-1)//(factorial(K-i)*factorial(i-1))
        print(a*b % MOD)

if __name__ == '__main__':
    main()
Problem p03053 (python)

Fixed submission:
def main():
    H, W = map(int,input().split())
    visited = [[False]*W for _ in range(H)]
    q = []
    for y in range(H):
        S = input()
        for x, s in enumerate(S):
            if s == "#":
                q.append((y, x))
                visited[y][x] = True

    ans = -1
    while q:
        ans += 1
        nq = []
        for y, x in q:
            if 0 < x and not visited[y][x-1]:
                visited[y][x-1] = True
                nq.append((y,x-1))
            if x < W-1 and not visited[y][x+1]:
                visited[y][x+1] = True
                nq.append((y,x+1))
            if 0 < y and not visited[y-1][x]:
                visited[y-1][x] = True
                nq.append((y-1, x))
            if y < H-1 and not visited[y+1][x]:
                visited[y+1][x] = True
                nq.append((y+1,x))
        if nq:
            q = nq
        else:
            break

    print(ans)

if __name__ == '__main__':
    main()

Buggy submission (verdict: Runtime Error):
import sys
from bisect import *
from collections import *
from copy import deepcopy
from heapq import *
from itertools import *
from math import *
from operator import *
from pprint import *
import numpy as np

sys.setrecursionlimit(10**8)

input = sys.stdin.readline

def main():
    """ main """
    H,W = map(int, input().split())
    visited = [[False]*W for _ in range(H)]
    q = []
    for y in range(H):
        for x, val in enumerate(list(input().rstrip())):
            if val == '#':
                q.append((y,x))
                visited[y][x] = True
    ans = -1
    while q:
        ans += 1
        new_q = []
        for y,x in q:
            for dy,dx in [(1,0),(-1,0),(0,1),(0,-1)]:
                ny = y+dy
                nx = x+dx
                if 0<=ny<H and 0<=nx<W and not visited[ny][nx]:
                    new_q.append((ny,nx))
                    visited[ny][nx] = True
        if new_q:
            q = new_q[:]
        else:
            break
    print(ans)

if __name__ == '__main__':
    main()
Problem p03776 (python)

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

v = [int(i) for i in input().split()]
v.sort(reverse=True)

max_average = sum(v[:A]) / A

C = [[0]*51 for i in range(51)]
for i in range(N+1):
    for j in range(i+1):
        if j == 0 or i == 0:
            C[i][j] = 1
        else:
            C[i][j] = C[i-1][j-1] + C[i-1][j]

ans = 0
cnt = 0
if v[0] == v[A-1]:
    for i in range(N):
        if v[i] == v[0]:
            cnt += 1
    for i in range(A, B+1):
        ans += C[cnt][i]
else:
    included = 0
    for i in range(N):
        if v[i] == v[A-1]:
            cnt += 1
            if i < A:
                included += 1
    ans += C[cnt][included]

print(max_average)
print(ans)

Buggy submission (verdict: Runtime Error):
from itertools import combinations
N,A,B = [int(i) for i in input().split()]

v = [int(i) for i in input().split()]
v.sort()

if v[-A] != v[-A-1]:
    print(sum(v[-A:]) / A)
    print(1)
elif v[-1] :
    # AAと同じ数のカウント
    # Aよりも大きい数のカウント
    cnt = 0
    bigger = 0
    for i in range(N):
        if v[A] < v[i]:
            bigger += 1
        if v[i] == v[A]:
            cnt += 1

    ans = 0
    mini = min(B, cnt+bigger)
    for i in range(A,mini):
        ans += len(list(combinations(range(cnt), i - bigger)))

    print(sum(v[-A:]) / A)
    print(ans)
Problem p03221 (python)

Fixed submission:
N, M = map(int, input().split())
PY = [tuple(map(int,input().split())) for i in range(M)]

PY_sort = sorted(PY)

tmp = dict()

before = 0
for py in PY_sort:
    if before != py[0]:
        before = py[0]
        count = 0
    count += 1
    tmp[py] = count

for py in PY:
    print("{:06}{:06}".format(py[0],tmp[py]))

Buggy submission (verdict: Runtime Error):
N, M = map(int, input().split())
PY = [list(map(int,input().split())) for i in range(N)]

PY_sort = sorted(PY)

tmp = dict()

before = 0
for py in PY_sort:
    if before != py[0]:
        count = 0
    count += 1
    tmp[py] = count

for py in PY:
    print("{:06}{:06}".format(tmp[py][0],tmp[py][1]))
Problem p03834 (python)

Fixed submission:
print(*input().split(","))

Buggy submission (verdict: Runtime Error):
K, S = map(int, input().split())

result = 0
for X in range(K+1):
    for Y in range(K+1):
        Z = S-X-Y
        if Z<0:
            continue
        elif K<Z:
            continue
        elif S == X+Y+Z:
            result += 1
print(result)
Problem p02897 (python)

Fixed submission:
N = int(input())
 
print(int((N+1)/2)/N)

Buggy submission (verdict: Runtime Error):
N = input()

print(int((N+1)/2)/N)
Problem p02912 (python)

Fixed submission:
import heapq
N,M = map(int,input().split())
A = list(map(int,input().split()))
 
for i in range(N):
  A[i] = -A[i]
  
heapq.heapify(A)
 
for _ in range(M): 
    hoge = -heapq.heappop(A)
    hoge = hoge // 2
    heapq.heappush(A, -hoge)
 
print(-sum(A))

Buggy submission (verdict: Runtime Error):
import heapq
N,M = map(int,input().split())
A = list(map(int,input().split()))
 
for i in range(N):
  A[i] = -A[i]
  
heapq.heapify(A)
 
for _ in range(M):
    print("mae")
    print(A)
    hoge = -heapq.heappop(A)
    hoge = hoge // 2
    print(A)
    heapq.heappush(A, -hoge)

    print(A)
    
print(-sum(A))
Problem p02916 (python)

Fixed submission:
N = int(input())
A = list(map(int,input().split()))
B = list(map(int,input().split()))
C = list(map(int,input().split()))

def buffet(N,x,y,z):
  a = sum(y)
  for i in range(N-1):
    if x[i+1] - x[i] == 1:
      a = a + z[x[i]-1]
  print(a)

if __name__ == '__main__':
  buffet(N,A,B,C)

Buggy submission (verdict: Runtime Error):
N = int(input())
A = list(map(int,input().split()))
B = list(map(int,input().split()))
C = list(map(int,input().split()))

def buffet(N,x,y,z):
  a = sum(y)
  for i in range(N-1):
    if x[i+1] - x[i] == 1:
      a = a + z[i+1]
  print(a)

if __name__ == '__main__':
  buffet(N,A,B,C)
Problem p02989 (python)

Fixed submission:
import sys

n = int(input())
d = list(map(int, input().split()))
dic = {}
val = 0

for i in range(n):
    if d[i] in dic.keys():
        dic[d[i]] += 1
    else:
        dic[d[i]] = 1

dic = sorted(dic.items())

if len(dic) == 1:
    print(0)
    sys.exit() 

for i in range(len(dic) - 1):
    val += dic[i][1]
    if val == n//2:
        ans = (dic[i][0], dic[i+1][0])
        print(ans[1] - ans[0])
        break
    elif val > n//2:
        print(0)
        break

Buggy submission (verdict: Runtime Error):
import sys

n = int(input())
d = list(map(int, input().split()))
dic = {}
val = 0

for i in range(n):
    if d[i] in dic.keys():
        dic[d[i]] += 1
    else:
        dic[d[i]] = 1

dic = sorted(dic.items())

for i in range(len(dic) - 1):
    val += dic[i][1]
    if val == n//2:
        ans = (dic[i][0] + 1, dic[i+1][0])
        break
    elif i == len(dic) - 2:
        print(0)
        sys.exit()

print(ans[1] - ans[0] + 1)

Buggy submission (verdict: Runtime Error):
n = int(input())
d = list(map(int, input().split()))
dic = {}
val = 0

for i in range(n):
    if d[i] in dic.keys():
        dic[d[i]] += 1
    else:
        dic[d[i]] = 1

dic = sorted(dic.items())

for i in range(len(dic) - 1):
    val += dic[i][1]
    if val == n//2:
        ans = (dic[i][0] + 1, dic[i+1][0])
        break
    elif i == len(dic) - 2:
        ans = (1, 0)
        break

print(ans[1] - ans[0] + 1)
Problem p02990 (python)

Fixed submission:
from math import factorial

n, k = map(int, input().split())
red = n - k
m = 10**9+7

def com_cal(p, q):
    return factorial(p) // (factorial(p - q) * factorial(q))

for i in range(1, k+1):
    if red+1 < i:
        print(0)
        continue
    com = com_cal(red + 1, i)
    div_num = com_cal(k - 1, i - 1)
    print((com * div_num)%m)

Buggy submission (verdict: Runtime Error):
from math import factorial

n, k = map(int, input().split())
red = n - k
m = 10**9+7

def com_cal(p, q):
    return factorial(p) // (factorial(p - q) * factorial(q))

for i in range(1, k+1):
    com = com_cal(red + 1, i)
    div_num = com_cal(k - 1, i - 1)
    print((com * div_num)%m)