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

Fixed submission:
S_str=str(input())
S=int(S_str[-1])
N=len(S_str)

mod=[0]*2019
mod[0]=1
now=S%2019
mod[now]+=1

for i in range(N-1)[::-1]:
    #print(i+1,S,S%2019)
    next=pow(10,N-1-i,2019)
    next=(next*int(S_str[i]))%2019
    now=(now+next)%2019
    mod[now]+=1

    

def culc(x):
    return x*(x-1)//2


ans=0
for j in range(len(mod)):
    ans+=culc(mod[j])

print(ans)

Buggy submission (verdict: Runtime Error):
S_str=str(input())
S=int(S_str[-1])
N=len(S_str)

mod=[0]*2018
mod[0]=1
now=S%2019
mod[now]+=1

for i in range(N-1)[::-1]:
    #print(i+1,S,S%2019)
    next=pow(10,N-1-i,2019)
    next=(next*int(S_str[i]))%2019
    now=(now+next)%2019
    mod[now]+=1

    

def culc(x):
    return x*(x-1)//2


ans=0
for j in range(len(mod)):
    ans+=culc(mod[j])

print(ans)

Buggy submission (verdict: Runtime Error):
S_str=str(input())
S_list=list(S_str)
S=int(S_list[-1])
N=len(S_str)

mod=[0]*2018
mod[0]=1
now=S%2019
mod[now]+=1

for i in range(N-1)[::-1]:
    #print(i+1,S,S%2019)
    next=pow(10,N-1-i,2019)
    next=(next*int(S_list[i]))%2019
    now=(now+next)%2019
    mod[now]+=1

    

def culc(x):
    return x*(x-1)//2


ans=0
for j in range(len(mod)):
    ans+=culc(mod[j])

print(ans)

Buggy submission (verdict: Runtime Error):
S_str=str(input())
S_list=list(S_str)
S=int(S_str)
N=len(S_str)

mod=[0]*2018
mod[0]=1

for i in range(N):
    #print(i+1,S,S%2019)
    mod[S%2019]+=1
    S-=int(S_list[i])*(10**(N-1-i))

def culc(x):
    return x*(x-1)//2


ans=0
for j in range(len(mod)):
    ans+=culc(mod[j])

print(ans)
Problem p02715 (python)

Fixed submission:
N,K=map(int,input().split())
P=10**9+7

L=[0]*(K+1)
for i in range(1,K+1)[::-1]:
    minus=0
    count=2
    while True:
        if count*i<=K:
            minus+=L[count*i]
            minus=minus%P
            count+=1
        else:
            break

    L[i]=(pow(K//i,N,P)-minus)%P

ans=0
for j in range(1,K+1):
    ans+=j*L[j]
    ans=ans%P

print(ans)

Buggy submission (verdict: Runtime Error):
import math

N,K=map(int,input().split())
P=10**9+7

L=[0]*K
for i in range(N):
    L[i]=pow(K//(i+1),N-1,P)

def culc(x):
    f=K//i
    r=K-f
    if r==1:
        return (f*(N-1))%P
    else:
        y=pow(r,N-1)-1
        return ((f*y)//(r-1))%P

for j in range(1,K):
    L[0]+=culc(j+1)

ans=0
for k in range(K):
    ans+=((k+1)*L[k])%P

print(ans)
Problem p02761 (python)

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



if N>=2:
    for i in range(10**(N-1),10**N):
        letter=str(i)
        for j in range(M):
            if letter[S[j][0]-1]!=str(S[j][1]):
                break
        else:
            print(i)
            break
    else:
        print('-1')
else:
    for k in range(0,10):
        letter=str(k)
        for l in range(M):
            if letter[S[l][0]-1]!=str(S[l][1]):
                break
        else:
            print(k)
            break
    else:
        print('-1')

Buggy submission (verdict: Runtime Error):
N,M=map(int,input().split())
S=[list(map(int,input().split())) for _ in range(M)]

ans=''

S_sorted=sorted(S)
#print(S_sorted)

for j in range(M-1):
    if S_sorted[j][0]==S_sorted[j+1][0] and S_sorted[j][1]!=S_sorted[j+1][1]:
        ans='-1'

if ans!='-1':
    if S_sorted[0][0]==1 and S_sorted[0][1]==0:
        if N==1:
            ans=0
        else:
            ans='-1'

R=[1]

if ans!='-1' and ans!=0:
    for _ in range(1,N):
        R.append(0)
    
    for k in range(M):
        R[S_sorted[k][0]-1]=S_sorted[k][1]
    
    for l in range(N):
        ans+=str(R[l])
        int(ans)

#print(R)


print(ans)
Problem p02787 (python)

Fixed submission:
H,N=map(int,input().split())
A=[]
B=[]
for _ in range(N):
    a,b=map(int,input().split())
    A.append(a)
    B.append(b)


inf=float('inf')
component=[0]
for i in range(H):
    component.append(inf)
DP=[]
for j in range(N+1):
    DP.append(component)#DPは(N+1)×(H+1)


for k in range(1,N+1):#k番目の魔法
    for l in range(1,H+1):#体力H
        DP[k][l]=min(DP[k-1][l],DP[k][max(0,l-A[k-1])]+B[k-1])

print(DP[N][H])

Buggy submission (verdict: Runtime Error):
H,N=map(int,input().split())
A=[]
B=[]
for _ in range(N):
    a,b=map(int,input().split())
    A.append(a)
    B.append(b)


inf=float('inf')
component=[0]
for i in range(H):
    component.append(inf)
DP=[]
for j in range(N+1):
    DP.append(copy.copy(component))#DPは(N+1)×(H+1)


for k in range(1,N+1):#k番目の魔法
    for l in range(1,H+1):#体力H
        DP[k][l]=min(DP[k-1][l],DP[k][max(0,l-A[k-1])]+B[k-1])

print(DP[N][H])
Problem p02789 (python)

Fixed submission:
N,M=map(str,input().split())

if M==N:
    print('Yes')
else:
    print('No')

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

Min=P[0]
ans=1

for i in range(1,N):
    if Min>=P[i]:
        ans+=1
        Min=P[i]
    
print(ans)
Problem p02802 (python)

Fixed submission:
import copy

N,M=map(int,input().split())
L=[list(map(str,input().split())) for i in range(M)]

for x in range(M):
    L[x][0]=int(L[x][0])

#print(N,M)
#print(L)

S=[]
component=[0,0]
for j in range(N):
    S.append(copy.deepcopy(component))

#print(S)

for k in range(1,M+1):
    if L[k-1][1]=='AC':
        if S[L[k-1][0]-1][0]==0:
            S[L[k-1][0]-1][0]=1
    else:
        if S[L[k-1][0]-1][0]==0:
            S[L[k-1][0]-1][1]+=1
    #print(S)

ansAC=0
ansWA=0

for l in range(N):
    ansAC+=S[l][0]
    if S[l][0]==1:
        ansWA+=S[l][1]

print(ansAC,ansWA)

Buggy submission (verdict: Runtime Error):
import copy

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

S=[]
component=[0,0]
for j in range(N):
    S.append(copy.deepcopy(component)

for k in range(1,M+1):
    if L[k-1][1]=='AC':
        if S[L[k-1][0]][0]==0:
            S[L[k-1][0]][0]=1
    else:
        if S[L[k-1][0]][0]==0:
            S[L[k-1][0]][1]+=1

ansAC=0
ansWA=0

for l in range(N):
    ansAC+=S[l][0]
    ansWA+=S[l][1]

print(ansAC,ansWA)
Problem p02803 (python)

Fixed submission:
import copy
from collections import deque

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


def check(tup):
    global H
    global W
    global S

    tup_x=tup[0]
    tup_y=tup[1]
    if 0<=tup_x<H and 0<=tup_y<W:
        if S[tup_x][tup_y]=='.':
            return True
    else:
        return False

def neighbor(tup):
    x=tup[0]
    y=tup[1]
    cand=[(x-1,y),(x+1,y),(x,y-1),(x,y+1)]
    List=[]
    for c in cand:
        if check(c):
            List.append(c)
    return List

def bfs(start):#startはtuple型
    global H
    global W

    if check(start):
        deq=deque()#as queue
        Dict=[]
        component=[]
        for i in range(W):
            component.append(-1)
        for j in range(H):
            Dict.append(copy.copy(component))

        deq.append(start)
        Dict[start[0]][start[1]]=0
        while deq:
            now=deq.popleft()
            nexts=neighbor(now)
            for next in nexts:
                next_x=next[0]
                next_y=next[1]
                if Dict[next_x][next_y]>=0:
                    continue
                if next in deq:
                    continue
                deq.append(next)
                Dict[next_x][next_y]=Dict[now[0]][now[1]]+1

        M=[]
        for d in Dict:
            M.append(max(d))
        return max(M)
    
    else:
        return 0

Ans=[]
for k in range(H):
    for l in range(W):
        Ans.append(bfs((k,l)))

print(max(Ans))

Buggy submission (verdict: Runtime Error):
import copy
from collections import deque

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


def check(tup):
    global H
    global W
    global S

    tup_x=tup[0]
    tup_y=tup[1]
    if 0<=tup_x<H and 0<=tup_y<W:
        if S[tup_x][tup_y]=='.':
            return True
    else:
        return False

def neighbor(tup):
    x=tup[0]
    y=tup[1]
    cand=[(x-1,y),(x+1,y),(x,y-1),(x,y+1)]
    List=[]
    for c in cand:
        if check(c):
            List.append(c)
    return List

def bfs(start):#startはtuple型
    global H
    global W

    deq=deque()#as queue
    Dict=[]
    component=[]
    for i in range(W):
        component.append(-1)
    for j in range(H):
        Dict.append(copy.copy(component))

    deq.append(start)
    Dict[start[0]][start[1]]=0
    while deq:
        now=deq.popleft()
        nexts=neighbor(now)
        for next in nexts:
            next_x=next[0]
            next_y=next[1]
            if Dict[next_x][next_y]>=0:
                continue
            if next in deq:
                continue
            deq.append(next)
            Dict[next_x][next_y]=Dict[now[0]][now[1]]+1

    M=[]
    for d in Dict:
        M.apeend(max(d))
    return max(M)

Ans=[]
for k in range(H):
    for l in range(W):
        Ans.append(bfs((k,l)))

print(max(Ans))
Problem p02887 (python)

Fixed submission:
N=int(input())
S=str(input())

ans=N

for i in range(N-1):
    if S[i]==S[i+1]:
        ans-=1

print(ans)

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

ans=N

for i in range(N-1):
    if S[i]=S[i+1]:
        ans-=1

print(ans)
Problem p02921 (python)

Fixed submission:
S=str(input())
T=str(input())

count=0
for i in range(3):
    if S[i]==T[i]:
        count+=1

print(count)

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

count=0
for i in range(3):
    if S[i]==S[j]:
        count+=1

print(count)
Problem p02924 (python)

Fixed submission:
N=int(input())

print((N-1)*N//2)

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

print(int(((N-1)*N/2))
Problem p02934 (python)

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

preans=0

for i in range(N):
    preans+=1/A[i]

print(1/preans)

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

preans=0

for i in range(N):
    preans+=1/A[i]

print(1/preans)
Problem p02936 (python)

Fixed submission:
from collections import deque

N,Q=map(int,input().split())
L=[[] for _ in range(N+1)]
for i in range(N-1):
    a,b=map(int,input().split())
    L[a].append(b)
    L[b].append(a)
count=[0]*(N+1)
for j in range(Q):
    p,x=map(int,input().split())
    count[p]+=x

#print(count)

q=deque() #queueとして(popleftとappend)
q.append(1)
parent=[-1]*(N+1)
#parent[1]=1

while q:
    now=q.popleft()
    for k in L[now]:
        if parent[now]==k:
            continue
        count[k]+=count[now]
        parent[k]=now
        q.append(k)
        #print(parent)

print(*count[1:])

Buggy submission (verdict: Runtime Error):
n,q=map(int,input().split())
G=[[] for i in range(n)]
for i in range(n-1):
    a,b=map(int,input().split())
    G[a-1].append(b-1)
    G[b-1].append(a-1)

add=[0]*n
for i in range(q):
    p,x=map(int,input().split())
    add[p-1]+=x

ans=[0]*n

check=[False]*n
temp=0
def dfs(v):
    global temp

    check[v]=True
    temp+=add[v]
    ans[v]=temp

    for next in G[v]:
        if check[next]:
            continue
        dfs(next)
    
    temp-=add[v]

dfs(0)

print(*ans)
Problem p02957 (python)

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

if (A+B)%2==0:
    print((A+B)//2)
else:
    print('IMPOSSIBLE')

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

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

if (A+B)%2==0:
    print((A+B)//2)
else:
    print('IMPOSSIBLE')

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

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

if (A+B)%2==0:
    print((A+B)/2)
else:
    print('impossible')
Problem p02971 (python)

Fixed submission:
import copy

N=int(input())
A=[]
for _ in range(N):
    A.append(int(input()))

A_max=max(A)
ind_max=A.index(A_max)
B=copy.copy(A)
B.remove(A_max)
B_max=max(B)

for i in range(N):
    if A[i]!=A_max:
        print(A_max)
    else:
        print(B_max)

Buggy submission (verdict: Runtime Error):
N=int(input())
A=[]
for i in range(N):
    A.append(int(input()))

max_value=max(A)
max_index=A.index(max_value)
second_value=A.sort()[-2]

for j in range(N):
    if j==max_index:
        print(second_value)
    else:
        print(max_value)

Buggy submission (verdict: Runtime Error):
N=int(input())
A=[]
for i in range(N):
    A.append(int(input()))

max_value=max(A)
max_index=A.index(max_value)
second_value=A.sort()[-2]

for j in range(N):
    if i==max_index:
        print(second_value)
    else:
        print(max_value)
Problem p02983 (python)

Fixed submission:
L,R=map(int,input().split())

l=L%2019
r=R%2019

ans=0

if R-L<2019 and l<r:
    D=[]
    for i in range(l,r):
        for j in range(i+1,r+1):
            D.append((i*j)%2019)
    ans=min(D)

print(ans)

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

l=L%2019
r=R%2019

ans=0

if R-L<2019 and l<r:
    D=[]
    for i in range(l,r):
        for j in range(i+1,r+1):
            D.append((i*j)%2019)

ans=min(D)

print(ans)
Problem p03044 (python)

Fixed submission:
from collections import deque

N=int(input())
L=[[] for _ in range(N+1)]
for a in range(N-1):
    u,v,w=map(int,input().split())  #これで良いのか
    L[u].append((v,w))
    L[v].append((u,w))

dist=[-1]*(N+1)
q=deque()
color=[-1]*(N+1)

dist[1]=0
q.append(1)
color[1]=0
while q:
    now=q.popleft()
    for next in L[now]:
        if dist[next[0]]==-1:
            q.append(next[0])
            dist[next[0]]=dist[now]+next[1]
            if dist[next[0]]%2==0:
                color[next[0]]=0
            else:
                 color[next[0]]=1

for b in range(1,N+1):
    print(color[b])

Buggy submission (verdict: Runtime Error):
N=int(input())
L=[[] for _ in range(N+1)]
for a in range(N-1):
    u,v,w=map(int,input().split())  #これで良いのか
    L[u].append((v,w))
    L[v].append((u,w))

color=[-1]*(N+1)

def dfs(x,cur=0):
    global L
    global color

    color[x]=cur
    for next in L[x]:
        if color[next[0]]!=-1:
            continue
        if next[1]%2==0:
            dfs(next[0],cur)
        if next[1]%2==1:
            dfs(next[0],1-cur)

dfs(1)
for b in range(1,N+1):
    print(color[b])
Problem p03165 (python)

Fixed submission:
S=str(input())
T=str(input())

ls=len(S)
lt=len(T)


DP=[[0]*(lt+1) for _ in range(ls+1)]


for i in range(1,ls+1):
    for j in range(1,lt+1):
        if S[i-1]==T[j-1]:
            DP[i][j]=max(DP[i-1][j-1]+1,DP[i][j-1],DP[i-1][j])
        else:
            DP[i][j]=max(DP[i][j-1],DP[i-1][j])

lf=DP[ls][lt]

res=''
u=ls
v=lt
while u>0 and v>0:
    if DP[u][v]==DP[u-1][v]:
        u-=1
    elif DP[u][v]==DP[u][v-1]:
        v-=1
    else:
        res=S[u-1]+res
        u-=1
        v-=1

print(res)

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

G=[[] for _ in range(N+1)]  #G[0]はダミー
for edge in range(M):
    x,y=map(int,input().split())
    G[x].append(y)

DP=[-1]*(N+1)   #DP[0]はダミー

def rec(now):
    global G

    if DP[now]!=-1:
        return DP[now]

    else:
        res=0
        for next in G[now]:
            res=max(res,rec(next)+1)
        DP[now]=res
        return res

ans=0
for v in range(1,N+1):
    ans=max(ans,rec(v))

print(ans)
Problem p03166 (python)

Fixed submission:
import sys
sys.setrecursionlimit(1000000)

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

G=[[] for _ in range(N+1)]  #G[0]はダミー
for edge in range(M):
    x,y=map(int,input().split())
    G[x].append(y)

DP=[-1]*(N+1)   #DP[0]はダミー

def rec(now):
    global G
    global DP

    if DP[now]!=-1:
        return DP[now]

    else:
        res=0
        for next in G[now]:
            res=max(res,rec(next)+1)
        DP[now]=res
        return DP[now]  #resは不可


ans=0
for v in range(1,N+1):
    ans=max(ans,rec(v))



print(ans)

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

G=[[] for _ in range(N+1)]  #G[0]はダミー
for edge in range(M):
    x,y=map(int,input().split())
    G[x].append(y)

DP=[-1]*(N+1)   #DP[0]はダミー

def rec(now):
    global G
    global DP

    if DP[now]!=-1:
        return DP[now]

    else:
        res=0
        for next in G[now]:
            res=max(res,rec(next)+1)
        DP[now]=res
        return DP[now]  #resは不可

ans=0
for v in range(1,N+1):
    ans=max(ans,rec(v))

print(ans)

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

G=[[] for _ in range(N+1)]  #G[0]はダミー
for edge in range(M):
    x,y=map(int,input().split())
    G[x].append(y)

DP=[-1]*(N+1)   #DP[0]はダミー

def rec(now):
    global G

    if DP[now]!=-1:
        return DP[now]

    else:
        res=0
        for next in G[now]:
            res=max(res,rec(next)+1)
        DP[now]=res
        return DP[now]

ans=0
for v in range(1,N+1):
    ans=max(ans,rec(v))

print(ans)
Problem p03177 (python)

Fixed submission:
#少なくとも表示が楽
#import numpy as np


P=10**9+7
N,K=map(int,input().split())
G=[]
for index in range(N):
    G.append(list(map(int,input().split())))
#こうするしかない
#G=np.matrix(G)

#print(np.dot(G,G))
#print(G*G)は正しくならないがおそらくversionの問題

def mul(x,y,p): #x[0]とlen(y)が同じなのは前提
    res=[[0]*(len(y[0])) for _ in range(len(x))]
    #res[index1][index2]を決定
    for index1 in range(len(x)):
        for index2 in range(len(y[0])):
            for index3 in range(len(y)):  #len(x[0])でも良い　
                res[index1][index2]=(res[index1][index2]+x[index1][index3]*y[index3][index2])%p
    return res


def pow(x,y,p):
    res=[[0]*(len(x)) for _ in range(len(x))]
    for index1 in range(len(x)):
        res[index1][index1]=1
    
    while y>0:
        if y&1==1:
            res=mul(res,x,p)
        x=mul(x,x,p)
        y=y>>1
    
    return res

#print(np.matrix(pow(G,2,P)))

#DP_K=np.matrix(pow(G,K,P))
DP_K=pow(G,K,P)

ans=0
for i in range(N):
    for j in range(N):
        #ans=(ans+DP_K[i,j])%P
        ans=(ans+DP_K[i][j])%P

print(ans)

Buggy submission (verdict: Runtime Error):
#少なくとも表示が楽
import numpy as np


P=10**9+7
N,K=map(int,input().split())
G=[]
for index in range(N):
    G.append(list(map(int,input().split())))
#こうするしかない
#G=np.matrix(G)

#print(np.dot(G,G))
#print(G*G)は正しくならないがおそらくversionの問題

def mul(x,y,p): #x[0]とlen(y)が同じなのは前提
    res=[[0]*(len(y[0])) for _ in range(len(x))]
    #res[index1][index2]を決定
    for index1 in range(len(x)):
        for index2 in range(len(y[0])):
            for index3 in range(len(y)):  #len(x[0])でも良い　
                res[index1][index2]=(res[index1][index2]+x[index1][index3]*y[index3][index2])%p
    return res


def pow(x,y,p):
    res=[[0]*(len(x)) for _ in range(len(x))]
    for index1 in range(len(x)):
        res[index1][index1]=1
    
    while y>0:
        if y&1==1:
            res=mul(res,x,p)
        x=mul(x,x,p)
        y=y>>1
    
    return res

#print(np.matrix(pow(G,2,P)))

DP_K=np.matrix(pow(G,K,P))

ans=0
for i in range(N):
    for j in range(N):
        ans=(ans+DP_K[i,j])%P

print(ans)
Problem p03436 (python)

Fixed submission:
from collections import deque

H,W=map(int,input().split())
count=0
S=[['#']*(W+1) for _ in range(H+1)]
for i in range(1,H+1):
    S_comp=list(str(input()))
    for j in range(1,W+1):
        if S_comp[j-1]=='.':
            count+=1
        S[i][j]=S_comp[j-1]


def sur(v):  #v is tuple
    vx=v[0]
    vy=v[1]
    preE=[(vx-1,vy),(vx+1,vy),(vx,vy-1),(vx,vy+1)]
    E=[]
    for nv in preE:
        if 1<=nv[0]<=H and 1<=nv[1]<=W:
            if S[nv[0]][nv[1]]=='.':
                E.append(nv)
    return E

q=deque()
s=(1,1)
g=(H,W)
q.append(s)
dist=[[-1]*(W+1) for k in range(H+1)]
dist[s[0]][s[1]]=0

while q:
    now=q.popleft()
    for next in sur(now):
        if dist[next[0]][next[1]]!=-1:
            continue
        q.append(next)
        dist[next[0]][next[1]]=dist[now[0]][now[1]]+1
        if next==g:
            ans=dist[g[0]][g[1]]
            print(count-1-ans)
            break
    else:
        continue
    break
else:
    print(-1)

Buggy submission (verdict: Runtime Error):
from collections import deque

H,W=map(int,input().split())
count=0
S=[['#']*(W+1) for _ in range(H+1)]
for i in range(1,H+1):
    S_comp=list(str(input()))
    for j in range(1,W+1):
        if S_comp[j-1]=='.':
            count+=1
        S[i][j]=S_comp[j-1]


def sur(v):  #v is tuple
    vx=v[0]
    vy=v[1]
    preE=[(vx-1,vy),(vx+1,vy),(vx,vy-1),(vx,vy+1)]
    E=[]
    for nv in preE:
        if 1<=nv[0]<=H and 1<=nv[1]<=W:
            if S[nv[0]][nv[1]]=='.':
                E.append(nv)
    return E

q=deque()
s=(1,1)
g=(H,W)
q.append(s)
dist=[[-1]*(W+1) for k in range(H+1)]
dist[s[0]][s[1]]=0

while q:
    now=q.popleft()
    for next in sur(now):
        if dist[next[0]][next[1]]!=-1:
            continue
        q.append(next)
        dist[next[0]][next[1]]=dist[now[0]][now[1]]+1
        if next==g:
            ans=dist[g[0]][g[1]]
            break
    else:
        continue
    break

print(count-1-ans)
Problem p02606 (python)

Fixed submission:
l,r,d = map(int,input().split())
print(r//d-(l-1)//d)

Buggy submission (verdict: Runtime Error):
n = int(input())
a = list(map(int,input().split()))
ans = 0
for i,ai in enumerate(a):
  if (i+1)%2 == 1 and ai%2 == 1:
    ans += 1
print(ans)
Problem p02645 (python)

Fixed submission:
s = input()
print(s[:3])

Buggy submission (verdict: Runtime Error):
def main(): 
  import sys
  read = sys.stdin.buffer.read
  readline = sys.stdin.buffer.readline
  readlines = sys.stdin.buffer.readlines
  from bisect import bisect

  n = int(readline())
  g = []
  for i in range(n):
    v,W = map(int,readline().split())
    g.append((v,W))

  q = int(readline())
  for i in range(q):
    V,w = map(int,readline().split())
    c = []
    ans = 0
    while V > 0:
      c.append(g[V-1])
      V //= 2
    d = []
    e = []
    h = n//2-1
    H = n-h
    for i in range(2**h):
      cw = 0
      cv = 0
      for j,cj in enumerate(c[:h]):
        if (i>>j)&1 == 1:
          cw += cj[1]
          cv += cj[0]
      d.append((cv,cw))

    for i in range(2**H):
      cw = 0
      cv = 0
      for j,cj in enumerate(c[h:]):
        if (i>>j)&1 == 1:
          cw += cj[1]
          cv += cj[0]
      e.append((cv,cw))

    from operator import itemgetter
    e = sorted(e,key=itemgetter(1))

    Ev = [0]
    Ew = [0]
    ch = 0
    for i in range(1,len(e)):
      ev,ew = e[i]
      if ev > ch:
        Ev.append(ev)
        Ew.append(ew)
        ch = ev

    for i in d:
      Cv,Cw = i
      if Cw > w:
        continue
      ind = bisect(Ew,w-Cw)
      cc = Cv+Ev[ind-1]
      ans = max(cc,ans)

    print(ans)
if __name__ == '__main__':
    main()
Problem p02657 (python)

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

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

Fixed submission:
a = list(map(int,input().split()))
print(a[2]*60+a[3]-a[0]*60-a[1]-a[4])

Buggy submission (verdict: Runtime Error):
import sys
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
 
n = int(readline())
a = list(map(int,readline().split()))

b = [0]*(n+1)
b[-1] = a[-1]
for i in range(n-1,-1,-1):
  b[i] = b[i+1]+a[i]
#print(b)
c = [1]*(n+1)
for i in range(n):
  c[i+1] = (c[i]-a[i])*2
#print(c)
ans = 0
for i in range(n+1):
  m = min(b[i],c[i])
  if m < 0:
    ans = -1
    break
  ans += m
  
if n == 0:
  ans = 1
if a[0] != 0:
  ans = -1
print(ans)
Problem p02669 (python)

Fixed submission:
import sys
sys.setrecursionlimit(10**9)
from functools import lru_cache

t = int(input())
  
for _ in range(t):
    n,a,b,c,d = map(int,input().split())
    @lru_cache(None)
    def f(k):
      if k == 1:return d
      if k == 0:return 0
      return min(k*d,f(k//5)+c+k%5*d,f(k//3)+b+k%3*d,f(k//2)+a+k%2*d,f((k+4)//5)+c+-k%5*d,f((k+2)//3)+b+-k%3*d,f((k+1)//2)+a+-k%2*d)
    print(f(n))

Buggy submission (verdict: Runtime Error):
import sys
sys.setrecursionlimit(10**9)
from functools import lru_cache
from math import ceil as C
  
for _ in range(t):
    n,a,b,c,d = map(int,input().split())
    @lru_cache(None)
    def f(k):
      if k == 1:return d
      if k == 0:return 0
      return min(k*d,f(k//2)+a+k%2*d,f(C(k/2))+a+-k%2*d,f(k//3)+b+k%3*d,f(C(k/3))+b+-k%3*d,f(k//5)+c+k%5*d,f(C(k/5))+c+-k%5*d)
    print(f(n))