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

Fixed submission:
w,h,n=map(int, input().split())
x=[]
y=[]
a=[]
for i in range(n):
  s=input().split()
  x.append(int(s[0]))
  y.append(int(s[1]))
  a.append(int(s[2]))
x_l=0
x_h=w
y_l=0
y_h=h
for i in range(n):
  if a[i]==1:
    if x_l<x[i]:
      x_l=x[i]
  elif a[i]==2:
    if x_h>x[i]:
      x_h=x[i]
  elif a[i]==3:
    if y_l<y[i]:
      y_l=y[i]
  else:
    if y_h>y[i]:
      y_h=y[i]
if x_h>x_l and y_h>y_l:
  print((x_h-x_l)*(y_h-y_l))
else:
  print("0")

Buggy submission (verdict: Runtime Error):
w,h,n=map(int, input().split())
x=[]
y=[]
a=[]
for i in range(n):
  s=map(int, input().split())
  x.append(s[0])
  y.append(s[1])
  a.append(s[2])
x_l=0
x_h=w
y_l=0
y_h=h
for i in range(n):
  if a[i]==1:
    if x_l<x[i]:
      x_l=x[i]
  elif a[i]==2:
    if x_h>x[i]:
      x_h=x[i]
  elif a[i]==3:
    if y_l<y[i]:
      y_l=y[i]
  else:
    if y_h>y[i]:
      y_h=y[i]
s=(x_h-x_l)*(y_h-y_l)
if s>0:
  print(s)
else:
  print("0")
Problem p03998 (python)

Fixed submission:
s=[]
for i in range(3):
  s.append(input())
member=["A","B","C"]
turn=0

while True:
  if s[turn]=="":
      winner=turn
      break
  if s[turn][0]=="a":
    next=0
  elif s[turn][0]=="b":
    next=1
  else:
    next=2
  s[turn]=s[turn][1:]
  turn=next

print(member[winner])

Buggy submission (verdict: Runtime Error):
for i in range(3):
  s.append(input())
member=["A","B","C"]
turn=0

while True:
  if s[turn]=="":
    winner=turn
    break
  elif s[turn][0]=="a":
    s[turn]=s[turn][1:]
    turn=0
  elif s[turn][0]=="b":
    s[turn]=s[turn][1:]
    turn=1
  else:
    s[turn]=s[turn][1:]
    turn=2
print(member[winner])
Problem p04012 (python)

Fixed submission:
w=input()

dict={}
alh="abcdefghijklmnopqrstuvwxyz"
for i in alh:
  dict[i]=0
for i in w:
  dict[i]+=1
flag=True
for i in alh:
  if dict[i]%2==1:
    flag=False
if flag:
  print("Yes")
else:
  print("No")

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

dict={}
alh="abcdefghijklmnopqrstuvwxyz"
for i in alh:
  dict[i]=0
for i in w:
  dict[i]+=1
flag=True
for j in range(len(dict)):
  if dict[j]%2==1:
    flag=False
if flag:
  print("Yes")
else:
  print("No")

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

dict={}
for i in w:
  dict[i]+=1
flag=True
for j in range(len(dict)):
  if dict[j]%2==1:
    flag=False
if flag:
  print("Yes")
else:
  print("No")
Problem p02657 (python)

Fixed submission:
a, b = map(int, input().split())
print(a*b)

Buggy submission (verdict: Runtime Error):
a = int(input())
b = int(input())
print(a*b)

Buggy submission (verdict: Runtime Error):
a, b = int(input()), int(input())
print(a*b)
Problem p02658 (python)

Fixed submission:
n = int(input())
ls = list(map(int, input().split()))
res = 1
if 0 in ls:
    print(0)
    quit()
for x in ls:
    res *= x
    if res > 10**18:
        print(-1)
        quit()
print(res)

Buggy submission (verdict: Runtime Error):
import numpy
n = int(input())
ls = list(map(int, input().split()))
if 0 in ls:
    print(0)
res = numpy.prod(ls)
elif res > 10**18:
    print(-1)
else:
    print(numpy.prod(ls))

Buggy submission (verdict: Runtime Error):
import numpy
n = int(input())
ls = [int(input()) for _ in range(n)]
if 0 in ls:
    print(0)
res = numpy.prod(ls)
elif res > 10**18:
    print(-1)
else:
    print(numpy.prod(ls))
Problem p02606 (python)

Fixed submission:
L, R, d = [int(digit) for digit in input().split()]
c = 0

for i in range(L, R+1):
    if i % d == 0:
        c += 1

print(c)

Buggy submission (verdict: Runtime Error):
L, R, d = [int(digit) for digit in input()]
c = 0

for i in range(L, R+1):
    if i % d == 0:
        c += 1

print(c)

Buggy submission (verdict: Runtime Error):
L, R, d = [int(digit) for digit in input()]
c = 0

for i in range(L, R+1):
    if i % d == 0:
        c += 1
Problem p02628 (python)

Fixed submission:
n, k = map(int, input().split())
p = list(map(int, input().split()))
p.sort()

i = 0
price = 0
while i < k:
  price += p[i]
  i += 1
 
print(price)

Buggy submission (verdict: Runtime Error):
n, k = map(int, input().split())
p = list(map(int, input().split()))
 
p.sort()
 
i = 0
price = 0
while i < k:
  price += p[i]
  i ++
  
print(price)

Buggy submission (verdict: Runtime Error):
n, k = map(int, input().split())
p = list(map(int, input().split()))
 
p.sort()
 
i = 0
while i < k:
  i += p[i]
  i ++
  
print(i)

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

p.sort(reverse=True)

i = 0
while i < k:
  i += p[i]
  i ++
  
print(i)
Problem p02730 (python)

Fixed submission:
S=str(input())
import sys
t=0
lista=[]
for i in range(99):
    try:
        lista.append(S[i])
        t=t+1
    except IndexError:
        break
u=t//2
v=u//2+1
p=1
for i in range(v):
    if S[i]==S[u-i-1] and S[u-i-1]==S[u+i+1] and S[u+i+1]==S[t-1-i]:
        p=p*1
    else:
        print ('No')
        sys.exit()
print ('Yes')

Buggy submission (verdict: Runtime Error):
S=str(input())
import sys
t=0
lista=[]
for i in range(99):
  try:
    lista.append(S[i])
    t=t+1
  except IndexError:
    break
u=t//2
v=u//2+1
p=1
for i in range(v):
  if S[i]==S[u-i-1]:
    p=p*1
  else:
    print ('No')
    sys.exit()
for j in range(v):
  if S[u+j+1]==S[t-1-j]:
    p=p*1
  else:
    print ('No')
    sys.exit()
if t>3:
  print ('Yes')
else:
  if S[0]=S[2]:
    print ('Yes')
  else:
    print ('No')

Buggy submission (verdict: Runtime Error):
S=str(input())
import sys
t=0
lista=[]
for i in range(99):
  try:
    lista.append(S[i])
    t=t+1
  except IndexError:
    break
print (t)
u=t//2
v=u//2+1
p=1
for i in range(v):
  if S[i]==S[u-i-1]:
    p=p*1
  else:
    print ('No')
    sys.exit()
for j in range(v):
  if S[u+j+1]==S[t-1-j]:
    p=p*1
  else:
    print ('No')
    sys.exit()
if t>3:
  print ('Yes')
else:
  if S[0]=S[2]:
    print ('Yes')
  else:
    print ('No')
Problem p02741 (python)

Fixed submission:
b=[1, 1, 1, 2, 1, 2, 1, 5, 2, 2, 1, 5, 1, 2, 1, 14, 1, 5, 1, 5, 2, 2, 1, 15, 2, 2, 5, 4, 1, 4, 1, 51]
K=int(input())
print (b[K-1])

Buggy submission (verdict: Runtime Error):
a,b,c=map(int,input().split())

if a**0.5+b**0.5<c**0.5:
  print ('Yes')
else:
  print ('No')
Problem p02755 (python)

Fixed submission:
x,y=map(int, input().split())
import math
x1=math.ceil(x*12.5)
x2=math.ceil((x+1)*12.5)-1
y1=math.ceil(y*10)
y2=math.ceil((y+1)*10)-1
if x1>y2 or y1>x2:
	print (-1)
else:
	print (int(max(x1,y1)))

Buggy submission (verdict: Runtime Error):
x,y=map(int, input().split())
import math
x1=math.ceil(x*12.5)
x2=math.ceil((x+1)*12.5)-1
y1=math.ceil(y*10)
y2=math.ceil((y+1)*10)-1
if x1>y2 or y1>x2:
	print -1
else:
	print (int(max(x1,y1)))

Buggy submission (verdict: Runtime Error):
x,y=input(),input()
import math
x1=math.ceil(x*12.5)
x2=math.ceil((x+1)*12.5)-1
y1=math.ceil(y*10)
y2=math.ceil((y+1)*10)-1
if x1>y2 or y1>x2:
	print -1
else:
	print  int(max(x1,y1))

Buggy submission (verdict: Runtime Error):
x,y=input(),input()
import math
x1=math.ceil(x*12.5)
x2=math.ceil((x+1)*12.5)-1
y1=math.ceil(y*10)
y2=math.ceil((y+1)*10)-1
if x1>y2 or y1>x2:
	print -1
else:
	print  int(max(x1,y1))
Problem p02731 (python)

Fixed submission:
L = int(input())

print((L/3)**3)

Buggy submission (verdict: Runtime Error):
L = int(intput())

print(L/3**3)
Problem p02747 (python)

Fixed submission:
S = list(input())
len = len(S)
flag = 1
s = S[0]


for i in range(0, len, 2):
    if len%2 == 1:
        flag = 0
        break

    if S[i] != 'h' or S[i+1] != 'i':
            flag = 0

    """""
    if s == 'h':
        if S[i] == 'i':
            flag = 1
    if s == 'i':
        if S[i] == 'h':
            flag = 1
    s = S[i]
    """

if flag == 1:
    print('Yes')
else:
    print('No')

Buggy submission (verdict: Runtime Error):
S = list(input())
len = len(S)
flag = 1
s = S[0]


for i in range(1, len):
    if S[1] == null:
        break
    if s == 'h':
        if S[i] != 'i':
            flag = 0
            break
    if s == 'i':
        if S[i] != 'h':
            flag = 0
            break
    s = S[i]

if flag == 1:
    print('Yes')
else:
    print('No')
Problem p02609 (python)

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

X_pc = X.count("1")
X_res_m1 = 0
X_res_p1 = 0
for i, s in enumerate(reversed(X)):
    if s == "1":
        if X_pc > 1:
            X_res_m1 += pow(2, i, X_pc - 1)
            X_res_m1 %= X_pc - 1

        X_res_p1 += pow(2, i, X_pc + 1)
        X_res_p1 %= X_pc + 1

f = [-1] * (X_pc + 1)
f[0] = 0
for n in range(1, X_pc + 1):
    pc = format(n, "b").count("1")
    f[n] = f[n % pc] + 1

ans = []
for i, s in enumerate(reversed(X)):
    if s == "1":
        if X_pc > 1:
            fx = (X_res_m1 - pow(2, i, X_pc - 1)) % (X_pc - 1)
            ans.append(f[fx] + 1)
        else:
            ans.append(0)

    else:
        fx = (X_res_p1 + pow(2, i, X_pc + 1)) % (X_pc + 1)
        ans.append(f[fx] + 1)

print(*reversed(ans), sep="\n")

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

N_ub = 2 * 10 ** 5
f = [-1] * (N_ub + 1)
f[0] = 0
for n in range(1, N_ub + 1):
    pc = format(n, "b").count("1")
    f[n] = f[n % pc] + 1

X_pc = X.count("1")
X_res_m1 = 0
X_res_p1 = 0
for i, s in enumerate(reversed(X)):
    if s == "1":
        X_res_m1 += pow(2, i, X_pc - 1)
        X_res_m1 %= X_pc - 1

        X_res_p1 += pow(2, i, X_pc + 1)
        X_res_p1 %= X_pc + 1

ans = []
for i, s in enumerate(reversed(X)):
    if s == "1":
        fx = (X_res_m1 - pow(2, i, X_pc - 1)) % (X_pc - 1)
        ans.append(f[fx] + 1)
    else:
        fx = (X_res_p1 + pow(2, i, X_pc + 1)) % (X_pc + 1)
        ans.append(f[fx] + 1)

print(*reversed(ans), sep="\n")

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

N_ub = 2 * 10 ** 5
f = [-1] * (N_ub)
f[0] = 0
for n in range(1, N_ub):
    pc = format(n, "b").count("1")
    f[n] = f[n % pc] + 1

X_pc = X.count("1")
X_res_m1 = 0
X_res_p1 = 0
for i, s in enumerate(reversed(X)):
    if s == "1":
        X_res_m1 += pow(2, i, X_pc - 1)
        X_res_m1 %= X_pc - 1

        X_res_p1 += pow(2, i, X_pc + 1)
        X_res_p1 %= X_pc + 1

ans = []
for i, s in enumerate(reversed(X)):
    if s == "1":
        fx = (X_res_m1 - pow(2, i, X_pc - 1)) % (X_pc - 1)
        ans.append(f[fx] + 1)
    else:
        fx = (X_res_p1 + pow(2, i, X_pc + 1)) % (X_pc + 1)
        ans.append(f[fx] + 1)

print(*reversed(ans), sep="\n")
Problem p02642 (python)

Fixed submission:
from collections import Counter

_ = int(input())
A = list(map(int, input().split()))
a_max = 10 ** 6

c = Counter(A)
b = list(set(A))
b.sort()

dp = [True] * (a_max + 1)
ans = 0
for a in b:
    if dp[a]:
        if c[a] == 1:
            ans += 1
        for i in range(2 * a, a_max + 1, a):
            dp[i] = False

print(ans)

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

A.sort()
basis = []

for a in A:
    for b in basis:
        if a % b == 0:
            break
    else:
        basis.append(a)

ans = 0
c = Counter(A)
for b in basis:
    if c[b] == 1:
        ans += 1

print(ans)
Problem p02698 (python)

Fixed submission:
import bisect
import sys


N = int(input())
a = list(map(int, input().split()))
to = [[] for _ in range(N)]
for _ in range(N - 1):
    u, v = map(int, input().split())
    u -= 1
    v -= 1
    to[u].append(v)
    to[v].append(u)
del u, v

ans = [-1] * N


def dfs(v, dp):
    # dp は参照渡し
    if len(dp) == 0 or a[v] > dp[-1]:
        dp.append(a[v])
        back = -1
    else:
        pos = bisect.bisect_left(dp, a[v])
        back = dp[pos]
        dp[pos] = a[v]
    ans[v] = len(dp)

    for u in to[v]:
        if ans[u] == -1:
            dfs(u, dp)
    if back == -1:
        dp.pop()
    else:
        dp[pos] = back


sys.setrecursionlimit(10 ** 6)
dfs(0, [])


for an in ans:
    print(an)

Buggy submission (verdict: Runtime Error):
import bisect

N = int(input())
a = list(map(int, input().split()))
to = [[] for _ in range(N)]
for _ in range(N - 1):
    u, v = map(int, input().split())
    u -= 1
    v -= 1
    to[u].append(v)
    to[v].append(u)
del u, v

ans = [-1] * N


def dfs(v, prev_dp):
    dp = [*prev_dp]
    if len(dp) == 0 or a[v] > dp[-1]:
        dp.append(a[v])
    else:
        pos = bisect.bisect_left(dp, a[v])
        dp[pos] = a[v]
    ans[v] = len(dp)

    for u in to[v]:
        if ans[u] == -1:
            dfs(u, dp)


dfs(0, [])


for an in ans:
    print(an)
Problem p02720 (python)

Fixed submission:
import numpy as np

K = int(input())

top = np.ones(10, dtype=int)
adj = np.eye(10, dtype=int)
adj[1:, :-1] += np.eye(9, dtype=int)
adj[:-1, 1:] += np.eye(9, dtype=int)

counts = [top]
tmp = top
for _ in range(10):
    tmp = np.dot(tmp, adj)
    counts.append(tmp)

for i in range(10):
    for j in range(1, 10):
        if K > counts[i][j]:
            K -= counts[i][j]
        else:
            break
    else:
        continue
    break

ans = [-1] * (i + 1)
ans[i] = j

for d in range(i, 0, -1):
    for k in range(max(0, j - 1), min(9, j + 1) + 1):
        if K > counts[d - 1][k]:
            K -= counts[d - 1][k]
        else:
            ans[d - 1] = k
            j = k
            break


print("".join(list(map(str, ans))[::-1]))

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

K = int(input())

top = np.ones(10, dtype=int)
# top[0] = 0
adj = np.eye(10, dtype=int)
adj[1:, :-1] += np.eye(9, dtype=int)
adj[:-1, 1:] += np.eye(9, dtype=int)

counts = [top]
tmp = top
for _ in range(10):
    tmp = tmp.__matmul__(adj)
    counts.append(tmp)

for i in range(10):
    for j in range(1, 10):
        if K > counts[i][j]:
            K -= counts[i][j]
        else:
            break
    else:
        continue
    break

ans = [-1] * (i + 1)
ans[i] = j

for d in range(i, 0, -1):
    for k in range(max(0, j - 1), min(9, j + 1) + 1):
        if K > counts[d - 1][k]:
            K -= counts[d - 1][k]
        else:
            ans[d - 1] = k
            j = k
            break


print("".join(list(map(str, ans))[::-1]))
Problem p02787 (python)

Fixed submission:
from functools import lru_cache
import sys

sys.setrecursionlimit(10 ** 8)

H, N = map(int, input().split())
AB = [tuple(map(int, input().split())) for _ in range(N)]
# 効率順にソート
# 効率が同じなら、小規模な魔法を優先
AB.sort(key=lambda ab: (ab[1] / ab[0], ab[0]))


@lru_cache(maxsize=None)
def dp(h):
    if h <= 0:
        return 0
    else:
        best = float("inf")
        for a, b in AB:
            val = b + dp(h - a)
            if val < best:
                best = val
            else:
                # 更新されなかった場合は、以降の魔法で更新されることはない
                break
        return best


print(dp(H))

Buggy submission (verdict: Runtime Error):
from functools import lru_cache
import sys

sys.setrecursionlimit(10 ** 8)

H, N = map(int, input().split())
AB = [tuple(map(int, input().split())) for _ in range(N)]
# 効率が高い順にソート
# 効率が同じなら、小規模な順
AB.sort(key=lambda ab: (ab[1] / ab[0], ab[0]))


@lru_cache(maxsize=None)
def dp(h):
    if h <= 0:
        return 0
    else:
        for a, b in AB:
            val = b + dp(h - a)
            if val < best:
                best = val
            else:
                # 更新されなかった場合は、以降の魔法で更新されることはない
                break
        return best


print(dp(H))
Problem p02803 (python)

Fixed submission:
from scipy.sparse.csgraph import dijkstra, csgraph_from_dense
import numpy as np

H, W = map(int, input().split())
S = [input() for _ in range(H)]

v_id_dict = {}
dista = np.ones((400, 400)) * np.inf

for i in range(H):
    for j in range(W):
        if S[i][j] == ".":
            v_id_dict[i, j] = len(v_id_dict)

            if (i > 0) and (S[i - 1][j] == "."):
                dista[v_id_dict[(i, j)], v_id_dict[(i - 1, j)]] = 1

            if (j > 0) and (S[i][j - 1] == "."):
                dista[v_id_dict[(i, j)], v_id_dict[(i, j - 1)]] = 1

dist_mat = dijkstra(
    csgraph_from_dense(dista[: len(v_id_dict), : len(v_id_dict)]),
    directed=False,
    unweighted=False,
)

print(int(dist_mat.max()))

Buggy submission (verdict: Runtime Error):
from scipy.sparse.csgraph import dijkstra, csgraph_from_dense
import numpy as np

H, W = map(int, input().split())
S = [input() for _ in range(H)]

v_id_dict = {}
dista = np.ones((20, 20)) * np.inf

for i in range(H):
    for j in range(W):
        if S[i][j] == ".":
            v_id_dict[i, j] = len(v_id_dict)

            if (i > 0) and (S[i - 1][j] == "."):
                dista[v_id_dict[(i, j)], v_id_dict[(i - 1, j)]] = 1

            if (j > 0) and (S[i][j - 1] == "."):
                dista[v_id_dict[(i, j)], v_id_dict[(i, j - 1)]] = 1

dist_mat = dijkstra(
    csgraph_from_dense(dista[: len(v_id_dict), : len(v_id_dict)]),
    directed=False,
    unweighted=False,
)

print(int(dist_mat.max()))
Problem p02823 (python)

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

if (B - A) % 2 == 0:
    ans = (B - A) // 2
else:
    ans = min((B - 1 + A - 1 + 1) // 2, (N - A + N - B + 1) // 2)
print(ans)

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

A.sort(reverse=True)

cum_A = [0]
for ai in A:
    cum_A.append(cum_A[-1] + ai)

cur_Ai = A[P]
ans = P
j = P
for i in range(P, N):
    if (i + 1 < N) and (A[i] == A[i + 1]):
        continue

    while A[j] >= A[i] + M:
        j += 1

    if A[i] + M < A[P - 1]:
        break
    elif (
        M * (P - 1)
        + (A[i] + M) * (i + 1 - j)
        - (cum_A[i + 1] - cum_A[j])
        + M * (N - i - 1)
        >= M * V
    ):
        ans = i + 1
    else:
        break

print(ans)
Problem p02840 (python)

Fixed submission:
from fractions import gcd
from collections import defaultdict

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

if D == 0:
    if X == 0:
        ans = 1
    else:
        ans = N + 1
else:
    if D < 0:
        X = -X
        D = -D
    g = gcd(X, D)
    X //= g
    D //= g

    AN = X + D * (N - 1)

    intervals_dict = defaultdict(list)
    for k in range(N + 1):
        start = k * (2 * X + (k - 1) * D) // 2
        end = k * (2 * AN - (k - 1) * D) // 2

        intervals_dict[start % D].append((start // D, end // D + 1))

    ans = 0
    for k, v in intervals_dict.items():
        v.sort()

        current_stop = -float("inf")
        for start, stop in v:
            ans += max(stop, current_stop) - max(start, current_stop)
            current_stop = max(current_stop, stop)

print(ans)

Buggy submission (verdict: Runtime Error):
from fractions import gcd
from collections import defaultdict

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

# preprocess
if D < 0:
    X = -X
    D = -D
g = gcd(X, D)
X //= g
D //= g

AN = X + D * (N - 1)

intervals_dict = defaultdict(list)
for k in range(N + 1):
    start = k * (2 * X + (k - 1) * D) // 2
    end = k * (2 * AN - (k - 1) * D) // 2

    intervals_dict[start % D].append((start // D, end // D +1))

ans = 0
for k, v in intervals_dict.items():
    v.sort()

    current_stop = -float("inf")
    for start, stop in v:
        ans += max(stop, current_stop) - max(start, current_stop) 
        current_stop = max(current_stop, stop)

print(ans)

Buggy submission (verdict: Runtime Error):
from fractions import gcd

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

# preprocess
if D < 0:
    X = -X
    D = -D
g = gcd(X, D)
X //= g
D //= g

AN = X + D * (N - 1)

ans_set = set()
for k in range(N + 1):
    start = k * (2 * X + (k - 1) * D) // 2
    end = k * (2 * AN - (k - 1) * D) // 2
    if D:
        for r in range(start, end + D, D):
            ans_set.add(r)
    else:
        ans_set.add(start)

print(len(ans_set))

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

AN = X + D * (N - 1)

ans_set = set()
for k in range(N + 1):
    start = k * (2 * X + (k - 1) * D) // 2
    end = k * (2 * AN - (k - 1) * D) // 2
    for r in range(start, end + D, D):
        ans_set.add(r)

print(len(ans_set))
Problem p02960 (python)

Fixed submission:
import numpy as np
from numpy.fft import fft, ifft

mod = 10 ** 9 + 7
S = input()

mat = []
for i in range(6):
    w = np.zeros(13)
    for j in range(10):
        w[(10 ** i * j) % 13] += 1
    mat.append(fft(w))

ress = [[(10 ** i * j) % 13 for j in range(10)] for i in range(6)]


state = np.zeros(13)
state[0] = 1
state = fft(state)

keta = 0
res = 5
for s in reversed(S):
    if s == "?":
        state = state * mat[keta]
    else:
        res -= ress[keta][int(s)]

    if keta == 5:
        keta = 0
        state = fft(np.remainder(np.round(np.real(ifft(state))), mod))
    else:
        keta += 1


state = ifft(state)
print(int(np.round(np.real(state[res % 13]))) % mod)

Buggy submission (verdict: Runtime Error):
ress = [[(10 ** i * j) % 13 for j in range(10)] for i in range(6)]

mod = 10 ** 9 + 7

keta = 0
res = 5
state = [1] + [0] * 12
for s in reversed(input()):
    if s == "?":
        new_state = [0] * 13
        for i in range(13):
            for r in ress[keta]:
                new_state[i] += state[(i - r) % 13]

        state = new_state
    else:
        res -= ress[keta][int(s)]

    if keta == 5:
        keta = 0
        for i in range(13):
            new_state[i] %= mod
    else:
        keta += 1


print(state[res % 13] % mod)
Problem p03132 (python)

Fixed submission:
a = [int(input()) for _ in range(int(input()))]

dp = [[0] * 5 for _ in range(len(a) + 1)]

for i, x in enumerate(a):
    y = x % 2 + (x == 0) * 2
    z = (x + 1) % 2
    
    dp[i+1][0] = min(dp[i][0:1]) + x
    dp[i+1][1] = min(dp[i][0:2]) + y
    dp[i+1][2] = min(dp[i][0:3]) + z
    dp[i+1][3] = min(dp[i][0:4]) + y
    dp[i+1][4] = min(dp[i][0:5]) + x

print(min(dp[-1]))

Buggy submission (verdict: Runtime Error):
dp = [[0] * 5 for _ in range(len(a) + 1)]

for i, x in enumerate(a):
    m = x % 2
    y = m + (x == 0) * 2
    z = 1 - m
    
    dp[i+1][0] = dp[i][0] + x
    dp[i+1][1] = min(dp[i][:2]) + y
    dp[i+1][2] = min(dp[i][:3]) + z
    dp[i+1][3] = min(dp[i][:4]) + y
    dp[i+1][4] = min(dp[i]) + x

print(min(dp[-1]))
Problem p03238 (python)

Fixed submission:
if input() == '1':
    print('Hello World')
    exit()
print(int(input())+int(input()))

Buggy submission (verdict: Runtime Error):
from math import ceil
n, m = map(int, input().split())
for i in range(n, ceil(m**.5), 1):
    if not m % i:
        print(m//i)
        break
for i in range(int(min((m / n), m**.5)), 0, -1):
    if not m % i:
        print(i)
        break
Problem p03240 (python)

Fixed submission:
def ni(): 
    return int(input())
def li():
    return map(int, input().split())

xyh = [tuple(li()) for _ in range(ni())]
xmax, ymax, hmax = max(xyh, key=lambda _: _[-1])

for x_cent in range(101):
    for y_cent in range(101):
        h_cent = hmax + abs(xmax-x_cent) + abs(ymax-y_cent)
        
        for x, y, h in xyh:
            if h != max(0, h_cent - abs(x-x_cent) - abs(y-y_cent)):
                break
        else:
            print(x_cent, y_cent, h_cent)

Buggy submission (verdict: Runtime Error):
import numpy as np
def kouho(x, y, h):
    if h:
        return np.abs(np.arange(101) - x)[:, np.newaxis]  + np.abs(np.arange(101) - y) [np.newaxis] + h

n = int(input())
arrs = []
arrs0 = [np.ones((101, 101), dtype=np.int)*1000000000]
for _ in range(n):
  x, y, h = map(int, input().split())
  if h:
    arrs.append(kouho(x, y, h))
  else:
    arr0.append(kouho(x, y, h))
    
arrs = np.array(arrs)
arrs0 = np.array(arrs0)
for i in range(101):
  for j in range(101):
    if np.all(arrs[:,i,j]==arrs[0,i,j]) and (arrs[0,i,j] <= arrs0[:,i,j].min()):
      print(i, j, arrs[0, i, j])
      break

Buggy submission (verdict: Runtime Error):
import numpy as np
def kouho(x, y, h):
    if h:
        return np.abs(np.arange(101) - x)[:, np.newaxis]  + np.abs(np.arange(101) - y) [np.newaxis] + h

n = int(input())
arrs = []
for _ in range(n):
    arrs.append(kouho(*(map(int, input().split()))))
arrs = np.array(arrs)
for i in range(101):
  for j in range(101):
    if np.all(arrs[:,i,j]==arrs[0,i,j]):
      print(i, j, arrs[0, i, j])
      break

Buggy submission (verdict: Runtime Error):
import numpy as np
def kouho(x, y, h):
    if h:
        return np.abs(np.arange(101) - x)[:, np.newaxis]  + np.abs(np.arange(101) - y) [np.newaxis] + h

n = int(input())
arrs = []
for _ in range(n):
    arrs.append(kouho(*(map(int, input().split()))))
arrs = np.array(arrs)
v = arrs.var(0)
m = arrs.mean(0)
for i in range(101):
  for j in range(101):
    if v[i, j]==0:
      print(i, j, int(m[i, j]))
      break