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

Fixed submission:
[N,M,Q] = list(map(int,input().split()))

abcd = []
for i in range(Q):
    abcd.append(list(map(int,input().split())))

from itertools import permutations, combinations,combinations_with_replacement,product
AA=range(1,M+1)
CM = list(combinations_with_replacement(AA,N))
#print(CM)
wa = 0
A = [0]*N
dammy=[]
for i in range(len(CM)):
    A = CM[i]
    for j in range(Q):
        #print(abcd[2][j])
        if (A[abcd[j][1]-1] - A[abcd[j][0]-1]) == abcd[j][2]:
            wa+=abcd[j][3]
    dammy.append(wa)
    wa =0

print(max(dammy))

Buggy submission (verdict: Runtime Error):
[N,M,Q] = list(map(int,input().split()))

abcd = []
for i in range(Q):
    abcd.append(list(map(int,input().split())))

from itertools import permutations, combinations,combinations_with_replacement,product
AA=range(1,M+1)
CM = list(combinations(AA,N))


wa =0
A=[0]*N
dammy=[]
for i in range(len(CM)):
        A = sorted(CM[i])
        for j in range(Q):
            #print(abcd[2][j])
            if (A[abcd[j][1]-1] - A[abcd[j][0]-1]) == abcd[j][2]:
                wa+=abcd[j][3]
        dammy.append(wa)
        wa =0

print(max(dammy))

Buggy submission (verdict: Runtime Error):
[N,M,Q] = list(map(int,input().split()))

abcd = []
for i in range(Q):
    abcd.append(list(map(int,input().split())))

from itertools import permutations, combinations,combinations_with_replacement,product
AA=range(1,M+1)
CM = list(combinations(AA,N))


wa =0
A=[0]*N
dammy=[]
for i in range(len(CM)):
        A = sorted(CM[i])
        for j in range(Q):
            #print(abcd[2][j])
            if (A[abcd[j][1]-1] - A[abcd[j][0]-1]) == abcd[j][2]:
                wa+=abcd[j][3]
        dammy.append(wa)
        wa =0

print(max(dammy))
Problem p02862 (python)

Fixed submission:

[X,Y] = list(map(int,input().split()))

n = (-1*X+2*Y)//3
m = (2*X-Y)//3

if (X+Y)%3 !=0:
    print(0)

elif n<0 or m<0:
    print(0)

else:
    MAXN = (10**6)+10
    MOD = 10**9 + 7
    f = [1]
    for i in range(MAXN):
        f.append(f[-1] * (i+1) % MOD)
    def nCr(n, r, mod=MOD):
        return f[n] * pow(f[r], mod-2, mod) * pow(f[n-r], mod-2, mod) % mod


    print(nCr(n+m,n,10**9 + 7))

Buggy submission (verdict: Runtime Error):
[X,Y] = list(map(int,input().split()))

n = (-4*X+5*Y)//3)
m = (2*X-Y)//3)

if (X+Y)%3 !=0:
    print(0)

elif n<0 or m<0:
    print(0)

#コンビネーションを何回も計算する問題で使える関数
MAXN = (10**6)+10
MOD = 10**9 + 7
f = [1]
for i in range(MAXN):
    f.append(f[-1] * (i+1) % MOD)
def nCr(n, r, mod=MOD):
    return f[n] * pow(f[r], mod-2, mod) * pow(f[n-r], mod-2, mod) % mod


print(nCr(n+m,n,10**9 + 7))
Problem p02891 (python)

Fixed submission:
S =  list(input())
K = int(input())
#print(S)
N=len(S)

#if K==1:
kosuu=[]
cnt=1
for i in range(N-1):
    if S[i]==S[i+1]:
        cnt+=1
        if i==N-2:
            kosuu.append(cnt)
    elif S[i]!=S[i+1]:
        kosuu.append(cnt)
        cnt=1
#print('kosuu', kosuu)
dammy=0
for i in range(len(kosuu)):
    dammy+=kosuu[i]//2

#else:
if K==1:
    out=dammy

elif S[0]!=S[-1]:
    out = dammy * K

elif len(S)==1:
    out=K//2

elif len(kosuu)==1:
    out=(kosuu[0]*K)//2

else:
    #kotei=kosuu[1:-1]  #少ないとき
    kotei = dammy - kosuu[0]//2 - kosuu[-1]//2
    aida = (kosuu[0] + kosuu[-1]) // 2
    #print('aida',aida)
    out = kosuu[0]//2 + (kotei*K) + aida*(K-1) + kosuu[-1]//2

print(out)

Buggy submission (verdict: Runtime Error):
S =  list(input())
K = int(input())
#print(S)
N=len(S)

#if K==1:
kosuu=[]
cnt=1
for i in range(N-1):
    if S[i]==S[i+1]:
        cnt+=1
        if i==N-2:
            kosuu.append(cnt)
    elif S[i]!=S[i+1]:
        kosuu.append(cnt)
        cnt=1
#print('kosuu', kosuu)
dammy=0
for i in range(len(kosuu)):
    dammy+=kosuu[i]//2

#else:
if K==1:
    out=dammy

elif S[0]!=S[-1]:
    out = dammy * K

else:
    #kotei=kosuu[1:-1]  #少ないとき
    kotei = dammy - kosuu[0]//2 - kosuu[-1]//2
    aida = (kosuu[0] + kosuu[-1]) // 2
    #print('aida',aida)
    out = kosuu[0]//2 + (kotei*K) + aida*(K-1) + kosuu[-1]//2

print(out)
Problem p03013 (python)

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

aa=[0]*(N+1)
for j in range(M):
    aa[a[j]] = 1

dp = [0]*(N+1)
dp[0]=1
if 1 not in a:
    dp[1]=1
else:
    dp[1]=0

for i in range(2,N+1):
    if aa[i]==0:
        dp[i]=dp[i-1] + dp[i-2]
    else:
        dp[i]=0

print(dp[-1] % 1000000007)

Buggy submission (verdict: Runtime Error):

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

#print(a)
dp = [0] * (N+1)
dp[0]=1
if a[0]!=1:
    dp[1]=1
#dp[1]=1
j=0
for i in range(1,N+1):
    if M!=0:
        if i==a[j]:
            dp[i] = 0
            j+=1
            if j==M:
                j=0

        else:
            dp[i] = dp[i-1] + dp[i-2]
    else:
        dp[i] = dp[i-1] + dp[i-2]

print(dp[-1] % 1000000007)

Buggy submission (verdict: Runtime Error):

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

#print(a)
dp = [0] * (N+1)
dp[0]=1
if a[0]!=1:
    dp[1]=1
#dp[1]=1
j=0
for i in range(1,N+1):
    if M!=0:
        if i==a[j]:
            dp[i] = 0
            j+=1
            if j==len(a):
                j=0

        else:
            dp[i] = dp[i-1] + dp[i-2]
    else:
        dp[i] = dp[i-1] + dp[i-2]

print(dp[-1] % 1000000007)

Buggy submission (verdict: Runtime Error):

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

#print(a)
dp = [0] * (N+1)
dp[0]=1
if a[0]!=1:
    dp[1]=1
#dp[1]=1
j=0
for i in range(1,N+1):
    if i==a[j]:
        dp[i] = 0
        j+=1
        if j==len(a):
            j=0

    else:
        dp[i] = dp[i-1] + dp[i-2]

print(dp[-1] % 1000000007)
Problem p03137 (python)

Fixed submission:
[N,M] = list(map(int,input().split()))
X = list(map(int,input().split()))
X = sorted(X)
#print('X',X)

if N>=M:
    out=0
else:
    aida=[0]*(M-1)
    for i in range(M-1):
        aida[i] = X[i+1] - X[i]
    #print(aida)
    aida = sorted(aida, reverse=True)

    out = X[-1] - X[0]
    for j in range(N-1):
        out-=aida[j]

print(out)

Buggy submission (verdict: Runtime Error):
[N,M] = list(map(int,input().split()))
X = list(map(int,input().split()))
X = sorted(X)
#print('X',X)

if N>=M:
    out=0
else:
    aida=[0]*(M-1)
    for i in range(M-1):
        aida[i] = X[i+1] - X[i]
    #print(aida)
    aida = sorted(aida, reverse=True)

    out = X[-1] - X[0]
    for j in range(N-1):
        out-=aida[j]

print(out)[N,M] = list(map(int,input().split()))
X = list(map(int,input().split()))
X = sorted(X)
#print('X',X)

if N>=M:
    out=0
else:
    aida=[0]*(M-1)
    for i in range(M-1):
        aida[i] = X[i+1] - X[i]
    #print(aida)
    aida = sorted(aida, reverse=True)

    out = X[-1] - X[0]
    for j in range(N-1):
        out-=aida[j]

print(out)
Problem p02688 (python)

Fixed submission:
def main():
    n, k = map(int, input().split())
    d = [None for _ in range(k)]
    a = [None for _ in range(k)]
    for i in range(k):
        d[i] = int(input())
        a[i] = list(map(int, input().split()))

    tricked = [True for _ in range(n)]
    for i in range(k):
        for j in range(d[i]):
            tricked[a[i][j]-1] = False

    ans = 0
    for i in range(n):
        if tricked[i]:
            ans += 1

    print(ans)

if __name__ == '__main__':
    main()

Buggy submission (verdict: Runtime Error):
def main():
    n, k = map(int, input().split())
    d = [None for _ in range(k)]
    a = [None for _ in range(k)]
    for i in range(k):
        d[i] = int(input())
        a[i] = list(map(int, input().split()))

    tricked = [True for _ in range(n)]
    for i in range(k):
        for j in range(d[i]):
            tricked[a[i][j]-1] = False

    ans = 0
    for i in range(k):
        if tricked[i]:
            ans += 1

    print(ans)

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

Fixed submission:
from itertools import accumulate

m = 1000000007

N, *A = map(int, open(0).read().split())

result = 0
b = list(accumulate(A))
for i in range(N):
    result += A[i] * (b[N - 1] - b[i])
    result %= m
print(result)

Buggy submission (verdict: Runtime Error):
l = input()
a = l.split(' ')

tmp = 0
tmp2 = 0

for i in range(n):
    tmp += int(a[i])

for i in range(n):
    tmp2 += int(a[i])*int(a[i])

print((tmp*tmp-tmp2)//2%1000000007)
Problem p02580 (python)

Fixed submission:
H, W, M = map(int, input().split())

hc = [0] * H
wc = [0] * W
d = {}
for _ in range(M):
    h, w = map(lambda x: int(x) - 1,input().split())
    hc[h] += 1
    wc[w] += 1
    d.setdefault(h, {})
    d[h][w] = 1

result = 0
hm = max(hc)
wm = max(wc)
hi = [i for i in range(H) if hc[i] == hm]
wi = [i for i in range(W) if wc[i] == wm]

for h in hi:
    for w in wi:
        if h in d and w in d[h]:
            result = max(result, hm + wm - 1)
        else:
            result = max(result, hm + wm)
            break
print(result)

Buggy submission (verdict: Runtime Error):
H, W, M = map(int, input().split())

hc = [0] * H
wc = [0] * W
hwc = [[0] * W for _ in range(H)]
for _ in range(M):
    h, w = map(lambda x: int(x) - 1,input().split())
    hc[h] += 1
    wc[w] += 1
    hwc[h][w] += 1

result = 0
for h in range(H):
    for w in range(W):
        result = max(result, hc[h] + wc[w] - hwc[h][w])
print(result)
Problem p02597 (python)

Fixed submission:
N = int(input())
c = input()

d = list(c)

i = 0
j = N - 1
result = 0
while True:
    while i < N and d[i] != 'W':
        i += 1
    while j > 0 and d[j] != 'R':
        j -= 1
    if i == N or j == -1 or i >= j:
        break
    d[i] = 'R'
    d[j] = 'W'
    result += 1
print(result)

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

result = -float('inf')
for i in range(N):
    p = P[i] - 1
    c = C[p]
    k = K - 1
    t = c
    while p != i and k != 0:
        p = P[p] - 1
        c += C[p]
        t = max(t, c)
        k -= 1
    if k == 0 or c <= 0:
        result = max(result, t)
        continue
    l = K - k
    c = c * (K // l - 1)
    k = K - (K // l - 1) * l
    t = c
    while k != 0:
        p = P[p] - 1
        c += C[p]
        t = max(t, c)
        k -= 1
    result = max(result, t)
print(result)

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

d = list(c)

i = 0
j = N - 1
result = 0
while i != j:
    if d[i] == 'W':
        while d[j] != 'R' and i != j:
            j -= 1
        d[i] = 'R'
        d[j] = 'W'
        result += 1
    i += 1
print(result)
Problem p02598 (python)

Fixed submission:
from math import ceil

N, K, *A = map(int, open(0).read().split())

def is_ok(n):
    t = 0
    for a in A:
        if a <= n:
            continue
        t += ceil(a / n) - 1
    return t <= K

ok = 1000000000
ng = 0.0000000001
while abs(ng - ok) > 1:
    m = (ok + ng) // 2
    if is_ok(m):
        ok = m
    else:
        ng = m

print(ceil(ok))

Buggy submission (verdict: Runtime Error):
from math import ceil
from heapq import heapify, heappop, heappush

N, K, *A = map(int, open(0).read().split())

t = sum(A) / K
a = [None] * len(A)
for i in A:
    k = max(ceil(i / t), 1)
    a.append((-i / k, i, k))

heapify(a)
for _ in range(K):
    i, j, k = heappop(a)
    k += 1
    i = -(j / k)
    heappush(a, (i, j, k))
print(ceil(heappop(a)[0] * -1))

Buggy submission (verdict: Runtime Error):
from math import ceil
from heapq import heapify, heappop, heappush

N, K, *A = map(int, open(0).read().split())

a = [(-i, i, 1) for i in A]
heapify(a)
while K != 0:
    i, j, k = heappop(a)
    #print(i, j, k)
    t = -a[0][0]
    nk = ceil(j / t)
    t = max(min(nk - k, K), 1)
    K -= t
    k += t
    i = -(j / k)
    heappush(a, (i, j, k))
    #print(i, j, k)
print(ceil(heappop(a)[0] * -1))

Buggy submission (verdict: Runtime Error):
from math import ceil
from heapq import heapify, heappop, heappush

N, K, *A = map(int, open(0).read().split())

a = [(-i, i, 1) for i in A]
heapify(a)
while K != 0:
    i, j, k = heappop(a)
    #print(i, j, k)
    t = -a[0][0]
    nk = ceil(j / t)
    t = min(nk - k, K)
    K -= t
    k += t
    i = -(j / k)
    heappush(a, (i, j, k))
    #print(i, j, k)
print(ceil(heappop(a)[0] * -1))

Buggy submission (verdict: Runtime Error):
from math import ceil
from heapq import heapify, heappop, heappush

N, K, *A = map(int, open(0).read().split())

a = [(-i, i, 1) for i in A]
heapify(a)
while K != 0:
    i, j, k = heappop(a)
    #print(i, j, k)
    t = -a[0][0]
    nk = ceil(j / t)
    t = min(nk - k, K)
    K -= t
    k = nk
    i = -(j / k)
    heappush(a, (i, j, k))
    #print(i, j, k)
print(ceil(heappop(a)[0] * -1))
Problem p02623 (python)

Fixed submission:
from itertools import accumulate
from bisect import bisect_left

N, M, K = map(int, input().split())
A = list(map(int, input().split()))
B = list(map(int, input().split()))

a = list(accumulate(A))
b = list(accumulate(B))

result = 0
j = bisect_left(b, K)
if j == M:
  result = M
elif b[j] == K:
    result = j + 1
else:
    result = j
for i in range(N):
    t = K - a[i]
    if t < 0:
        break
    j = bisect_left(b, t)
    if j == M:
        result = max(result, i + 1 + M)
    elif b[j] == t:
        result = max(result, i + 1 + j + 1)
    else:
        result = max(result, i + 1 + j)
print(result)

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

b_sum = 0
for i in range(M):
    b_sum += B[i]
    if b_sum > K:
        b_sum -= B[i]
        j = i - 1
        break
result = j + 1

a_sum = 0
for i in range(N):
    a_sum += A[i]
    if a_sum > K:
        break
    while a_sum + b_sum > K:
        b_sum -= B[j]
        j -= 1
    result = max(result, (i + 1) + (j + 1))
print(result)

Buggy submission (verdict: Runtime Error):
from itertools import accumulate
from bisect import bisect_left

N, M, K = map(int, input().split())
A = list(map(int, input().split()))
B = list(map(int, input().split()))

a = [0] + list(accumulate(A))
b = [0] + list(accumulate(B))

result = 0
for i in range(N):
    t = K - a[i]
    if t < 0:
        break
    j = bisect_left(b, t)
    if b[j] == t:
        result = max(result, i + j + 1)
    else:
        result = max(result, i + j)
print(result)
Problem p02624 (python)

Fixed submission:
# エラトステネスの篩
N = int(input())

sieve = [0] * (N + 1)
sieve[0] = -1
sieve[1] = -1
for i in range(2, N + 1):
    if sieve[i] != 0:
        continue
    sieve[i] = i
    for j in range(i * i, N + 1, i):
        if sieve[j] == 0:
            sieve[j] = i


def f(K):
    t = []
    a = K
    while a != 1:
        if len(t) != 0 and t[-1][0] == sieve[a]:
            t[-1][1] += 1
        else:
            t.append([sieve[a], 1])
        a //= sieve[a]
    result = 1
    for _, n in t:
        result *= (n + 1)
    return result


result = 0
for K in range(1, N + 1):
    result += K * f(K)
print(result)

Buggy submission (verdict: Runtime Error):
# エラトステネスの篩
def make_prime_table(N):
    sieve = list(range(N + 1))
    sieve[0] = -1
    sieve[1] = -1
    sieve[2] = 2
    for i in range(3, int(N ** 0.5) + 1, 2):
        if sieve[i] != 0:
            continue
        sieve[i] = i
        for j in range(i * i, N + 1, i):
            if sieve[j] == 0:
                sieve[j] = i
    return sieve


def f(X):
    t = []
    a = X
    while a != 1:
        if len(t) != 0 and t[-1][0] == prime_table[a]:
            t[-1][1] += 1
        else:
            t.append([prime_table[a], 1])
        a //= prime_table[a]
    result = 1
    for _, n in t:
        result *= n + 1
    return result


N = int(input())

prime_table = make_prime_table(N)
result = 0
for K in range(1, N + 1):
    result += K * f(K)
print(result)
Problem p02707 (python)

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

d = {}

for i in range(N - 1):
    if A[i] in d:
        d[A[i]].append(i + 2)
    else:
        d[A[i]] = [i + 2]

for i in range(1, N + 1):
    if i in d:
        print(len(d[i]))
    else:
        print(0)

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

result = [0] * N
for a in A:
    result[a - 1] += 1
print('\n'.join(result))
Problem p02726 (python)

Fixed submission:
N, X, Y = map(int, input().split())

t = [0] * (N - 1)
for i in range(1, N):
    for j in range(i + 1, N + 1):
        t[min(j - i, abs(X - i) + 1 + abs(Y - j)) - 1] += 1
print('\n'.join(map(str, t)))

Buggy submission (verdict: Runtime Error):
N, X, Y = map(int, input().split())

t = [0] * (N - 1)
for i in range(1, N):
    for j in range(i + 1, N + 1):
        t[min(j - i, abs(X - i) + 1 + abs(Y - j)) - 1] += 1
#print('\n'.join(map(str, t)))
print(*result, sep='\n')
Problem p02773 (python)

Fixed submission:
N = int(input())

d1 = {}
for _ in range(N):
    S = input()
    if S in d1:
        d1[S] += 1
    else:
        d1[S] = 1

d2 = {}
for key in d1:
    value = d1[key]
    if value in d2:
        d2[value].append(key)
    else:
        d2[value] = [key]

key = sorted(d2.keys(), reverse=True)[0]
for s in sorted(d2[key]):
    print(s)

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

d = {}
for _ in range(N):
    S = input()
    if S in d:
        d[S] += 1
    else:
        d[S] = 1

m = max(d.values)
l = []
for k in d:
    v = d[k]
    if v != m:
        continue
    l.append(v)

for s in sorted(l):
    print(s)
Problem p02781 (python)

Fixed submission:
N = input()
K = int(input())

a = [0] * (K + 1)
b = [0] * (K + 1)

t = int(N[0])

a = 1
b[0] = 1
b[1] = t - 1

for c in N[1:]:
    t = int(c)
    for i in range(K - 1, -1, -1):
        b[i + 1] += b[i] * 9
    if t != 0:
        if t != 1 and a + 1 <= K:
            b[a + 1] += t - 1
        if a <= K:
            b[a] += 1
        a += 1

if a == K:
    print(b[K] + 1)
else:
    print(b[K])

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

a = 1
b = [0] * (K + 1)
b[0] = 1
b[1] = int(N[0]) - 1

for c in N[1:]:
    t = int(c)
    for i in range(K - 1, -1, -1):
        b[i + 1] += b[i] * 9
    if t != 0:
        b[a + 1] += t - 1
        b[a] += 1
        a += 1

if a == K:
    print(b[K] + 1)
else:
    print(b[K])
Problem p02793 (python)

Fixed submission:
def mpow(x, n):
    result = 1
    while n != 0:
        if n & 1 == 1:
            result *= x
            result %= 1000000007
        x *= x
        x %= 1000000007
        n >>= 1
    return result


max_A = 1000000

N = int(input())
A = list(map(int, input().split()))

sieve = [0] * (max_A + 1)
sieve[0] = -1
sieve[1] = -1
for i in range(2, max_A + 1):
    if sieve[i] != 0:
        continue
    sieve[i] = i
    for j in range(i * i, max_A + 1, i):
        if sieve[j] == 0:
            sieve[j] = i

lcm_factors = {}
for i in range(N):
    t = []
    a = A[i]
    while a != 1:
        if len(t) == 0:
            t.append([sieve[a], 1])
        elif t[-1][0] == sieve[a]:
            t[-1][1] += 1
        else:
            t.append([sieve[a], 1])
        a //= sieve[a]
    for k, v in t:
        if k not in lcm_factors or lcm_factors[k] < v:
            lcm_factors[k] = v

lcm = 1
for k in lcm_factors:
    for i in range(lcm_factors[k]):
        lcm *= k
        lcm %= 1000000007

result = 0
for i in range(N):
    result += lcm * mpow(A[i], 1000000007-2)
    result %= 1000000007
print(result)

Buggy submission (verdict: Runtime Error):
# エラトステネスの篩, フェルマーの小定理
from math import sqrt


def mpow(x, n):
    result = 1
    while n != 0:
        if n & 1 == 1:
            result *= x
            result %= 1000000007
        x *= x
        x %= 1000000007
        n >>= 1
    return result


max_A = 1000000

N = int(input())
A = list(map(int, input().split()))

sieve = [0] * (max_A + 1)
sieve[0] = -1
sieve[1] = -1
for i in range(2, int(sqrt(max_A)) + 1):
    if sieve[i] != 0:
        continue
    sieve[i] = i
    for j in range(i * i, max_A + 1, i):
        if sieve[j] == 0:
            sieve[j] = i

lcm_factors = {}
for i in range(N):
    t = []
    a = A[i]
    while a != 1:
        if len(t) != 0 and t[-1][0] == sieve[a]:
            t[-1][1] += 1
        else:
            t.append([sieve[a], 1])
        a //= sieve[a]
    for k, v in t:
        if k not in lcm_factors or lcm_factors[k] < v:
            lcm_factors[k] = v

lcm = 1
for k in lcm_factors:
    for i in range(lcm_factors[k]):
        lcm *= k
        lcm %= 1000000007

result = 0
for i in range(N):
    result += lcm * mpow(A[i], 1000000007-2)
    result %= 1000000007
print(result)
Problem p02990 (python)

Fixed submission:
def main():
    N, K = map(int, input().split())

    c = [[0] * 4000 for _ in range(4000)]
    c[0][0] = 1
    for i in range(1, 4000):
        ci = c[i]
        ci1 = c[i - 1]
        ci[0] = 1
        for j in range(1, i + 1):
            ci[j] = (ci1[j - 1] + ci1[j]) % 1000000007

    def f(n, k):
        return c[n+k-1][k-1]

    for i in range(1, K + 1):
        print((f(K-i, i) * f(N-K-(i-1), i+1)) % 1000000007)


main()

Buggy submission (verdict: Runtime Error):
# パスカルの三角形
N, K = map(int, input().split())

n = max(K - 1, N - K + 1)
c = [[0] * (n + 1) for _ in range(n + 1)]
c[0][0] = 1
for i in range(1, n + 1):
    ci = c[i]
    ci1 = c[i - 1]
    ci[0] = 1
    for j in range(1, i + 1):
        ci[j] = (ci1[j - 1] + ci1[j]) % 1000000007

result = []
for i in range(1, K + 1):
    result.append(c[K - 1][i - 1] * c[N - K + 1][i] % 1000000007)
print('\n'.join(str(i) for i in result))
Problem p03038 (python)

Fixed submission:
from functools import cmp_to_key
n, m = map(int, input().split())
a = [int(e) for e in input().split()]
bc = [[int(e) for e in input().split()] for _ in range(m)]
bc.sort(key = cmp_to_key(lambda x, y: y[1] - x[1]))
t = 0
for v in bc:
  b, c = v
  t += b
  a.extend([c] * b)
  if t > n:
    break
a.sort(reverse = True)
print(sum(a[:n]))

Buggy submission (verdict: Runtime Error):
from functools import cmp_to_key
n, m = map(int, input().split())
a = [int(e) for e in input().split()]
bc = [[int(e) for e in input().split()] for _ in range(m)]
bc.sort(key = cmp_to_key(lambda x, y: x[1] - y[1]))
t = 0
for bc in range(m):
  b, c = bc
  t += b
  a.extend([c] * b)
  if t > n:
    break
a.sort(reverse = True)
print(sum(a[:n]))

Buggy submission (verdict: Runtime Error):
from functools import cmp_to_key
from heapq import heappush, heappop, heapify, heapreplace
n, m = map(int, input().split())
a = [int(e) for e in input().split()]
heapify(a)
bc = [[int(e) for e in input().split()] for _ in range(m)]
bc.sort(key = cmp_to_key(lambda x, y: x[1] - y[1]))
for i in range(m):
  b, c = bc[i]
  for j in range(b):
    if a[0] >= c:
      break
    else:
      heapreplace(a, c)
print(result)

Buggy submission (verdict: Runtime Error):
from functools import cmp_to_key
from heapq import heappush, heappop, heapify
n, m = map(int, input().split())
a = [int(e) for e in input().split()]
heapify(a)
bc = [[int(e) for e in input().split()] for _ in range(m)]
bc.sort(key = cmp_to_key(lambda x, y: x[1] - y[1]))
for i in range(m):
  b, c = bc[i]
  for j in range(b):
    t = heappop(a)
    if t < c:
      heappush(a, c)
    else:
      heappop(a, t)
      break
print(sum(a))
Problem p03107 (python)

Fixed submission:
s = input()
t = len([c for c in s if c == '0'])
print(2 * min(t, len(s) - t))

Buggy submission (verdict: Runtime Error):
s = input()
result = 0
while True:
  t = len(s)
  for i in range(len(s) - 1):
    if s[i] != s[i + 1]:
      result += 2
      s = s[:i] + s[i+2:]
      print(s)
      break
  if len(s) == t:
    break
print(result)