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

Fixed submission:
n,m=map(int,input().split())
probs = [False]*n
wrongs = [0]*n
for i in range(m):
    p,s=map(str,input().split())
    if probs[int(p)-1] == False:
        if s == "AC":
            probs[int(p)-1] = True
        elif s == "WA":
            wrongs[int(p)-1] += 1

ac=0
wa=0
for i,a in enumerate(probs):
    if a == True:
        ac+=1
        wa+=wrongs[i]
print(ac,wa)

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

n,m=map(int,input().split())
l=[list(input().split()) for _ in range(m)]
 
p=[0]*m
wa=0

for i in range(m):
  if l[i][1]=="AC":
    wa += p[int(l[i][0])]
    p[int(l[i][0])]= -1
  elif l[i][1]=="WA":
    if p[int(l[i][0])] != -1:
      p[int(l[i][0])] += 1
      
print(p.count(-1),wa)
Problem p02848 (python)

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

a = "ABCDEFGHIJKLMNOPQRSTUVWXYZ"
ans = ""
for i in s:
    ans += a[(int(a.index(i)) + n)%26]
print(ans)

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

a = "ABCDEFGHIJKLMNOPQRSTUVWXYZ" * 2
ans = ""
for i in s:
    ans[i] = a.index(a.index(s[i]) + n)
print(ans)
Problem p02850 (python)

Fixed submission:
import sys
sys.setrecursionlimit(10**5)
n = int(input())
ab = [list(map(int,input().split()))for _ in range(n-1)]

graph = [[] for _ in range(n+1)]
ans = [0]*(n-1)
for i in range(n-1):
    graph[ab[i][0]].append((ab[i][1],i))
    graph[ab[i][1]].append((ab[i][0],i))

visit = [False]*(n+1)
def dfs(p,c):
    color = 1
    visit[p] = True
    for n,i in graph[p]:
        if visit[n] == False:
            if color == c:
                color += 1
            ans[i] = color
            dfs(n,color)
            color += 1

dfs(1,0)
print(max(ans))
for t in ans:
    print(t)

Buggy submission (verdict: Runtime Error):
n = int(input())
ab = [list(map(int,input().split()))for _ in range(n-1)]

graph = [[] for _ in range(n+1)]
ans = [0]*(n-1)
for i in range(n-1):
    graph[ab[i][0]].append((ab[i][1],i))
    graph[ab[i][1]].append((ab[i][0],i))

visit = [False]*(n+1)
def dfs(p,c):
    color = 1
    visit[p] = True
    for n,i in graph[p]:
        if visit[n] == False:
            if color == c:
                color += 1
            ans[i] = color
            dfs(n,color)
            color += 1

dfs(1,0)
print(max(ans))
for t in ans:
    print(t)
Problem p02861 (python)

Fixed submission:
import itertools
import math
n = int(input())
xy = [list(map(int,input().split()))for _ in range(n)]

ans = 0
for i in itertools.permutations(range(n), n):
    tmp = i[0]
    for j in i:
        ans += (((xy[tmp][0]-xy[j][0])**2 + (xy[tmp][1]-xy[j][1])**2)**0.5)
        tmp = j
print(ans/math.factorial(n))

Buggy submission (verdict: Runtime Error):
import math
import itertools

n = int(input())

distans = []
tmps = []
for i in range(n):
    x,y = map(int,input().split())
    tmps.append((x - y)**2)

ans = 0
comb = list(itertools.combinations(range(int((n*(n-1))/2)),2))
for k in range(len(comb)):
    distans.append(math.sqrt(tmps[comb[k][0]] + tmps[comb[k][1]]))
    ans += distans[k] * (math.factorial(n)-n+1) 
print(ans/math.factorial(n))

Buggy submission (verdict: Runtime Error):
import math

n = int(input())

distans = []
tmps = []
for i in range n:
    x,y = map(int,input().split())
    tmps[i] = (x - y)**2

for i in range n-1:
    distans[i] = math.sqrt(tmps[i] + tmps[i+1])
    ans += distans[i] * (math.factorial(n)-1) 

print(ans/math.factorial(n))
Problem p02936 (python)

Fixed submission:
import sys
input = sys.stdin.readline
sys.setrecursionlimit(10 ** 7)

# 遅延評価で加えてあげるだけ

N,Q = map(int,input().split())
AB = [[int(x) for x in input().split()] for _ in range(N-1)]
PX = [[int(x) for x in input().split()] for _ in range(Q)]

graph = [[] for _ in range(N+1)]
for a,b in AB:
    graph[a].append(b)
    graph[b].append(a)

value = [0] * (N+1)
for p,x in PX:
    value[p] += x

def dfs(v,parent,add):
    value[v] += add
    for x in graph[v]:
        if x == parent:
            continue
        dfs(x,v,value[v])

dfs(1,0,0)

answer = ' '.join(map(str,value[1:]))
print(answer)

Buggy submission (verdict: Runtime Error):
import sys
sys.setrecursionlimit(10 ** 7)

n,q = map(int,input().split())
ab = [list(map(int,input().split()))for _ in range(n-1)]
px = [list(map(int,input().split()))for _ in range(q)]

graph = [[] for _ in range(n+3)]
for a,b in ab:
    graph[a].append(b)
    graph[b].append(a)

value = [0]*(n+1)
for p,x in px:
    value[p] += x

def dfs(v,parent,add):
    value[v] += add
    for x in graph[v]:
        if v == parent:
            continue
        dfs(x,v,value[v])

dfs(1,0,0)
print(*value[1:],end="\t")

Buggy submission (verdict: Runtime Error):
import sys
sys.setrecursionlimit(10 ** 7)

n,q = map(int,input().split())
ab = [list(map(int,input().split()))for _ in range(n-1)]
px = [list(map(int,input().split()))for _ in range(q)]

graph = [[] for _ in range(n+3)]
for a,b in ab:
    graph[a].append(b)
    graph[b].append(a)

value = [0]*(n+1)
for p,x in px:
    value[p] += x

def dfs(v,add):
    value[v] += add
    for x in graph[v]:
        dfs(x,value[v])

dfs(1,0)
print(*value[1:],end="\t")
Problem p02947 (python)

Fixed submission:
n = int(input())
s = {}
ans = 0
for i in range(n):
    tmp = str(sorted(input()))
    if tmp in s:
        ans += s[tmp]
        s[tmp] += 1
    else:
        s[tmp] = 1
print(ans)

Buggy submission (verdict: Runtime Error):
import math
n=int(input())
s=[]
ans=0
for i in range(n):
  S=''.join(sorted(input()))
  s.append(S)

for i in range(len(set(s))):
  tmp = s.count(list(set(s))[i])
  if tmp==1:
    ans+=0
  else:
    ans+=math.factorial(tmp)/math.factorial(2)*math.factorial(tmp-2)
  
print(int(ans))
Problem p02971 (python)

Fixed submission:
n=int(input())
a=[]
best_cnt=0
[a.append(int(input())) for _ in range(n)]
b = sorted(a)
if len(set(b))==1:
  best=better=b[-1]
else:
  best=list(set(b))[-1]
  better=list(set(b))[-2]
for i in range(n):
  if a[i]==best:
    best_cnt+=1
    
for i in range(n):
  if a[i] == best:
    if best_cnt==1:
      print(better)
    else:
      print(best)
  else:
    print(best)

Buggy submission (verdict: Runtime Error):
n=int(input())
a=[]
best_cnt=0
[a.append(int(input())) for _ in range(n)]
b = sorted(a)
if len(set(b))==1:
  best=better=b[-1]
else:
  best=list(set(b))[-1]
  better=list(set(b))[-2]
for i in range(n):
  if a[i]==best:
    best_cnt+=1
    
for i in range(n):
  if a[i] == best:
    if b_cnt==1:
      print(better)
    else:
      print(best)
  else:
    print(best)
Problem p03044 (python)

Fixed submission:
import sys
sys.setrecursionlimit(10 ** 7)
n=int(input())
E=[[] for _ in range(n+1)]
for _ in range(n-1):
    u,v,w=map(int,input().split())
    E[u].append((v,w))
    E[v].append((u,w))
color=[-1]*(n+1)

def dfs(i,j):
    color[i] = j
    for w,l in E[i]:
        if color[w] == -1:
            tj = j
            if l % 2 != 0:
                tj = int(not tj)
            dfs(w,tj)

dfs(1,0)
[print(color[i]) for i in range(1,n+1)]

Buggy submission (verdict: Runtime Error):
n=int(input())
E=[[] for _ in range(n+1)]
for _ in range(n-1):
    u,v,w=map(int,input().split())
    E[u].append((v,w))
    E[v].append((u,w))
color=[-1]*(n+1)

def dfs(i,j):
    color[i] = j
    for w,l in E[i]:
        if color[w] == -1:
            tj = j
            if l % 2 != 0:
                tj = int(not tj)
            dfs(w,tj)

dfs(1,0)
[print(color[i]) for i in range(1,n+1)]
Problem p03160 (python)

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

dp = [float("inf")] * n #dpテーブル
#dp[i]:=i番目の足場まで来るのに必要な最小コスト

#初期条件
dp[0]=0
dp[1]=abs(h[1]-h[0])

for i in range(2,n):
    dp[i] = min(dp[i-1] + abs(h[i-1]-h[i]) ,dp[i-2] + abs(h[i-2]-h[i]))

print(dp[n-1])

Buggy submission (verdict: Runtime Error):
import sys
sys.setrecursionlimit(10**8)

n = int(input())
h = list(map(int,input().split()))

dp = [float("inf")] * n #dpテーブル
#dp[i]メモ化テーブル

def rec(i):#再帰による全探索
    if dp[i] != float("inf"):
        return dp[i]
    if i == 0:
        return 0
    elif i == 1:
        return abs(h[0]-h[1])
    else:
        return dp[i] = min(rec(i-1)+abs(h[i]-h[i-1]),rec(i-2)+abs(h[i]-h[i-2]))

print(rec(n-1))

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

dp = [float("inf")] * n #dpテーブル
#dp[i]メモ化テーブル
#まずは使わない

def rec(i):#再帰による全探索
    if i == 0:
        return 0
    elif i == 1:
        return abs(h[0]-h[1])
    else:
        return min(rec(i-1)+abs(h[i]-h[i-1]),rec(i-2)+abs(h[i]-h[i-2]))

print(rec(n-1))

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

dp = [float("inf")] * n #dpテーブル
#dp[i]メモ化テーブル

def rec(i):
    res = float("inf")
    if i<=0:
        return 0
    return min(rec(i-1) + abs(h[i]-h[i-1]),rec(i-2) + abs(h[i]-h[i-2]))

print(rec(n-1))
Problem p03161 (python)

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

dp = [float("inf")]*n

#初期条件
dp[0] = 0

#漸化式
for i in range(1,n):
    for l in range(1,k+1):
        if i-l < 0:continue
        dp[i] = min(dp[i],dp[i-l] + abs(h[i-l]-h[i]))

print(dp[n-1])

Buggy submission (verdict: Runtime Error):
import sys
sys.setrecursionlimit(10*7)

n,k = map(int,input().split())
h = list(map(int,input().split()))

dp = [float("inf")]*n

def rec(i):#全探索+メモ化
    if dp[i] != float("inf"):
        return dp[i]
    if i <= 0:
        return 0
    else:
        for l in range(1,k+1):
            if i-l < 0:continue
            dp[i] = min(dp[i],rec(i-l) + abs(h[i]-h[i-l]))
    return dp[i]

print(rec(n-1))

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

dp = [float("inf")]*n

def rec(i):#全探索+メモ化
    if dp[i] != float("inf"):
        return dp[i]
    if i <= 0:
        return 0
    else:
        for l in range(1,k+1):
            if i-l < 0:continue
            dp[i] = min(dp[i],rec(i-l) + abs(h[i]-h[i-l]))
    return dp[i]

print(rec(n-1))
Problem p03682 (python)

Fixed submission:
#最小全域木　プリム法
from heapq import *

n=int(input())
xy=[]
for i in range(n):
    x,y=map(int,input().split())
    xy.append([x,y,i])

#今回の問題では,高々xが隣のやつとyが隣のやつを全部考えればよし
#（詳しくは解説pdfより）
x_sort = sorted(xy, key=lambda x: x[0])
y_sort = sorted(xy, key=lambda x: x[1])

cost = [[]for _ in range(n+3)] #cost[i]にはi番目から(j,k)でj番目にコストkかかる
for i in range(n-1):
    cost[x_sort[i][2]].append((x_sort[i+1][2],x_sort[i+1][0]-x_sort[i][0]))
    cost[x_sort[i+1][2]].append((x_sort[i][2],x_sort[i+1][0]-x_sort[i][0]))

    cost[y_sort[i][2]].append((y_sort[i+1][2],y_sort[i+1][1]-y_sort[i][1]))
    cost[y_sort[i+1][2]].append((y_sort[i][2],y_sort[i+1][1]-y_sort[i][1]))


used=[False]*(n+3)#頂点が最小全域木にもうすでに含まれているかどうか
q=[]
#すでに最小全域木が決まっている部分からまだ決まっていない部分への辺をヒープで管理
#(a,b)でaには向かう先の頂点,bにはかかるコスト
#ヒープで小さいコストからとりだせる

#初期条件
#はじめはどこでもよいので０番目スタートとする(0番目だけではコストは0)
used[0] = True
ans = 0

#0番目からの辺をすべてヒープに挿入
for to,cst in cost[0]:
    heappush(q,(cst,to))

#すでに決まっている最小全域木部分からまだ決まっていない部分を貪欲的にひたすら追加する
#はじめは初期条件の通り
while(len(q)!=0):
    c,ver=heappop(q)
#すでに決まっている部分から一番小さいコストの辺を取り出す
    if used[ver] == True:
        continue
#もしすでに最小全域木部分であればやり直し
#そうでなければコストの分を加算し、新しい頂点を最小全域木部分に追加する
    ans += c
    used[ver] = True
#新しく追加した頂点からの辺をヒープに追加する
    for to,cst in cost[ver]:
        heappush(q,(cst,to))
#これを貪欲的に繰り返すことでうまくいくらしい
print(ans)

Buggy submission (verdict: Runtime Error):
#最小全域木　プリム法
from heapq import *

n=int(input())
xy=[]
for i in range(n):
    x,y=map(int,input().split())
    xy.append([x,y,i])

#今回の問題では,高々xが隣のやつとyが隣のやつを全部考えればよし
#（詳しくは解説pdfより）
x_sort = sorted(xy, key=lambda x: x[0])
y_sort = sorted(xy, key=lambda x: x[1])

cost = [[]for _ in range(n+3)] #cost[i]にはi番目から(j,k)でj番目にコストkかかる
for i in range(n-1):
    cost[x_sort[i][2]].append((x_sort[i+1][2],x_sort[i+1][0]-x_sort[i][0]))
    cost[x_sort[i+1][2]].append((x_sort[i][2],x_sort[i+1][0]-x_sort[i][0]))

    cost[y_sort[i][2]].append((y_sort[i+1][2],y_sort[i+1][1]-y_sort[i][1]))
    cost[y_sort[i+1][2]].append((y_sort[i][2],y_sort[i+1][1]-y_sort[i][1]))


used=[False]*(n+3)#頂点が最小全域木にもうすでに含まれているかどうか
q=[]
#すでに最小全域木が決まっている部分からまだ決まっていない部分への辺をヒープで管理
#(a,b)でaには向かう先の頂点,bにはかかるコスト
#ヒープで小さいコストからとりだせる

#初期条件
#はじめはどこでもよいので０番目スタートとする(0番目だけではコストは0)
used[0] = True
ans = 0

#0番目からの辺をすべてヒープに挿入
for to,cst in cost[0]:
    heappush(q,(cst,to))

#すでに決まっている最小全域木部分からまだ決まっていない部分を貪欲的にひたすら追加する
#はじめは初期条件の通り
while(len(q)!=0):
    c,ver=heappop(q)
  #すでに決まっている部分から一番小さいコストの辺を取り出す
    if used[ver] == True:
        continue
  #もしすでに最小全域木部分であればやり直し
  #そうでなければコストの分を加算し、新しい頂点を最小全域木部分に追加する
    ans += c
    used[ver] = True
  #新しく追加した頂点からの辺をヒープに追加する
    for to,cst in cost[ver]:
        heappush(q,(cst,to))
　#これを貪欲的に繰り返すことでうまくいくらしい
print(ans)
Problem p04001 (python)

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

#左から順番に文字を結合していき+を入れるパターンと入れないパターンについて同様に文字を結合させていく
def dfs(i,f):
    if i == n-1:#すべての文字を使いきったらそのときの計算をする
        return sum(list(map(int,f.split("+"))))
    return dfs(i+1,f+s[i+1]) + dfs(i+1,f+"+"+s[i+1])#+を入れない場合、+をいれる場合
    
print(dfs(0,s[0]))

Buggy submission (verdict: Runtime Error):
s = input()
n = len(s)

#左から順番に文字を結合していき+を入れるパターンと入れないパターンについて同様に文字を結合させていく
def dfs(i,f):
    if i == n-1:#すべての文字を使いきったらそのときの計算をする
        return sum(list(map(int,f.split("+"))))
    return dfs(i+1,f+s[i+1]) + dfs(i+2,f+"+"+s[i+1])#+を入れない場合、+をいれる場合
    
print(dfs(0,s[0]))

Buggy submission (verdict: Runtime Error):
s = input()
n = len(s)

#左から順番に文字を結合していき+を入れるパターンと入れないパターンについて同様に文字を結合させていく
def dfs(i,f):
    if i == n-1:#すべての文字を使いきったらそのときの計算をする
        return sum(list(map(int,f.split("+"))))
    return dfs(i+1,f+s[i+1]) + dfs(i+2,f+"+"+s[i+1])#+を入れない場合、+をいれる場合
    
print(dfs(0,s[0])
Problem p02641 (python)

Fixed submission:
x,n = map(int,input().split())
if n==0: exit(print(x))
p = list(map(int,input().split()))
p.sort()
if x not in p: exit(print(x))
h=101
l=0
for i in range(x,101):
    if i not in p:
        h = i
        break
for i in range(x,0,-1):
    if i not in p:
        l = i
        break
if abs(x-h)>=abs(x-l): print(l)
if abs(x-l)>abs(x-h): print(h)

Buggy submission (verdict: Runtime Error):
x,n = map(int,input().split())
if n==0: exit(print(x))
p = list(map(int,input().split()))
p.sort()
if x not in p: exit(print(x))
for i in range(x,101):
    if i not in p:
        h = i
        break
for i in range(x,0,-1):
    if i not in p:
        l = i
        break
if abs(x-h)>=abs(x-l): print(l)
if abs(x-l)>abs(x-h): print(h)
Problem p02761 (python)

Fixed submission:
n,m = map(int,input().split())
t='000'
if n==2: t='010'
if n==3: t='100'
f=[0]*len(t)
t=[int(t[0]),int(t[1]),int(t[2])]
ans = t[0]*100+t[1]*10+t[2] 
for i in range(m):
    ans = -1
    s,c = map(int,input().split())
    s=s-(n-2)
    if c <  t[s]: break
    if c >  t[s]:
        if f[s]==0:
            f[s],t[s]=1,c
        elif f[s]==1:
            break
    ans=t[0]*100+t[1]*10+t[2]
print(ans)

Buggy submission (verdict: Runtime Error):
n,m = map(int,input().split())
t='000'
if n==2: t='010'
if n==3: t='100'
f=[0]*len(t)
t=[int(t[0]),int(t[1]),int(t[2])]
for i in range(m):
    ans = -1
    s,c = map(int,input().split())
    s=s-(n-2)
    if c <  t[s]: break
    if c >  t[s]:
        if f[s]==0:
            f[s],t[s]=1,c
        elif f[s]==1:
            break
    ans=t[0]*100+t[1]*10+t[2]
print(ans)
print(f)

Buggy submission (verdict: Runtime Error):
n,m = map(int,input().split())
t='000'
if n==2: t='010'
if n==3: t='100'
f=[0]*len(t)
t=[int(t[0]),int(t[1]),int(t[2])]
for i in range(m):
    ans = -1
    s,c = map(int,input().split())
    s=s-(n-2)
    if c <  t[s]: break
    if c >  t[s]:
        if f[s]==0:
            f[s],t[s]=1,c
        elif f[s]==1:
            break
    ans=t[0]*100+t[1]*10+t[2]
print(ans)

Buggy submission (verdict: Runtime Error):
n,m = map(int,input().split())
t=0
if n==2: t=10
if n==3: t=100
t=str(t)
tt = list()
for i in range(n):
    tt.append(int(t[i]))
f=[0]*len(tt)
for i in range(m):
    ans = -1
    s,c = map(int,input().split())
    s-=1
    if c <  tt[s]: break
    if c >  tt[s]:
        if f[s]==0:
            f[s],tt[s]=1,c
        elif f[s]==1:
            break
    if n==1: ans=tt[0]
    if n==2: ans=tt[0]*10+tt[1]
    if n==3: ans=tt[0]*100+tt[1]*10+tt[2]

print(ans)

Buggy submission (verdict: Runtime Error):
n,m = map(int,input().split())
t=0
if n==2: t=10
if n==3: t=100
t=str(t)
t=[int(t[0]),int(t[1]),int(t[2])]
f=[0]*len(t)
for i in range(m):
    ans = -1
    s,c = map(int,input().split())
    s-=1
    if c <  t[s]: break
    if c >  t[s]:
        if f[s]==0:
            f[s],t[s]=1,c
        elif f[s]==1:
            break
    ans=t[0]*100+t[1]*10+t[2]
print(ans)
Problem p02802 (python)

Fixed submission:
n,m = map(int,input().split())
ac = [0]*n
wa = [0]*n
for i in range(m):
    p,s = input().split()
    p = int(p)
    if ac[p-1]:
        continue
    if s == 'AC':
        ac[p-1] = 1
    else:
        wa[p-1] += 1
count_ac = 0
count_wa = 0
for i in range(n):
    count_ac += ac[i]
    if ac[i]:
        count_wa += wa[i]
print(str(count_ac) + " " + str(count_wa))

Buggy submission (verdict: Runtime Error):
n,m = map(int,input().split())
ac = [0]*m
wa = [0]*m
for i in range(m):
    p,s = input().split()
    p = int(p)
    if ac[p-1]:
        continue
    if s == 'AC':
        ac[p-1] = 1
    else:
        wa[p-1] += 1
count_ac = 0
count_wa = 0
for i in range(n):
    count_ac += ac[i]
    if ac[i]:
        count_wa += wa[i]
print(str(count_ac) + " " + str(count_wa))
Problem p02995 (python)

Fixed submission:
# 21:15
import fractions as math

a,b,c,d = map(int,input().split())

def F(n,c,d):
    x = n
    x -= n//c
    x -= n//d
    lcm = c*d//math.gcd(c,d)
    x += n//lcm
    return x

print(F(b,c,d) - F(a-1,c,d))

Buggy submission (verdict: Runtime Error):
# 21:15
import math as math

a,b,c,d = map(int,input().split())

def F(n,c,d):
    x = n
    x -= n//c
    x -= n//d
    lcm = c*d//math.gcd(c,d)
    x += n//lcm
    return x

print(F(b,c,d) - F(a-1,c,d))

Buggy submission (verdict: Runtime Error):
# 21:15
import math as math

a,b,c,d = map(int,input().split())

def F(n,c,d):
    x = n
    x -= n//c
    x -= n//d
    lcm = c*d//math.gcd(c,d)
    x += n//lcm
    return x

print(F(b,c,d) - F(a-1,c,d))

Buggy submission (verdict: Runtime Error):
# 21:15
import math

a,b,c,d = map(int,input().split())

def F(n,c,d):
    x = n
    x -= n//c
    x -= n//d
    lcm = c*d//math.gcd(c,d)
    x += n//lcm
    return x

print(F(b,c,d) - F(a-1,c,d))
Problem p03699 (python)

Fixed submission:
N = int(input())

nums = []
max = 0

for i in range(0, N):
    nums.append(int(input()))

mx = sum(nums)
if mx % 10 != 0:
    print(str(mx))
    quit()

checker = [False for i in range(0, mx+1)]

now = 0
res = 0
for i in range(0, N):
    v = nums[i]
    for j in range(now, -1, -1):
        if checker[j]:
            idx = j + v
            if idx > res and idx % 10 != 0:
                res = idx
            checker[idx] = True
    checker[v] = True
    now = now + v

print(str(res))

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

nums = []
max = 0

for i in range(0, N):
    nums.append(int(input()))

mx = sum(nums)
checker = [0 for i in range(0, mx)]

now = 0
res = 0
for i in range(0, N):
    v = nums[i]
    for j in range(now - 1, -1, -1):
        if checker[j] == 1:
            idx = checker[j] + v
            if idx > res and idx % 10 != 0:
                res = idx
            checker[idx] = 1
            checker[j] = 0
    checker[v] = 1
    now = now + v


print(str(res))
Problem p03773 (python)

Fixed submission:
N, S = list(map(int, input().split()))
s = N + S
if s >= 24:
    s = s - 24
print(str(s))

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

a = []
c = []
for i in range(0, N + M):
    s = list(map(int, input().split()))
    if  i < N:
        a.append(s)
    else:
        c.append(s)

for i in range(0, N):
    min_idx = 0
    min_dis = 999999999999
    for j in range(0, M):
        dis = abs(a[i][0] - c[j][0]) + abs(a[i][1] - c[j][1])
        if min_dis > dis:
            min_dis = dis
            min_idx = j + 1
    print(str(min_idx))
Problem p03779 (python)

Fixed submission:
N = int(input())
 
for i in range(1, N + 1):
    if N <= (i * (i + 1) / 2):
        print (str(i))
        break

Buggy submission (verdict: Runtime Error):
# -*- coding: utf-8 -*-
def check(t, n, idx):
    if t == n + idx or t == n - idx:
        return idx
    if idx >= t and t > 0:
        return t
    elif t < 0 and idx * -1 <= t:
        return idx
    return min(check(t, n + idx, idx + 1), check(t, n - idx, idx + 1), check(t, n, idx + 1))

X = int(input())
print(check(X, 0, 1))

Buggy submission (verdict: Runtime Error):
# -*- coding: utf-8 -*-
def check(t, n, idx):
    if t == n + idx or t == n - idx:
        return idx
    if idx >= t:
        return t
    return min(check(t, n + idx, idx + 1), check(t, n - idx, idx + 1), check(t, n, idx + 1))

X = int(raw_input())
print(check(X, 0, 1))

Buggy submission (verdict: Runtime Error):
# -*- coding: utf-8 -*-
def check(t, now, idx):
    if t < idx:
        return 99999999999
    # use
    use = 999999999999
    if t == now + idx:
        use = idx
    elif t > now + idx:
        use = check(t, now + idx, idx + 1)
    # not use
    nuse = check(t, now, idx + 1)

    return min(use, nuse)

X = int(raw_input())
print(str(check(X, 0, 1)))

Buggy submission (verdict: Runtime Error):
# -*- coding: utf-8 -*-
def check(t, now, idx):
    if t < idx:
        return 99999999999
    # use
    use = -1
    if t == now + idx:
        use = idx
    else:
        use = check(t, now + idx, idx + 1)
    # not use
    nuse = check(t, now, idx + 1)

    return min(use, nuse)

X = int(raw_input())
print(str(check(X, 0, 1)))
Problem p03795 (python)

Fixed submission:
# -*- coding: utf-8 -*-
n = int(input())
print(n * 800 - (200 * int(n / 15)))

Buggy submission (verdict: Runtime Error):
# -*- coding: utf-8 -*-
def check(s, ans):
    if len(s) != len(ans):
        return False;
    for i in range(0, len(s)):
        pre = i - 1
        next = i + 1
        if i == 0:
            pre = len(s) - 1
        if i == len(s) - 1:
            next = 0
                
        if ans[i] == "S":
            if s[i] == "o":
                if ans[pre] != ans[next]:
                    return False
            else:
                if ans[pre] == ans[next]:
                    return False
        else:
            if s[i] == "x":
                if ans[pre] != ans[next]:
                    return False
            else:
                if ans[pre] == ans[next]:
                    return False
    return True
                                
def getAns(s, ans, idx, n):
    if idx == n - 1:
        if check(a, ans):
            return ans
        else:
            return []
    if idx == 0:
        if ans[idx] == "S":
            if s[idx] == "o":
                ans[n - 1] = ans[1]
            else:
                if ans[1] == "S":
                    ans[n - 1] = "W"
                else:
                    ans[n - 1] = "S"
        else:
            if s[idx] == "x":
                ans[n - 1] = ans[1]
            else:
                if ans[1] == "S":
                    ans[n - 1] = "W"
                else:
                    ans[n - 1] = "S"
        return getAns(s, ans, idx + 1, n)
    pre  = idx - 1
    next = idx + 1
    # 羊
    if ans[idx] == "S":
        if s[idx] == "o":
            ans[next] = ans[pre]
        else:
            if ans[pre] == "S":
                ans[next] = "W"
            else:
                ans[next] = "S"
    # 狼
    else:
        if s[idx] == "x":
            ans[next] = ans[pre]
        else:
            if ans[pre] == "S":
                ans[next] = "W"
            else:
                ans[next] = "S"
    return getAns(s, ans, idx + 1, n)

def arrayToString(arry):
    s = ""
    for i in range(0, len(arry)):
        s+= arry[i]
    return s

n = int(input())
a = input()
s = [a[i] for i in range(0, len(a))]
ans = ["S" for i in range(0, len(a))]
ans1 = ans[:]
ans1 = getAns(s, ans1, 0, n)
if len(ans1) != 0:
    print(arrayToString(ans1))
    quit()
ans2 = ans[:]
ans2[0] = "W"
ans2 = getAns(s, ans2, 0, n)
if len(ans2) != 0:
    print(arrayToString(ans2))
    quit()
ans3 = ans[:]
ans3[1] = "W"
ans3 = getAns(s, ans3, 0, n)
if len(ans3) != 0:
    print(arrayToString(ans3))
    quit()
ans4 = ans[:]
ans4[0] = "W"
ans4[1] = "W"
ans4 = getAns(s, ans4, 0, n)
if len(ans4) != 0:
    print(arrayToString(ans4))
    quit()
print("-1")