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

Fixed submission:
n, m, k=map(int, input().split())
A=list(map(int, input().split()))
B=list(map(int, input().split()))

a=[0]
b=[0]

for i in range(n):
    a.append(a[i]+A[i])

for i in range(m):
    b.append(b[i]+B[i])

ans, j=0, m
for i in range(0, n+1):
    if a[i]>k:
        break
    else:
        while a[i]+b[j]>k:
            j-=1
        
    ans=max(ans, i+j)


print(ans)

Buggy submission (verdict: Runtime Error):
n, m, k=map(int, input().split())
a=list(map(int, input().split()))
b=list(map(int, input().split()))

k=tmp

ans=0

cnt1=0
cnt2=0
cost1=0
cost2=0

for i in range(n):
    cost1+=a[i]
    if cost1<=k:
        cnt1+=1
    else:
        cost1-=a[i]
        break

for j in range(m):
    cost2+=b[j]
    if cost2<=k:
        cnt2+=1
    else:
        cost2-=b[j]
        break

if cnt1>cnt2:
    ans+=cnt1
    k-=cost1
    for i in range(m):
        k-=b[i]
        if k>=0:
            ans+=1
        else:
            break
    
    print(ans)

elif cnt2>cnt1:
    ans+=cnt2
    k-=cost2
    for i in range(n):
        k-=a[i]
        if k>=0:
            ans+=1
        else:
            break
    
    print(ans)

else:
    alpha+=cnt1
    tmp-=cost1
    for i in range(m):
        tmp-=b[i]
        if k>=0:
            alpha+=1
        else:
            break
    
    bata+=cnt2
    k-=cost2
    for i in range(n):
        k-=a[i]
        if k>=0:
            bata+=1
        else:
            break

    ans=max(alpha, bata)

    print(ans)

Buggy submission (verdict: Runtime Error):
n, m, k=map(int, input().split())
a=list(map(int, input().split()))+[10**10]*(10**10)
b=list(map(int, input().split()))+[10**10]*(10**10)

loop=max(n, m)
i=0
j=0
T=0
ans=0

for t in range(2*loop):
    if a[i]>=b[j]:
        T+=b[j]
        if T<=k:
            ans+=1
            j+=1
        else:
            print(ans)
            exit()
    elif b[j]>a[i]:
        T+=a[i]
        if T<=k:
            ans+=1
            i+=1
        else:
            print(ans)
            exit()
    
    elif i==n-1:
        T+=b[j]
        if T<=k:
            ans+=1
            j+=1
        else:
            print(ans)
            exit()
    
    elif j==m-1:
        T+=a[i]
        if T<=k:
            ans+=1
            i+=1
        else:
            print(ans)
            exit()
Problem p02771 (python)

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

if A==B and B!=C:
    print("Yes")
elif B==C and C!=A:
    print("Yes")
elif C==A and A!=B:
    print("Yes")
else:
    print("No")

Buggy submission (verdict: Runtime Error):
import collections
N=int(input())
l=[input() for i in range(N)]
c=collections.Counter(l)
c=c.most_common()
l2=[]
 
M=c.[0][1]
for i in range(N):
    if c.[i][1]==M:
        l2.append(c.[i][0])
    else:
        break
l2.sort()
for j in range(len(l2)):
    print(l2[j])

Buggy submission (verdict: Runtime Error):
import collections
N=int(input())
l=[input() for i in range(N)]
c=collections.Counter(l)
c=c.most_common()
l2=[]

M=c.[0][1]
for i in range(N):
    if c.[i][1]==M:
        l2.append(c.[i][0])
    else:
        break
l2.sort()
for j in range(len(l2)):
    print(l2[j])
Problem p02773 (python)

Fixed submission:
N=int(input())
dic={}
for i in range(N):
    s=input()
    if s in dic:
        dic[s]+=1
    else:
        dic[s]=0
m=max(dic[i] for i in dic)
ans=[]
for j in dic:
    if dic[j]==m:
        ans.append(j)
ans.sort()
for k in range(len(ans)):
    print(ans[k])

Buggy submission (verdict: Runtime Error):
import collections
N=int(input())
l=[input() for i in range(N)]
c=collections.Counter(l)
c=c.most_common()
l2=[]
 
M=c.[0][1]
for i in range(N):
    if c.[i][1]==M:
        l2.append(c.[i][0])
    else:
        break
l2.sort()
for j in range(len(l2)):
    print(l2[j])

Buggy submission (verdict: Runtime Error):
import collections
N=int(input())
l=[input() for i in range(N)]
c=collections.Counter(l)
c=c.most_common()
l2=[]
 
M=c.[0][1]
for i in range(len(c)):
    if c.[i][1]==M:
        l2.append(c.[i][0])
    else:
        break
l2.sort()
for j in range(len(l2)):
    print(l2[j])

Buggy submission (verdict: Runtime Error):
import collections
N=int(input())
l=[input() for i in range(N)]
c=collections.Counter(l)
l2=[]

M=c.most_common()[0][1]
for i in range(N):
    if c.most_common()[i][1]==M:
        l2.append(c.most_common()[i][0])
    else:
        break
l2.sort()
for j in range(len(l2)):
    print(l2[j])
Problem p02836 (python)

Fixed submission:
S=input()
L=len(S)
cnt=0
for i in range(L//2):
  if S[i] is not S[L-1-i]:
    cnt +=1
print(cnt)

Buggy submission (verdict: Runtime Error):
S=input()
L=len(S)
cnt=0
for i in range(L):
  if L[i] is not L[L-1-i]:
    cnt +=1
print(cnt)
Problem p02847 (python)

Fixed submission:
S = input()
if S == "SUN":
	print(7)
elif S =="MON":
	print(6)
elif S == "TUE":
	print(5)
elif S == "WED":
	print(4)
elif S == "THU":
	print(3)
elif S == "FRI":
	print(2)
else:
	print(1)

Buggy submission (verdict: Runtime Error):
S = input()
if S = "SUN":
	print(7)
elif S = "MON":
	print(6)
elif S = "TUE":
	print(5)
elif S = "WED":
	print(4)
elif S = "THU":
	print(3)
elif S = "FRI":
	print(2)
else:
	print(1)
Problem p02859 (python)

Fixed submission:
n = int(input())
print(round(n*n))

Buggy submission (verdict: Runtime Error):
N = int(input())
S = input()
if N%" == 1:
	print("NO")
else:
  if (S[0: int(N/2)] == S[int(N/2):N]):
    print("YES")
  else:
    print("NO")
Problem p02860 (python)

Fixed submission:
N = int(input())
S = input()
if N%2 == 1:
  print("No")
else:
  if S[0: N//2] == S[N//2: N]:
    print("Yes")
  else:
    print("No")

Buggy submission (verdict: Runtime Error):
N = int(input())
S = input()
if N%" == 1:
	print("NO")
else:
  if (S[: N//2] == S[N//2:]):
    print("YES")
  else:
    print("NO")

Buggy submission (verdict: Runtime Error):
N = int(input())
S = input()
if N%" == 1:
	print("NO")
else:
  if (S[: N//2] == S[N//2:]):
    print("YES")
  else:
    print("NO")

Buggy submission (verdict: Runtime Error):
N = int(input())
S = input()
if N%2 == 1:
  print("NO")
if (S[0: N/2 -1] == S[N/2: N-1 ]):
  print("YES")
else:
  print("NO")
Problem p03073 (python)

Fixed submission:
s=input()
l=len(s)

ans=0

if s[0]=="0":
    for i in range(1,l):
        if i%2 != 0:
            if s[i] != "1":
                ans+=1
        
        if i%2 == 0:
            if s[i] != "0":
                ans+=1

else:
    for i in range(1,l):
        if i%2 != 0:
            if s[i] != "0":
                ans+=1
        
        if i%2 == 0:
            if s[i] != "1":
                ans+=1

print(ans)

Buggy submission (verdict: Runtime Error):
l=len(s)

ans=0

if s[0]=="0":
    for i in range(1,l):
        if i%2 != 0:
            if s[i] != "1":
                ans+=1
        
        if i%2 == 0:
            if s[i] != "0":
                ans+=1

else:
    for i in range(1,l):
        if i%2 != 0:
            if s[i] != "0":
                ans+=1
        
        if i%2 == 0:
            if s[i] != "1":
                ans+=1

print(ans)
Problem p03207 (python)

Fixed submission:
N = int(input())
list = [int(input())for _ in range(N)]
print(round(sum(list) - max(list)/2))

Buggy submission (verdict: Runtime Error):
N = int(input())
list =[]
for i in range(0, N):
  list = list.append(int(input()))
  
S = sum(list) - max(list)/2
print(S)
Problem p03208 (python)

Fixed submission:
N, K = map(int, input().split())
h = [int(input()) for _ in range(N)]
h.sort()
Min = h[K] - h[0]
for i in range(N-K+1):
  if h[K+i-1] - h[i] < Min:
    Min = h[K+i-1] - h[i]
    
print(Min)

Buggy submission (verdict: Runtime Error):
N, K = map(int, input().split())
h = [int(input()) for _ in range(N)]
h.sort()
Min = h[K] - h[0]
for i in range(N-K+1):
  if h[K+i] - h[i+1] < Min:
    Min = h[K+i] - h[K]
    
print(Min)
Problem p02623 (python)

Fixed submission:
import itertools
n, m, k = map(int, input().split())
a = [0] + list(map(int, input().split()))
b = [0] + list(map(int, input().split()))

sa = list(itertools.accumulate(a))
sb = list(itertools.accumulate(b))

output = 0
j = m
for i in range(n + 1):
    if sa[i] > k:
        break
    while sa[i] + sb[j] > k:
        j -= 1
    if output < i + j:
        output = i + j
print(output)

Buggy submission (verdict: Runtime Error):
from itertools import accumulate
N, M, K = map(int,input().split())
A_list = [0] + list(map(int,input().split()))
B_list = [0] + list(map(int,input().split()))
A_sums_list = list(accumulate(A_list))
B_sums_list = list(accumulate(B_list))

for n in range(N + 1):
    if A_sums_list[n] > K:
        break
    A_max = n
for m in range(M + 1):
    if B_sums_list[m] > K:
        break
    B_max = m
ans = max(A_max, B_max)

for i in reversed(range(A_max + 1)):
    for j in reversed(range(ans - i + 2)):
        if i + j > ans:
            if A_sums_list[i] + B_sums_list[j] <= K:
                ans = i + j
                break
        else:
            break
print(ans)
Problem p02627 (python)

Fixed submission:
N = input()
if N.islower():
    print("a")
else:
    print("A")

Buggy submission (verdict: Runtime Error):
N = int(input())
n = N
alpha = "abcdefghijklmnopqrstuvwxyz"

for i in range(1,12):
    
    if n <= 26 ** i:
        digits = i
        break
    else:
        n -= 26 ** i
#print("桁数は{0}桁".format(digits))
n -= 1
output = ""
for j in range(digits-1):
    amari = n % 26
    n //= 26
    output = alpha[amari] + output
output = alpha[n] + output
print(output)

Buggy submission (verdict: Runtime Error):
N = int(input())
alpha = "abcdefghijklmnopqrstuvwxyz"
output = ""
while N >= 26:
    mod = N % 26
    N = N / 26
    output = alpha[mod-1] + output
output = alpha[N-1] + output
print(output)
Problem p02629 (python)

Fixed submission:
N = int(input())
n = N
alpha = "abcdefghijklmnopqrstuvwxyz"

for i in range(1,12):
    
    if n <= 26 ** i:
        digits = i
        break
    else:
        n -= 26 ** i
#print("桁数は{0}桁".format(digits))
n -= 1
output = ""
for j in range(digits-1):
    amari = n % 26
    n //= 26
    output = alpha[amari] + output
output = alpha[n] + output
print(output)

Buggy submission (verdict: Runtime Error):
N = int(input())
n = N
alpha = "abcdefghijklmnopqrstuvwxyz"

for i in range(1,10):
    
    if n <= 26 ** i:
        digits = i
        break
    else:
        n -= 26 ** i
#print("桁数は{0}桁".format(digits))
n -= 1
output = ""
for j in range(digits-1):
    amari = n % 26
    n //= 26
    output = alpha[amari] + output
output = alpha[n] + output
print(output)
Problem p02659 (python)

Fixed submission:
import math
from decimal import Decimal
a, b = input().split()
a = int(a)
b = Decimal(b)
print(math.floor(a * b))

Buggy submission (verdict: Runtime Error):
import math
A,B = map(double,input().split())
print(int(A * B))
Problem p03013 (python)

Fixed submission:
N, M = map(int,input().split())
A_list = set([int(input()) for _ in range(M)])
Dp_list = [0] * (N+1)
Dp_list[0] = 1

if 1 in A_list:
    Dp_list[1] = 0
else:
    Dp_list[1] = 1

if N != 1:
    for i in range(2, N + 1):
        if i in A_list:
            continue

        Dp_list[i] = Dp_list[i-2] + Dp_list[i-1]
        Dp_list[i] %= 1000000007
    print(Dp_list[N])
else:
    print(1)

Buggy submission (verdict: Runtime Error):
N, M = map(int,input().split())
A_list = []
for i in range(M):
    A_list.append(int(input()))
if A_list:
    if A_list[0] == 1:
        Dp_list = [1,0]
    elif N == 1:
        print(1)
    else:
        Dp_list = [1,1]
else:
    Dp_list = [1,1]
if A_list and N != 1:
    for i in range(2, N + 1):
        if i not in A_list:
            Dp_list.append(Dp_list[i-2] + Dp_list[i-1])
        elif i in A_list and i-1 in A_list:
            Dp_list = [0] * (N + 1)
            break
        else:
            Dp_list.append(0)
        if Dp_list[i-1] > 1000000007:
            Dp_list[i-1] -= 1000000007
            Dp_list[i] -= 1000000007
	print(Dp_list[N]%1000000007)

Buggy submission (verdict: Runtime Error):
N, M = map(int,input().split())
A_list = []
for i in range(M):
    A_list.append(int(input()))
if A_list[0] == 1:
    Dp_list = [1,0]
else:
    Dp_list = [1,1]
for i in range(2, N + 1):
    if i not in A_list:
        Dp_list.append(Dp_list[i-2] + Dp_list[i-1])
    elif i in A_list and i-1 in A_list:
        Dp_list = [0] * (N + 1)
        break
    else:
        Dp_list.append(0)
    if Dp_list[i-1] > 1000000007:
        Dp_list[i-1] -= 1000000007
        Dp_list[i] -= 1000000007
print(Dp_list[N]%1000000007)

Buggy submission (verdict: Runtime Error):
N, M = map(int,input().split())
A_list = []
for i in range(M):
    A_list.append(int(input()))
if A_list[0] == 1:
    Dp_list = [1,0]
else:
    Dp_list = [1,1]
for i in range(2, N + 1):
    if i not in A_list:
        Dp_list.append(Dp_list[i-2] + Dp_list[i-1])
    elif i in A_list and i-1 in A_list:
        Dp_list = [0] * (N + 1)
        break
    else:
        Dp_list.append(0)
print(Dp_list[N]%1000000007)
Problem p02834 (python)

Fixed submission:
import sys
sys.setrecursionlimit(100000000)
n, runner, chaser = map(int, input().split())
runner -= 1
chaser -= 1
if runner == chaser:
    print(0)
    exit()

tree = [[] for _ in range(n)]
for i in range(n-1):
    a,b = map(int, input().split())
    a -= 1
    b -= 1
    tree[a].append(b)
    tree[b].append(a)

def dfs(dists, start, d=0, p=-1):  
    dists[start] = d
    for neighbor in tree[start]:
        if neighbor == p:
            continue
        dfs(dists, neighbor, d+1, start)

def dist(start):
    dists = [0 for _ in range(n)]
    dfs(dists, start)
    return dists

furthest = 0
run_dist = dist(runner)
chs_dist = dist(chaser)
for i in range(n):
    if run_dist[i] < chs_dist[i]:
        furthest = max(furthest, chs_dist[i])

ans = furthest-1

print(ans)

Buggy submission (verdict: Runtime Error):
n, runner, chaser = map(int, input().split())
runner -= 1
chaser -= 1
if runner == chaser:
    print(0)

tree = {}
for i in range(n-1):
    a,b = map(int, input().split())
    a -= 1
    b -= 1
    if tree.get(a) is None:
        tree[a] = []
    if tree.get(b) is None:
        tree[b] = []
    tree[a].append(b)
    tree[b].append(a)


def dfs(dists, start, d=0, p=-1):  
    dists[start] = d
    for neighbor in tree[start]:
        if neighbor == p:
            continue
        dfs(dists, neighbor, d+1, start)

def dist(start):
    dists = [0 for _ in range(n)]
    dfs(dists, start)
    return dists

furthest = 0
run_dist = dist(runner)
chs_dist = dist(chaser)
for i in range(n):
    if run_dist[i] < chs_dist[i]:
        furthest = max(furthest, chs_dist[i])

ans = furthest-1

print(ans)
Problem p02580 (python)

Fixed submission:
import sys
from collections import Counter


def main():
    H, W, M = map(int, sys.stdin.readline().rstrip().split())
    Mh = [0] * H
    Mw = [0] * W
    B = []
    for i in range(M):
        h, w = map(int, sys.stdin.readline().rstrip().split())
        Mh[h - 1] += 1
        Mw[w - 1] += 1
        B.append((h - 1, w - 1))

    nh = max(Mh)
    nw = max(Mw)

    # 交差する場所に置かれた処理物があるか？
    lh = Counter(Mh)[nh]
    lw = Counter(Mw)[nw]

    out = 0
    for (h, w) in B:
        if Mh[h] == nh and Mw[w] == nw:
            out += 1

    if out == lh * lw:
        print(nh + nw - 1)
    else:
        print(nh + nw)


main()

Buggy submission (verdict: Runtime Error):
import sys


def main():
    H, W, M = map(int, sys.stdin.readline().rstrip().split())
    Mh = [0] * H
    Mw = [0] * W
    B = []
    for i in range(M):
        h, w = map(int, sys.stdin.readline().rstrip().split())
        Mh[h - 1] += 1
        Mw[w - 1] += 1
        B.append((h - 1, w - 1))

    nh = max(Mh)
    nw = max(Mw)

    # 交差する場所に置かれた処理物があるか？
    lh = [i for i, v in enumerate(lh) if v == nh]
    lw = [i for i, v in enumerate(lw) if v == nw]

    for h in lh:
        for w in lw:
            if (h, w) not in B:
                print(nh + nw)
                return

    print(nh + nw - 1)


main()
Problem p02597 (python)

Fixed submission:
import sys
from collections import Counter

N = int(sys.stdin.readline().rstrip())
S = [x for x in input()]

C = Counter(S)

W = C["W"]
R = C["R"]

SS = S[:R]
CC = Counter(SS)
RR = CC["W"]

print(RR)

Buggy submission (verdict: Runtime Error):
import sys

N = int(sys.stdin.readline().rstrip())
TMP_C = [x for x in input()]
C = []
for i in range(N - 1, -1, -1):
    C.append(TMP_C[i])
# print(C)

cnt = 0
for i in range(N - 1, -1, -1):
    if C[i] == "W":
        j = C.index("R")
        if j < i:
            C[i], C[j] = C[j], C[i]
            cnt += 1

print(cnt)
Problem p02623 (python)

Fixed submission:
import sys

INF = 10**9 + 5

N, M, K = map(int, sys.stdin.readline().rstrip().split())
A = [int(x) for x in sys.stdin.readline().rstrip().split()]
B = [int(x) for x in sys.stdin.readline().rstrip().split()]

tmpA = [INF] * (N + 1)
tmpA[0] = 0

cntA = 0
# A だけを読み続けた場合の所要時間を記録
for i in range(1, N + 1):
    tmpA[i] = A[i - 1] + tmpA[i - 1]
    cntA = i
    if tmpA[i] > K:
        break

# print(tmpA, cntA)  # cntA 冊目まで読める

# A を一冊ずつ減らして、最大値を探索
j = 0
vol = 0
tmpB = 0

for i in range(cntA, -1, -1):
    rest = K - tmpA[i]  # 残り時間
    # print(f"A{i} 残時間 : {rest}")
    while j < M + 1:
        # print(f"B {j}冊 {tmpB}分")
        if rest < tmpB:  # 　tmpB が残り時間を超えたら終了
            break
        vol = max(i + j, vol)
        if j >= M:
            break
        tmpB += B[j]  # 超えていなければ新しい本を追加してみる
        j += 1

print(vol)

Buggy submission (verdict: Runtime Error):
import sys

INF = 10**9 + 5

N, M, K = map(int, sys.stdin.readline().rstrip().split())
A = [int(x) for x in sys.stdin.readline().rstrip().split()]
B = [int(x) for x in sys.stdin.readline().rstrip().split()]

A.append(INF)
A.append(INF)
i, j = 0, 0
t = 0
while i < N or j < M:

    if A[i] < B[j]:
        t += A[i]
        if t > K: break
        i += 1
    else:
        t += B[j]
        if t > K: break
        j += 1

print(i + j)
Problem p02679 (python)

Fixed submission:
import math
from collections import Counter

MOD = 10**9 + 7
N = int(input())

I = []
zz = 0
sz = 0
tz = 0
for _ in range(N):
    a,b = map(int, input().split())

    # (a, b) = (0, 0)
    if a == 0 and b == 0:
        zz += 1
        continue
    # (a, b) = (0, #)
    if a == 0:
        sz += 1
        continue
    # (a, b) = (#, 0)
    if b == 0:
        tz += 1
        continue

    gcd = math.gcd(a, b)
    if b < 0:
        a *= -1
        b *= -1
    I.append((a//gcd,b//gcd))

S = []
T = []
C = Counter(I)
for a, b in C.keys():
    if a > 0:
        S.append(C[(a,b)])
        T.append(C[(-b,a)])
    else:
        if C[(b,-a)] == 0:
            S.append(0)
            T.append(C[(a,b)])

ans = 1
ans *= 2**sz + 2**tz - 1
ans %= MOD
for i in range(len(S)):
    ans *= 2**S[i] + 2**T[i] - 1
    ans %= MOD
ans += zz  # (0, 0)
ans -= 1
print(ans % MOD)

Buggy submission (verdict: Runtime Error):
import math
from collections import Counter

MOD = 10**9 + 7
N = int(input())

I = []
zz = 0
sz = 0
tz = 0
for _ in range(N):
    a,b = map(int, input().split())

    # (a, b) = (0, 0)
    if a == 0 and b == 0:
        zero += 1
        continue
    # (a, b) = (0, #)
    if a == 0:
        sz += 1
        continue
    # (a, b) = (#, 0)
    if b == 0:
        tz += 1
        continue

    gcd = math.gcd(a, b)
    if b < 0:
        a *= -1
        b *= -1
    I.append((a//gcd,b//gcd))

S = []
T = []
C = Counter(I)
for a, b in C.keys():
    if a > 0:
        S.append(C[(a,b)])
        T.append(C[(-b,a)])
    else:
        if C[(b,-a)] == 0:
            S.append(0)
            T.append(C[(a,b)])

ans = 1
ans *= 2**sz + 2**tz - 1
ans %= MOD
for i in range(len(S)):
    ans *= 2**S[i] + 2**T[i] - 1
    ans %= MOD
ans += zz  # (0, 0)
ans -= 1
print(ans % MOD)

Buggy submission (verdict: Runtime Error):
import math
from collections import Counter

MOD = 10**9 + 7
N = int(input())

I = []
zz = 0
sz = 0
tz = 0
for _ in range(N):
    a,b = map(int, input().split())

    # (a, b) = (0, 0)
    if a == 0 and b == 0:
        zero += 1
        continue
    # (a, b) = (0, #)
    if a == 0:
        sz += 1
        continue
    # (a, b) = (#, 0)
    if b == 0:
        tz += 1
        continue

    gcd = math.gcd(a, b)
    if b < 0:
        a *= -1
        b *= -1
    I.append((a//gcd,b//gcd))

S = []
T = []
C = Counter(I)
for a, b in C.keys():
    if a > 0:
        S.append(C[(a,b)])
        T.append(C[(-b,a)])
    else:
        if C[(b,-a)] == 0:
            S.append(0)
            T.append(C[(a,b)])

ans = 1
ans *= 2**sz + 2**tz - 1
for i in range(len(S)):
    ans *= 2**S[i] + 2**T[i] - 1
ans += zz  # (0, 0)
ans -= 1
print(ans)
Problem p02685 (python)

Fixed submission:
N, M, K = map(int, input().split())
MOD = 998244353

fac = [1, 1] # 元テーブル
facinv = [1, 1] #逆元テーブル
inv = [0, 1] #逆元テーブル計算用テーブル

for i in range( 2, N + 1 ):
    fac.append( ( fac[-1] * i ) % MOD )
    inv.append( ( -inv[MOD % i] * (MOD//i) ) % MOD )
    facinv.append( (facinv[-1] * inv[-1]) % MOD )

def cmb(n, r):
    if ( r<0 or r>n ):
        return 0
    r = min(r, n-r)
    return fac[n] * facinv[r] * facinv[n-r] % MOD

sum = 0
for k in range(K+1):
    sum += M * pow(M-1,N-1-k, MOD) * cmb(N-1,k) % MOD
    sum %= MOD

print(sum % MOD)

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

dp = [ [0] * (K+1) for _ in range(N+1)]

# 1個目
dp[1][0] = M

for i in range(1,N):
    for k in range(K+1):
        dp[i+1][k] += dp[i][k] * (M-1) % MOD  # 違う色
        if K > k:
            dp[i+1][k+1] += dp[i][k] % MOD # 同じ色


sum(dp[N]) % MOD
Problem p02726 (python)

Fixed submission:
import itertools
import collections

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

pos = [i for i in range(1,N+1)]
ways = list(itertools.combinations(pos,2))

dist_l = [min(abs(i-j), abs(i - X) + 1 + abs(Y - j)) for i,j in ways]

dic = collections.Counter(dist_l)
for i in range(1,N):
    print(dic[i])

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

dist_l = [0] * N
for i in range(N-1):
    for j in range(i+1,N):
        dist_l[min(j-i, abs(i - X) + 1 + abs(Y - j))] += 1

for i in range(1,N):
    print(dict_l[i])

Buggy submission (verdict: Runtime Error):
import itertools

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

pos = [i for i in range(1,N+1)]
ways = list(itertools.combinations(pos,2))

dist_l = [min(abs(i-j), abs(i - X) + 1 + abs(Y - j)) for i,j in ways]

dic = collections.Counter(dist_l)
for i in range(1,N):
    print(dic[i])
Problem p02729 (python)

Fixed submission:
import math

N,M = map(int, input().split())

# 両方ともNから選ぶ
a = 0
if N > 1:
    a = int(math.factorial(N) / (math.factorial(N-2)*2))

# 両方ともMから選ぶ
b = 0
if M > 1:
    b = int(math.factorial(M) / (math.factorial(M-2)*2))

print(a + b)

Buggy submission (verdict: Runtime Error):
import numpy as np
import itertools

H, W, K = map(int, input().split())
choco = []
for i in range(H):
    choco.append([int(x) for x in list(input())])

arr = np.array(choco)

# W方向にGREEDY
count = (H-1) + (W-1)

for k in range(H):
    
    # この時点で同じ回数以上切ることが確定なら終了
    if count <= k:
        break

    # H 方向に切り込み
    for comb in itertools.combinations(range(1,H),k):

        # スライスを作っておく
        t = (None,) + comb + (None,)
        s = [slice(t[j],t[j+1],) for j in range(len(t)-1)]
        
        # print(t)
        
        sum_p = [0] * (k+1)
        
        cut = k
        
        for col in zip(*choco):
                        
            # 全 H で成立するか？
            sum_a = [sum(col[b]) for b in s]
            # print(sum_a)
            
            if any(map(K.__lt__, sum_a)):
                # 不成立
                break
            
            sum_b = [x+y for x,y in zip(sum_p, sum_a)]

            if any(map(K.__lt__, sum_b)):
                cut += 1
                sum_p = [0] * (k+1)
            else:
                sum_p = sum_b
                
                # 割った位置を記録
        
        else:
            count = min(count,cut)

print(count)