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

Fixed submission:
N = int(input())
import sys
sys.setrecursionlimit(N+10)

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

"""
相手の取れるマス目を減らすようにとるとよい
相手よりそのマスに近ければそのマスを取得できる
フェネックくん、すぬけ君について初期地点からそれぞれへの距離が必要
"""
def solve(now, depth, depth_list, es, visited):
    visited[now] = True
    depth_list[now] = depth
    for next in es[now]:
        if visited[next] == False:            
            solve(next, depth+1, depth_list, es, visited)

depth_list_F = [0] * N
visited_F = [False] * N
solve(0, 0, depth_list_F, es, visited_F)

depth_list_S = [0] * N
visited_S = [False] * N
solve(N-1, 0, depth_list_S, es, visited_S)

cnt_F = cnt_S = 0
for f,s in zip(depth_list_F, depth_list_S):
    if f <= s:
        cnt_F += 1 # フェネック君から始めるので同じ距離ならフェネック君がとる
    else:
        cnt_S += 1

if cnt_F > cnt_S:
    print("Fennec")
else:
    print("Snuke")

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

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

"""
相手の取れるマス目を減らすようにとるとよい
相手よりそのマスに近ければそのマスを取得できる
フェネックくん、すぬけ君について初期地点からそれぞれへの距離が必要
"""
def solve(now, depth, depth_list, es, visited):
    visited[now] = True
    depth_list[now] = depth
    for next in es[now]:
        if visited[next] == False:            
            solve(next, depth+1, depth_list, es, visited)

depth_list_F = [0] * N
visited_F = [False] * N
solve(0, 0, depth_list_F, es, visited_F)

depth_list_S = [0] * N
visited_S = [False] * N
solve(N-1, 0, depth_list_S, es, visited_S)

cnt_F = cnt_S = 0
for f,s in zip(depth_list_F, depth_list_S):
    if f <= s:
        cnt_F += 1 # フェネック君から始めるので同じ距離ならフェネック君がとる
    else:
        cnt_S += 1

if cnt_F > cnt_S:
    print("Fennec")
else:
    print("Snuke")
Problem p03662 (python)

Fixed submission:
N = int(input())
import sys

sys.setrecursionlimit(N+10)
ab = [[] for _ in range(N)]

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

dF = [0] * N
dS = [0] * N
def dfs(now, d, dlist, visited):
    
    if visited[now] == False:
        dlist[now] = d
        visited[now] = True

        for next in ab[now]:
            dfs(next, d+1, dlist, visited)


vF = [False] * N
dfs(0,0,dF, vF)
vS = [False] * N
dfs(N-1, 0, dS, vS)

cnt_F = 0
cnt_S = 0
for i in range(N):
    if dF[i] <= dS[i]:
        cnt_F += 1
    else:
        cnt_S += 1

#print(dF, dS)
if cnt_F > cnt_S:
    print("Fennec")
else:
    print("Snuke")

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

ab = [[] for _ in range(N)]

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

dF = [0] * N
dS = [0] * N
def dfs(now, d, dlist, visited):
    
    if visited[now] == False:
        dlist[now] = d
        visited[now] = True

        for next in ab[now]:
            dfs(next, d+1, dlist, visited)


vF = [False] * N
dfs(0,0,dF, vF)
vS = [False] * N
dfs(N-1, 0, dS, vS)

cnt_F = 0
cnt_S = 0
for i in range(N):
    if dF[i] <= dS[i]:
        cnt_F += 1
    else:
        cnt_S += 1

#print(dF, dS)
if cnt_F > cnt_S:
    print("Fennec")
else:
    print("Snuke")
Problem p03680 (python)

Fixed submission:
n = int(input())
arr = []
passed = []
for i in range(n):
  a = int(input())
  arr.append(a)
  
next_position = 1
ans = 0

while(1):
  next_position = arr[next_position-1]
  #print(position)
  if ans == n:
    print(-1)
    break
  #passed.append(next_position)
  ans += 1
  if next_position == 2:
    print(ans)
    break

Buggy submission (verdict: Runtime Error):
n = int(input())
arr = []
passed = []
for i in range(n):
  a = int(input())
  arr.append(a)
  
next_position = 1
ans = 0

while(1):
  next_position = arr[next_position-1]
  #print(position)
  if ans == n
    print(-1)
    break
  #passed.append(next_position)
  ans += 1
  if next_position == 2:
    print(ans)
    break
Problem p03722 (python)

Fixed submission:
INF = float("inf")
n, m = map(int, input().split())
edges = [None] * m

# n:node num
# e:edges
# s:start node

d = [INF] * n
d[0] = 0
def Bellmanford(n, e, s):

    # 経路は最大でもN-1回移動すると終わるので（閉路がない限り）その分だけ更新
    for i in range(n):
        # すべての辺についてみていく
        for a,b,c in e:
            # aにたどり着ける（コストがINFではない）かつ、今のところのbまでのコストがa->bで行くときより大きい場合、更新
            if d[a] != INF and d[a] + c < d[b]:
                d[b] = d[a] + c

                # N回目更新した際に、それでも最終地点Nまでのコストが更新されたー＞負の閉路がある
                if i == n-1 and b == n-1:
                    return INF


    return -1 * d[-1]



for i in range(m):
    A, B, C = map(int, input().split())
    edges[i] = (A-1, B-1, -C)

ans = Bellmanford(n, edges, 0)
print(ans)

Buggy submission (verdict: Runtime Error):
import sys

sys.setrecursionlimit(10**9)

n,m = map(int, (input().split()))


checked= {}
graph = {}
for i in range(m):
    a,b,c = map(int, input().split())

    if a in graph:
        graph[a].append((b,c))
    else:
        graph[a] = []
        graph[a].append((b,c))

ans = -1*float("inf")
def solve(node, current_score):
    global ans
    if node == n:
        if n in graph:
            for tmp in graph[n]:
                if tmp[0] == 1:
                    flag = True
            if not flag:
                if ans < current_score:
                    ans = current_score 
            else:
                print("inf")
                exit()
        else:
            if ans < current_score:
                ans = current_score 

    if node in graph:
        for g in graph[node]:
            solve(g[0], current_score + g[1])


solve(1,0)
print(ans)

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


checked= {}
graph = {}
for i in range(m):
    a,b,c = map(int, input().split())

    if a in graph:
        graph[a].append((b,c))
    else:
        graph[a] = []
        graph[a].append((b,c))

ans = -1*float("inf")
def solve(node, current_score):
    global ans
    if node == n:
        if n in graph:
            for tmp in graph[n]:
                if tmp[0] == 1:
                    flag = True
            if not flag:
                if ans < current_score:
                    ans = current_score 
            else:
                print("inf")
                exit()
        else:
            if ans < current_score:
                ans = current_score 

    if node in graph:
        for g in graph[node]:
            solve(g[0], current_score + g[1])


solve(1,0)
print(ans)
Problem p03760 (python)

Fixed submission:
o = list(input())
e = list(input())

ans = []
for i in range(len(o)):
  ans.append(o[i])
  if i < len(o)-1:
    ans.append(e[i])
  else:
    if len(e) == len(o):
      ans.append(e[i])
    
print("".join(ans))

Buggy submission (verdict: Runtime Error):
o = list(input())
e = list(input())

ans = []
for i in range(len(o)):
  ans.append(o[i])
  if e[i]:
    ans.append(e[i])
    
print("".join(ans))
Problem p03828 (python)

Fixed submission:
def getPrimeFactorsList(num):
  pn = 2 #素数は2から
  pflist = [] #素因数のリスト
  while pn * pn <= num: #√numまで調べる
    while num % pn == 0: #現在の素数で割り切れる範囲でループ
      num = num / pn
      pflist.append(pn)
    pn += 1 #割り切れなくなったら次の素数へ
  if num > 1:
    pflist.append(int(num))
  return pflist

mod = (10 ** 9 + 7)
N = int(input())
ans = 0


pf_dict = {}
#素因数がキー、割れる回数を値として用意し、最後に約数の個数を求める
for i in range(2, N+1):

  pflist = getPrimeFactorsList(i)
  pfset = set(pflist)
  for j in pfset:
    if j in pf_dict:
      pf_dict[j] += pflist.count(j)
    else:
      pf_dict[j] = pflist.count(j)
    #count *= (pflist.count(j) + 1)
  
count = 1
for v in pf_dict.values():
  count *= (v + 1)
print(count % mod)

Buggy submission (verdict: Runtime Error):
import math

def getPrimeFactorsList(num):
  pn = 2 #素数は2から
  pflist = [] #素因数のリスト
  while pn * pn <= num: #√numまで調べる
    while num % pn == 0: #現在の素数で割り切れる範囲でループ
      num = num / pn
      pflist.append(pn)
    pn += 1 #割り切れなくなったら次の素数へ
  if num > 1:
    pflist.append(int(num))
    
  return pflist

N = int(input())
pflist = getPrimeFactorsList(math.factorial(N))
pfset = set(pflist)
ans  = 1
for i in pfset:
  ans *= (pflist.count(i) + 1)
  #print(i)
  #print(pflist.count(i))
  
  
#print(pflist)
print(ans)
Problem p03846 (python)

Fixed submission:
import math
N = int(input())


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

A.sort()
ans = 0
flag = True
if N % 2 == 1:
  # 0,2,2,4,4,～みたいに並んでるはず
  if A[0] == 0:
    for i in range(1,N,2):
      if A[i] != i+1 or A[i+1] != i+1:
        flag = False
        break
  
    if flag: ans = 2**(N//2) % (10**9 + 7)

else:
  if A[0] != 0:
    for i in range(0,N,2):
      if A[i] != i+1 or A[i+1] != i+1:
        flag = False
        break
  
    if flag: ans = 2**(N//2) % (10**9 + 7)
    
    
    
print(ans)

Buggy submission (verdict: Runtime Error):
import sys
n = int(input())
a = list(map(int, input().split()))
ans = 0
flag = 0
if n % 2 == 1:
  if a.count(0) != 1: flag = 1
  else:
    sa = n-1
    while sa > 0:
      if a.count(sa) != 2:
        print(0)
        sys.exit()
      sa -= 2
else:
  if a.count(0) != 0: flag = 1
  else:
    sa = n-1
    while sa > 0:
      if a.count(sa) != 2:
        print(0
        sys.exit()
      sa -= 2

if flag == 0:
  print(2 ** (n // 2))
else:
  print(0)
Problem p03964 (python)

Fixed submission:
import math
from fractions import Fraction
n = int(input())

pt = [0] * n
pa = [0] * n

for i in range(n):
  t, a = map(int, input().split())
  if i == 0:
    pt[0] = t
    pa[0] = a
  else:
    tmp = math.ceil(max(Fraction(pt[i-1], t), Fraction(pa[i-1], a)))
    pt[i]=tmp*t
    pa[i]=tmp*a

print(int(pt[-1] + pa[-1]))

Buggy submission (verdict: Runtime Error):
import math
n = int(input())

pt = [0] * n
pa = [0] * n

for i in range(n):
  t, a = map(int, input().split())
  if i == 0:
    pt[0] = t
    pa[0] = a
  else:
    tmp = math.ceil(max(pt[i-1]/, pa[i-1]/a))
    pt[i]=tmp*t
    pa[i]=tmp*a

print(int(pt[-1] + pa[-1]))

Buggy submission (verdict: Runtime Error):
import math
n = int(input())

pt = [0] * n
pa = [0] * n

for i in range(n):
  t, a = map(int, input().split())
  if i == 0:
    pt[0] = t
    pa[0] = a
  else:
    tmp = math.ceil(max(pt[i-1]/t*, pa[i-1]/a))
    pt[i]=tmp*t
    pa[i]=tmp*a

print(int(pt[-1] + pa[-1]))

Buggy submission (verdict: Runtime Error):
import math
n = int(input())

pt = [0] * n
pa = [0] * n

for i in range(n):
  t, a = map(int, input().split())
  if i == 0:
    pt[0] = t
    pa[0] = a
  else:
    tmp = math.ceil(max([pt[i-1]/t*1.0, pa[i-1]a*1.0]))
    pt[i]=tmp*t
    pa[i]=tmp*a

print(int(pt[-1] + pa[-1]))
Problem p03999 (python)

Fixed submission:
S = input()

ans = 0
def dfs(num_string, p):

  global ans
  
  if len(S) == 1:
    ans = int(S)
    return
  
  if p > len(S) - 1:
    #終わり
    ans += eval(num_string)
    return 
  
  #先頭の数字だけ扱いが微妙
  if p == 0:
    num_string  = "" + S[0]
    p = 1
  
  tmp = 0
  
  dfs(num_string + "+" + S[p], p+1)
  dfs(num_string + S[p], p+1)
  
  return

dfs(0,0)
print(ans)

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

ans = 0
def dfs(num_string, p):
  global ans
  if p > len(S) - 1:
    #終わり
    ans += eval(num_string)
    return 
  
  #先頭の数字だけ扱いが微妙
  if p == 0:
    num_string  = "" + S[0]
    p = 1
  
  tmp = 0
  
  dfs(num_string + "+" + S[p], p+1)
  dfs(num_string + S[p], p+1)
  
  return

dfs(0,0)
print(ans)
Problem p04013 (python)

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

max_num = max(x)
max_num = max(A, max_num)
# x_jまでからk枚選んで合計がｓになる選び方の総数。ｓはk*Aにすれば平均がAになる
dp = [[[0 for _ in range(max_num * N + 1)] for _ in range(N + 1)] for _ in range(N + 1)]
#何も選ばないで平均が０
dp[0][0][0] = 1

for j in range(N+1):
  for k in range(j+1):
    for s in range(max_num * k + 1):
      if j >= 1 and s < x[j - 1]:
        # j番目を選んでk+1個を選んだ際に平均がAにならない場合
        dp[j][k][s] = dp[j - 1][k][s]
      elif j >= 1 and k >= 1 and s >= x[j - 1]:
        # j番目をえらんでk+1個選んで平均がAになるものがあるなら、j-1番までの合計はs-x_j-1なので、その数を足している
        dp[j][k][s] = dp[j - 1][k][s] + dp[j - 1][k - 1][s - x[j - 1]]
 

ans = 0
# 合計がkAになるものを加算
for k in range(1, N + 1):
  ans += dp[N][k][k*A]
print(ans)

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

x = list(map(int, input().split()))

tmp_max = max(x)
tmp_max = max(tmp_max, A)

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

for j in range(N + 1):
  for k in range(j + 1):
    for s in range(tmp_max * k + 1):
      if j >= 1 and s < x[j - 1]:
        dp[j][k][s] = dp[j - 1][k][s]
      elif j >= 1 and k >= 1 and s >= x[j - 1]:
        dp[j][k][s] = dp[j - 1][k][s] + dp[j - 1][k - 1][s - x[j - 1]]
        
        
ans = 0
for k in range(1, N + 1):
  ans += dp[N][k][k * A]
  
print(ans)

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

x = list(map(int, input().split()))

tmp_max = max(x)
tmp_max = max(tmp_max, A)

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

for j in range(N + 1):
  for k in range(j + 1):
    for s in range(tmp_max * K + 1):
      if j >= 1 and s < x[j - 1]:
        dp[j][k][s] = dp[j - 1][k][s]
      elif j >= 1 and k >= 1 and s >= x[j - 1]:
        dp[j][k][s] = dp[j - 1][k][s] + dp[j - 1][k - 1][s - x[j - 1]]
        
        
ans = 0
for k in range(1, N + 1):
  ans += dp[N][k][k * A]
  
print(ans)

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

x = list(map(int, input().split()))

tmp_max = max(x)
tmp_max = max(tmp_max, A)

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

for j in range(n + 1):
  for k in range(j + 1):
    for s in range(tmp_max * K + 1):
      if j >= 1 and s < x[j - 1]:
        dp[j][k][s] = dp[j - 1][k][s]
      elif j >= 1 and k >= 1 and s >= x[j - 1]:
        dp[j][k][s] = dp[j - 1][k][s] + dp[j - 1][k - 1][s - x[j - 1]]
        
        
ans = 0
for k in range(1, n + 1):
  ans += dp[N][k][k * A]
  
print(ans)
Problem p02900 (python)

Fixed submission:
import fractions

def factorization(n):
    arr = []
    temp = n
    for i in range(2, int(-(-n**0.5//1))+1):
        if temp%i==0:
            cnt=0
            while temp%i==0:
                cnt+=1
                temp //= i
            arr.append([i, cnt])

    if temp!=1:
        arr.append([temp, 1])

    if arr==[]:
        arr.append([n, 1])

    return arr

A, B = list(map(int, input().split(' ')))
maxKouyaku = fractions.gcd(A, B)
#print(maxKouyaku)
#print(*factorization(maxKouyaku))
if maxKouyaku == 1:
    print(1)
else:
    print(len(factorization(maxKouyaku)) + 1)

Buggy submission (verdict: Runtime Error):
import math

def factorization(n):
    arr = []
    temp = n
    for i in range(2, int(-(-n**0.5//1))+1):
        if temp%i==0:
            cnt=0
            while temp%i==0:
                cnt+=1
                temp //= i
            arr.append([i, cnt])

    if temp!=1:
        arr.append([temp, 1])

    if arr==[]:
        arr.append([n, 1])

    return arr

A, B = list(map(int, input().split(' ')))
maxKouyaku = math.gcd(A, B)
#print(maxKouyaku)
if maxKouyaku == 1:
    print(1)
else:
    print(len(factorization(maxKouyaku)) + 1)
Problem p02918 (python)

Fixed submission:
N, K = list(map(int, input().split(' ')))
S = list(input())

def change():
    check = S[0]
    k = 1
    while S[k] == check:
        k += 1
    i = 0
    while S[k + i] != check:
        S[k + i] = check
        i += 1

group = 1
old = S[0]
happy_num = 0
for i in range(1, N):
    if old == S[i]:
        group += 1
        if i == N - 1:
            happy_num += group - 1
    else:
        happy_num += group - 1
        old = S[i]
        group = 1
#print(happy_num)


old = S[0]
border = 0
for i in range(1, N):
    if old != S[i]:
        border += 1
        old = S[i]
#print(border)

changed = 2 * K
if changed < border:
    print(happy_num + 2 * K)
else:
    print(N - 1)

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

def change():
    check = S[0]
    k = 1
    while S[k] == check:
        k += 1
    i = 0
    while S[k + i] != check:
        S[k + i] = check
        i += 1

group = 1
old = S[0]
happy_num = 0
for i in range(1, N):
    if old == S[i]:
        group += 1
        if i == N - 1:
            happy_num += group - 1
    else:
        happy_num += group - 1
        old = S[i]
        group = 1
print(happy_num)

border = 0
for k in range(K):
    old = S[0]
    for i in range(1, N):
        if old != S[i]:
            border += 1
            if border == 2:
                break
            old = S[i]
    if border == 0:
        break
    elif border == 1:
        happy_num += 1
        S[1:] = S[0]
    else:
        happy_num += 2
        change()

print(happy_num)
Problem p03059 (python)

Fixed submission:
A, B, T = input().split(' ')
A = int(A)
B = int(B)
T = int(T)
print(int(T / A) * B)

Buggy submission (verdict: Runtime Error):
A, B, T = input.split(' ')
print(T / A * B)
Problem p03846 (python)

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

false_flag = 0
'''
if N % 2 == 0:
    count_ = 1
else:
    if A.count(0) != 1:
        false_flag = 1
    count_ = 2
while count_ < N and false_flag == 0:
    if A.count(count_) != 2:
        false_flag = 1
    count_ += 2
'''

count_list = [0 for i in range(N)]
for index in A:
    count_list[index] += 1

if N % 2 == 0:
    count_ = 1
    diff = -1
else:
    if count_list[0] != 1:
        false_flag = 1
    count_ = 2
    diff = -1
while count_ < N and false_flag == 0:
    #print(count_)
    if count_list[count_] != 2 or count_list[count_ + diff] != 0:
        false_flag = 1
    count_ += 2

if false_flag == 0:
    print((2 ** (N // 2) ) % 1000000007)
else:
    print(0)

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

false_flag = 0
'''
if N % 2 == 0:
    count_ = 1
else:
    if A.count(0) != 1:
        false_flag = 1
    count_ = 2
while count_ < N and false_flag == 0:
    if A.count(count_) != 2:
        false_flag = 1
    count_ += 2
'''

count_list = [0 for i in range(N)]
for index in A:
    count_list[index] += 1

if N % 2 == 0:
    count_ = 1
    diff = -1
else:
    if count_list[0] != 1 or count_list[1] != 0:
        false_flag = 1
    count_ = 2
    diff = 1
while count_ < N and false_flag == 0:
    if count_list[count_] != 2 or count_list[count_ + diff] != 0:
        false_flag = 1
    count_ += 2

if false_flag == 0:
    print(2 ** (N // 2))
else:
    print(0)
Problem p02727 (python)

Fixed submission:
x, y, a, b, c = map(int, input().split())
P = sorted(list(map(int, input().split())), reverse=True)
Q = sorted(list(map(int, input().split())), reverse=True)
R = sorted(list(map(int, input().split())))

A = sorted(P[:x] + Q[:y])
ans = sum(A)

for i in range(min(c, len(A))):
    if A[i] < R[-1]:
        ans = ans + R[-1] - A[i]
        R.pop(-1)

print(ans)

Buggy submission (verdict: Runtime Error):
x, y, a, b, c = map(int, input().split())
P = sorted(list(map(int, input().split())), reverse=True)
Q = sorted(list(map(int, input().split())), reverse=True)
R = sorted(list(map(int, input().split())))

A = sorted(P[:x] + Q[:y])
ans = sum(A)

for i in range(c):
    if A[i] < R[-1]:
        ans = ans + R[-1] - A[i]
        R.pop(-1)

print(ans)
Problem p02756 (python)

Fixed submission:
s = input()
q = int(input())

rev = False

forward = ''
back = ''

for i in range(q):
    tfc = input()
    if len(tfc) == 1:
        if rev:
            rev = False
        else:
            rev = True
    else:
        t, f, c = tfc.split()
        if f == '1':
            if rev:
                back += c
            else:
                forward += c
        else:
            if rev:
                forward += c
            else:
                back += c

s = forward[::-1] + s + back
if rev:
    s = s[::-1]

print(s)

Buggy submission (verdict: Runtime Error):
for i in range(q):
    tfc = input()
    if len(tfc) == 1:
        if rev:
            rev = False
        else:
            rev = True
    else:
        t, f, c = tfc.split()
        if f == '1':
            if rev:
                back += c
            else:
                forward += c
        else:
            if rev:
                forward += c
            else:
                back += c

s = forward[::-1] + s + back
if rev:
    s = s[::-1]

print(s)
Problem p02787 (python)

Fixed submission:
INF = 1000000000

h, n = map(int, input().split())
AB = [list(map(int, input().split())) for i in range(n)]

maxA = max(AB, key=lambda x: x[0])[0]

dp = [INF for i in range(h+maxA)]
dp[0] = 0

for i in range(1, h+maxA):
    dp[i] = min(dp[i-a] + b for a, b in AB)

print(min(dp[h:]))

Buggy submission (verdict: Runtime Error):
INF = 1000000000

h, n = map(int, input().split())
AB = [list(map(int, input().split())) for i in range(n)]

maxA = max(AB[:][0])

dp = [INF for i in range(h+maxA)]
dp[0] = 0

for i in range(1, h+maxA):
    dp[i] = min(dp[i-a] + b for a, b in AB)

print(min(dp[h:]))

Buggy submission (verdict: Runtime Error):
INF = 10000000

h, n = map(int, input().split())
AB = [list(map(int, input().split())) for i in range(n)]

maxA = max(AB[:][0])

dp = [INF for i in range(h+maxA)]
dp[0] = 0

for i in range(1, h+maxA):
    for j in range(n):
        a, b = AB[j][0], AB[j][1]
        dp[i] = min(dp[i], dp[i-a] + b)

ans = min(dp[h:])

print(ans)

Buggy submission (verdict: Runtime Error):
INF = 10000000

h, n = map(int, input().split())
AB = [list(map(int, input().split())) for i in range(n)]

maxA = max(AB[:][0])

dp = [INF for i in range(h+maxA)]
dp[0] = 0

for i in range(1, h+maxA):
    for j in range(n):
        a, b = AB[j][0], AB[j][1]
        dp[i] = min(dp[i], dp[i-a] + b)

ans = min(dp[h:])

print(ans)
Problem p02845 (python)

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

rgb = [0, 0, 0]
ans = 1
for a in A:
    if a not in rgb:
        print(0)
        break
    ans = (ans * rgb.count(a)) % 1000000007
    idx = rgb.index(a)
    rgb[idx] += 1
else:
    print(ans)

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

rgb = [0, 0, 0]
ans = 1
for a in A:
    ans = (ans * rgb.count(a)) % 1000000007
    idx = rgb.index(a)
    rgb[idx] += 1

print(ans)

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

rgb = [0, 0, 0]
ans = 1
for a in A:
    ans = ans * rgb.count(a) % 1000000007
    idx = rgb.index(a)
    rgb[idx] += 1

print(ans)
Problem p02866 (python)

Fixed submission:
n = int(input())
D = list(map(int, input().split()))


if D[0] != 0 or 0 in D[1:]:
    ans = 0
else:
    num = [0 for i in range(max(D)+1)]
    ans = 1
    cnt = 1
    for i in range(n):
        num[D[i]] += 1
    for i in range(len(num)):
        ans = ans * (cnt ** num[i]) % 998244353
        cnt = num[i]

print(ans)

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


if D[0] != 0 or 0 in D[1:]:
    ans = 0
else:
    num = [0 for i in range(max(D)+1)]
    ans = 1
    cnt = 1
    for i in range(n):
        num[D[i]] += 1
    for i in range(len(num)):
        ans = ans * (cnt ** num[i]) % 998244353
        cnt = num[i]

print(num)
print(ans)
Problem p02888 (python)

Fixed submission:
import bisect

n = int(input())
L = sorted(list(map(int, input().split())))

ans = 0
for i in range(n-2):
    for j in range(i+1, n-1):
        ans += bisect.bisect_left(L, L[i]+L[j]) - (j+1)

print(ans)

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

ans = 0
for i in range(n-1, 1, -1):
    for j in range(i-1, 0, -1):
        ans += j - bisect.bisect_right(L[:j], L[i]-L[j])

print(ans)