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

Fixed submission:
import math
N, K = map(int, input().split())
A = list(map(int, input().split()))
A2 = [0]*(N+1)
for i in range(K):
    for j in range(N):
        g = math.ceil(j+1-A[j]-0.5)
        if g<1:
            g=1
        h = math.floor(j+1+A[j]+0.5)
        if h>N:
            h=N
        A2[g-1]+=1
        A2[h]-=1
    A[0]=A2[0]
    for j in range(1, N):
        A[j]=A[j-1]+A2[j]
    A2 = [0]*(N+1)
    c = 0
    for p in range(N):
        c+=A[p]
    if c >= N*N:
        break

print(*A)

Buggy submission (verdict: Runtime Error):
import math
N, K = map(int, input().split())
A = list(map(int, input().split()))
A2 = [0]*N
for i in range(K):
    for j in range(N):
        g = math.ceil(j+1-A[j]-0.5)
        if g<1:
            g=1
        h = math.floor(j+1+A[j]+0.5)
        if h>N:
            h=N
        for x in range(g,h+1):
            A2[x-1]+=1
    A=A2[:]
    A2 = [0]*N
    c = 0
    for p in range(N):
        c+=A[p]
    if c => N*N:
        break

print(*A)
Problem p02555 (python)

Fixed submission:
s=int(input())
p=10**9+7
if s<=2:
    print(0)
    exit()
n=s//3
ans=0
def f(n,k,p):
    if k==0:
        return 1
    elif k%2==0:
        return (f(n,k//2,p)**2)%p
    else:
        return (n*f(n,k-1,p))%p

for k in range(1,n+1):
    a=1
    b=1
    for j in range(k-1):
        a=(a*(s-3*k+1+j))%p
        b=(b*(j+1))%p
    ans=(ans+a*f(b,p-2,p))%p

print(ans%p)

Buggy submission (verdict: Runtime Error):
s=int(input())
p=10**9+7
if s<=2:
    print(0)
    exit()
n=s//3
ans=0


for k in range(1,n+1):
    a=1
    b=1
    for j in range(k-1):
        a=a*(s-3*k+1+j)%p
        b=b*(j+1)%p
    ans=(ans+a*pow(b,-1,p))%p

print(ans%p)
Problem p02573 (python)

Fixed submission:
import sys
sys.setrecursionlimit(10**9)
n,m=map(int,input().split())
root=[-1]*n
def r(x):
    if root[x]<0:
        return x
    else:
        root[x]=r(root[x])
        return root[x]
def unite(x,y):
    x=r(x)
    y=r(y)
    if x==y:
        return
    root[x]+=root[y]
    root[y]=x
def size(x):
    x=r(x)
    return -root[x]
for i in range(m):
    x,y=map(int,input().split())
    x-=1
    y-=1
    unite(x,y)
ans=0
for i in range(n):
    ans=max(ans,size(i))
print(ans)

Buggy submission (verdict: Runtime Error):

n,m=map(int,input().split())
root=[-1]*n
def r(x):
    if root[x]<0:
        return x
    else:
        root[x]=r(root[x])
        return root[x]
def unite(x,y):
    x=r(x)
    y=r(y)
    if x==y:
        return
    root[x]+=root[y]
    root[y]=x
def size(x):
    x=r(x)
    return -root[x]
for i in range(m):
    x,y=map(int,input().split())
    x-=1
    y-=1
    unite(x,y)
ans=0
for i in range(n):
    ans=max(ans,size(i))
print(ans)
Problem p02603 (python)

Fixed submission:
n=int(input())
a=list(map(int,input().split()))
d=1
kabu=0
ans=1000
while d<=n-1:
    if a[d]>a[d-1]:
        f=ans//a[d-1]
        kabu+=f
        ans=ans-a[d-1]*f
    if a[d]<a[d-1]:
        ans+=kabu*a[d-1]
        kabu=0
    d+=1
ans+=kabu*a[n-1]
print(ans)

Buggy submission (verdict: Runtime Error):
a=list(map(int,input().split()))
d=1
kabu=0
ans=1000
while d<=n-1:
    if a[d]>a[d-1]:
        f=ans//a[d-1]
        kabu+=f
        ans=ans-a[d-1]*f
    if a[d]<a[d-1]:
        ans+=kabu*a[d-1]
        kabu=0
    d+=1
ans+=kabu*a[n-1]
print(ans)
Problem p02630 (python)

Fixed submission:
n=int(input())
a=list(map(int,input().split()))
q=int(input())
num=[0]*(10**5+1)
ans=sum(a)
for i in a:
    num[i]+=1
for i in range(q):
    b,c=map(int,input().split())
    ans=ans+(c-b)*num[b]
    num[c]+=num[b]
    num[b]=0
    print(ans)

Buggy submission (verdict: Runtime Error):
n=int(input())
a=list(map(int,input().split()))
q=int(input())
num=[0]*(10**5+1)
ans=sum(a)
for i in a:
    num[i]+=1
for i in range(q):
    b,c=map(int,input().split())
    ans=ans+(c-b)*num[b-1][0]
    num[c-1][0]+=num[b-1][0]
    num[b-1][0]=0
    print(ans)

Buggy submission (verdict: Runtime Error):
n=int(input())
a=list(map(int,input().split()))
q=int(input())
num=[[a.count(i+1)] for i in range(n)]
ans=sum(a)
for i in range(q):
    b,c=map(int,input().split())
    ans=ans+(c-b)*num[b-1][0]
    num[c-1][0]+=num[b-1][0]
    num[b-1][0]=0
    print(ans)
Problem p02761 (python)

Fixed submission:
n,m=map(int,input().split())
a=[-1 for _ in range(n)]
f=0
if n!=1:
    
    for i in range(m):
        s,c=map(int,input().split())
        if a[s-1]==-1 or a[s-1]==c:
            a[s-1]=c
        if a[s-1]!=-1 and a[s-1]!=c:
            f=1
        if s==1 and c==0:
            f=1
    for q in range(n):
        if q!=0 and a[q]==-1:
            a[q]=0
        if q==0 and a[q]==-1:
            a[q]=1

    ans=0
    for t in range(n):
        ans+=a[n-t-1]*(10**t)
    print(ans if f==0 else -1)
else:
    for i in range(m):
        
        s,c=map(int,input().split())
        if i==0:
            d=c
        if d!=c:
            f=1
            
    if m!=0:
        
        print(c if f==0 else -1)
    if m==0:
        print(0)

Buggy submission (verdict: Runtime Error):
n,m=map(int,input().split())
a=[-1 for _ in range(n)]
f=0
if n!=1:
    
    for i in range(m):
        s,c=map(int,input().split())
        if a[s-1]==-1 or a[s-1]==c:
            a[s-1]=c
        if a[s-1]!=-1 and a[s-1]!=c:
            f=1
        if s==1 and c==0:
            f=1
    for q in range(n):
        if q!=0 and a[q]==-1:
            a[q]=0
        if q==0 and a[q]==-1:
            a[q]=1

    ans=0
    for t in range(n):
        ans+=a[n-t-1]*(10**t)
    print(ans if f==0 else -1)
else:
    s,c=map(int,input().split())
    d=c
    for i in range(m-1):
        e,r=map(int,input().split())
        if d!=r:
            f=1
    print(c if f==0 else -1)

Buggy submission (verdict: Runtime Error):
n,m=map(int,input().split())
a=[-1 for _ in range(n)]
f=0
if n!=1:
    
    for i in range(m):
        s,c=map(int,input().split())
        if a[s-1]==-1 or a[s-1]==c:
            a[s-1]=c
        if a[s-1]!=-1 and a[s-1]!=c:
            f=1
        if s==1 and c==0:
            f=1
    for q in range(n):
        if q!=0 and a[q]==-1:
            a[q]=0
        if q==0 and a[q]==-1:
            a[q]=1

    ans=0
    for t in range(n):
        ans+=a[n-t-1]*(10**t)
    print(ans if f==0 else -1)
else:
    s,c=map(int,input().split())
    d=c
    for i in range(m-1):
        e,r=map(int,input().split())
        if d!=r:
            f=1
    print(c if f==0 else -1)
Problem p02812 (python)

Fixed submission:
n=int(input())
s=list(input())
a=0
for i in range(n-2):
    if s[i]=="A" and s[i+1]=="B" and s[i+2]=="C":
        a+=1
print(a)

Buggy submission (verdict: Runtime Error):
n=int(input())
s=list(input())
a=0
for i in range(n):
    if s[i]=="A" and s[i+1]=="B" and s[i+2]=="C":
        a+=1
print(a)
Problem p02945 (python)

Fixed submission:
a,b=map(int,input().split())
x=a+b
y=a-b
z=a*b
print(max(x,y,z))

Buggy submission (verdict: Runtime Error):
a,b=map(int,input().split())
x=a+b
y=a-b
z=a*b
if x>=y and x>=z:
    print(x)
if y>=x and y>=z:
    print(y):
if z>=x and z>=y:
     print(z)
Problem p02981 (python)

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

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

Fixed submission:
import fractions

a,b,c,d=map(int,input().split())
g=int(fractions.gcd(c,d))
l=int((c*d)/g)

print(b-a+1-int(b//c)+int((a-1)//c)-int(b//d)+int((a-1)//d)+int(b//l)-int((a-1)//l))

Buggy submission (verdict: Runtime Error):
import math

a,b,c,d=map(int,input().split())
C=b//c-((a-1)//c)
D=b//d-((a-1)//d)
g=math.gcd(c,d)
l=c*d/g
E=b//l-((a-1)//l)
print(int(b-a+1-C-D+E))

Buggy submission (verdict: Runtime Error):
import fractinos

a,b,c,d=map(int,input().split())
C=b//c-((a-1)//c)
D=b//d-((a-1)//d)
g=fractions.gcd(c,d)
E=b//g-((a-1)//g)
print(b-a+1-C-D+E)
Problem p03147 (python)

Fixed submission:
n=int(input())
h=list(map(int,input().split()))
if n==1:
    print(h[0])
elif n==2:
    print(max(h))
else:
    h.append(0)
    h.insert(0,0)
    
    ans=0
    f=[0 for i in range(n+2)]
    
    for i in range(10010):
        a=1
        x=[]
        for j in range(n+2):
            if h[j]<=f[j]:
                x.append(j)
        m=len(x)
        if m==n+2:
            break
        a=m-1
        for j in range(m-1):
            if x[j]+1==x[j+1]:
                a-=1
        ans+=a
        for j in range(n+2):
            f[j]+=1
        
    print(ans)

Buggy submission (verdict: Runtime Error):
n=int(input())
h=list(map(int,input().split()))
if n==1:
    print(h[0])
elif n==2:
    print(max(h))
else:
    h.append(0)
    h.insert(0,0)
    
    ans=0
    f=[0 for i in range(n+2)]
    
    for i in range(10010):
        a=1
        x=[]
        for j in range(n+2):
            if h[j]<=f[j]:
                x.append(j)
        m=len(x)
        if m==n+2:
            break
        a=m-1
        for j in range(m-1):
            if x[j]+1==x[j+1]:
                a-=1
        ans+=a
        for j in range(n+2):
            f[j]+=1
        
print(ans)
Problem p03407 (python)

Fixed submission:
a,b,c=map(int,input().split())
print("Yes" if a+b>=c else "No")

Buggy submission (verdict: Runtime Error):
n=int(input())
red=[[] for i in range(n)]
blue=[[] for i in range(n)]
for i in range(n):
    a,b=map(int,input().split())
    red[i].append(a)
    red[i].append(b)
for i in range(n):
    a,b=map(int,input().split())
    blue[i].append(a)
    blue[i].append(b)
red=sorted(red)
blue=sorted(blue)
ans=0
for i in range(n):
    x=blue[i][0]
    y=blue[i][1]
    maxy=-1
    for j in range(n):
        if x>red[j][0] and y>red[j][1]:
            maxy=max(maxy,red[j][1])
    for j in range(n):
        if x>red[j][0] and maxy==red[j][1]:
            ans+=1
            red[j][0]=1000
            break
print(ans)
Problem p03607 (python)

Fixed submission:
n=int(input())
a=[]
for i in range(n):
    a.append(int(input()))
a=sorted(a)
ans=0
cnt=1
for i in range(n-1):

    if a[i]==a[i+1]:
        cnt+=1
    else:
        if cnt%2==1:ans+=1
        cnt=1
if cnt%2==1:ans+=1
print(ans)

Buggy submission (verdict: Runtime Error):
n=int(input())
x=[0]*(10**9+1)
ans=0
for i in range(n):
    a=int(input())
    if x[a]==0:
        x[a]=1
        ans+=1
    else:
        ans-=1
        x[a]=0
print(ans)
Problem p03645 (python)

Fixed submission:
from _collections import deque
n,m=map(int,input().split())
edg=[[] for i in range(n+1)]
for i in range(m):
    a,b=map(int,input().split())
    edg[a].append(b)
    edg[b].append(a)
dep=[-1]*(n+1)
dep[1]=0
data=deque([1])
while len(data)>0:
    p=data.popleft()
    for i in edg[p]:
        if dep[i]==-1:
            dep[i]=dep[p]+1
            data.append(i)
print("POSSIBLE" if dep[n]==2 else "IMPOSSIBLE")

Buggy submission (verdict: Runtime Error):
import sys
input=sys.stdin.readline()
from _collections import deque
n,m=map(int,input().split())
edg=[[] for i in range(n+1)]
for i in range(m):
    a,b=map(int,input().split())
    edg[a].append(b)
    edg[b].append(a)
dep=[-1]*(n+1)
dep[1]=0
data=deque([1])
while len(data)>0:
    p=data.popleft()
    for i in edg[p]:
        if dep[i]==-1:
            dep[i]=dep[p]+1
            data.append(i)
print("POSSIBLE" if dep[n]==2 else "IMPOSSIBLE")

Buggy submission (verdict: Runtime Error):
n,m=map(int,input().split())
edg=[[0]*(n+1) for i in range(n+1)]
for i in range(m):
    a,b=map(int,input().split())
    edg[a][b]=1
    edg[b][a]=1
f=1
for i in range(2,n+1):
    if edg[i][1]==1 and edg[i][n]==1:
        f=0
print("POSSIBLE" if f==0 else "IMPOSSIBLE")
Problem p03761 (python)

Fixed submission:
n=int(input())
x=[[0 for i in range(26)] for j in range(n)]
for i in range(n):
    s=input()
    for j in range(len(s)):
        x[i][ord(s[j])-97]+=1
ans=[0]*26
for i in range(26):
    ans[i]=min(x[j][i] for j in range(n))
a=[]
for i in range(26):
    for j in range(ans[i]):
        a.append(chr(97+i))
print("".join(a))

Buggy submission (verdict: Runtime Error):
n=int(input())
x=[[0 for i in range(26)] for j in range(n)]
for i in range(n):
    s=input()
    for j in range(len(s)):
        x[i][ord(s[j])-97]+=1
ans=[0]*26
for i in range(n):
    ans[i]=min(x[j][i] for j in range(n))
a=[]
for i in range(26):
    for j in range(ans[i]):
        a.append(chr(97+i))
print("".join(a))
Problem p04013 (python)

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

x=list(map(int,input().split()))
A=max(x)
x.insert(0,-1)
dp=[[[0]*(n+1) for _ in range(n*A+1)] for i in range(n+1)]
dp[1][x[1]][1]=1
dp[1][0][0]=1
for i in range(1,n):
    q=x[i+1]
    for s in range(n*A+1):
        for k in range(i+1):
            if s+q<=n*A:
                dp[i+1][s+q][k+1]+=dp[i][s][k]
            dp[i+1][s][k]+=dp[i][s][k]

ans=0
i=1

while i<=n and a*i<=n*A:
    ans+=dp[n][a*(i)][i]
    i+=1
print(ans)

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

x=list(map(int,input().split()))
A=max(x)
x.insert(0,-1)
dp=[[[0]*(n+1) for _ in range(n*A+1)] for i in range(n+1)]
dp[1][x[1]][1]=1
dp[1][0][0]=1
for i in range(1,n):
    q=x[i+1]
    for s in range(n*A+1):
        for k in range(i+1):
            if s+q<=n*A:
                dp[i+1][s+q][k+1]+=dp[i][s][k]
            dp[i+1][s][k]+=dp[i][s][k]

ans=0
i=1

while i<=n:
    ans+=dp[n][a*(i)][i]
    i+=1
print(ans)
Problem p02888 (python)

Fixed submission:
import bisect

N=int(input())
L=list(map(int,input().split()))

L=sorted(L)

ans=0
for i in range(N-1):
    for k in range(i+1,N-1):
        a=L[i]+L[k]
        b=bisect.bisect_left(L,a)
        ans=ans+(b-k-1)

print(ans)

Buggy submission (verdict: Runtime Error):
import bisect

N=int(input())
L=list(map(int,input().split()))

L=sorted(L)

ans=0
for i in range(N-1):
    for k in range(i+1,N-1):
        a=L[i]+L[k]
        b=bisect.bisect_left(L,a)
        ans=ans+(b-k-1)

print(ans)

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

a=0
for i in range(N-1):
    for k in range(1,N-i-1):
        a=a+sum(x<L[i]+L[i+k] for x in L[i+k+1:N])

print(a)
Problem p03282 (python)

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

ans=1
for i in range(min(len(s),k)):
    if int(s[i])!=1:
        ans=s[i]
        break

print(ans)

Buggy submission (verdict: Runtime Error):
def count(x,y):
    return abs((x-y)/2)

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


if (A-B)%2==0:
    ans=count(A,B)

else:
    
    if (A-1)<(N-B):
        ans=A
        A=1
        B=B-ans
    else:
        ans=N-B+1
        A=A+ans
        B=N
    
    ans+=count(A,B)

print(int(ans))

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

s0=int(s[0])
if s0==1:
    print(s[1])
else:
    print(s0)
Problem p03361 (python)

Fixed submission:
import numpy as np

H,W=map(int,input().split())

s=np.zeros((H+2,W+2),dtype=int)

for i in range(H):
    s0=input()
    for j in range(W):
        if s0[j]==".":
            num=0
        elif s0[j]=="#":
            num=1
        
        s[i+1][j+1]=num
        

ans_s=s[1:H+1,1:W+1]

ans=0
for k in range(1,H+1):
    for l in range(1,W+1):
        if s[k][l]==1:
            if s[k-1][l]==0 and s[k+1][l]==0 and s[k][l-1]==0 and s[k][l+1]==0:
                ans=1
                break

if ans==1:
    print("No")
else:
    print("Yes")

Buggy submission (verdict: Runtime Error):
H,W=map(int,input().split())

xy=((-1,0),(-1,0),(1,0),(0,1))
S=[]
S.append("."*(W+2))
for i in range(H):
    S.append("."+input()+".")

S.append("."*(W+2))

for i in range(1,H+1):
    for j in range(1,W+1):
        if S[i][j]==".":
            continue
        ans=False
        for x,y in xy:
            if S[i+x][j+y]=="#":
                ans=True
                break

if ans==True:
    print("Yes")
else:
    print("No")
Problem p02536 (python)

Fixed submission:
from collections import deque

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

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

for _ in range(M):
    a,b = map(lambda x: int(x)-1, input().split())
    AB[a].append(b)
    AB[b].append(a)

visited = [0] * N
ans = []
for i in range(N):
    if visited[i]:
        continue
    group = [i]
    d = deque(AB[i])
    while d:
        s = d.popleft()
        if visited[s]:
            continue
        visited[s] = 1
        group.append(s)
        for k in AB[s]:
            d.append(k)
    ans.append(len(group))

print(len(ans)-1)

Buggy submission (verdict: Runtime Error):
def dfs(v):
    visited[v] = 1
    for i in AB[v]:
        if visited[i]:
            continue
        dfs(i)

def main():
    N, M = map(int, input().split())
    AB = [[] for _ in range(N)]

    for _ in range(M):
        a,b = map(lambda x: int(x)-1, input().split())
        AB[a].append(b)
        AB[b].append(a)

    visited = [0]*N
    cnt = 0
    for i in range(N):
        if visited[i]:
            continue
        dfs(i)
        cnt += 1
    print(cnt-1)

if __name__ == "__main__":
    main()

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

    for _ in range(M):
        a,b = map(lambda x: int(x)-1, input().split())
        AB[a].append(b)
        AB[b].append(a)

    def dfs(v):
        visited[v] = 1
        for i in AB[v]:
            if visited[i]:
                continue
            dfs(i)

    visited = [0]*N
    cnt = 0
    for i in range(N):
        if visited[i]:
            continue
        dfs(i)
        cnt += 1
    print(cnt-1)

if __name__ == "__main__":
    main()

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

    for _ in range(M):
        a,b = map(lambda x: int(x)-1, input().split())
        AB[a].append(b)
        AB[b].append(a)

    def dfs(v):
        if visited[v]:
            return
        visited[v] = 1
        for i in AB[v]:
            dfs(i)

    visited = [0]*N
    cnt = 0
    for i in range(N):
        if visited[i]:
            continue
        dfs(i)
        cnt += 1
    print(N-cnt)

if __name__ == "__main__":
    main()
Problem p02614 (python)

Fixed submission:
H, W, K = map(int, input().split())

origin = [list(input()) for _ in range(H)]
ans = 0
for i in range(2**H):
    for j in range(2**W):
        cnt = 0
        for h_shift in range(H):
            for w_shift in range(W):
                if i >> h_shift & 1 == 1 or j >> w_shift & 1: #赤で塗られるマス
                    continue
                if origin[h_shift][w_shift] == "#":
                    cnt += 1
        if cnt == K:
            ans += 1
print(ans)

Buggy submission (verdict: Runtime Error):
h, w, k = gets.chomp.split(" ").map(&:to_i)
map = Array.new(h)
h.times do |i|
  map[i]=gets.chomp.split("")
end

cnt = 0
ans = 0
(1<<h).times do |i|
  (1<<w).times do |j|
    cnt = 0
    h.times do |h_shift|
      w.times do |w_shift|
        next if i>>h_shift&1==1 or j>>w_shift&1==1
        if map[h_shift][w_shift] == "#"
          cnt += 1
        end
      end
    end
    if k==cnt
      ans += 1
    end
  end
end
puts ans
Problem p02664 (python)

Fixed submission:
T = str(input())

ans = []
for i in T:
    if i == '?':
        ans.append('D')
    else:
        ans.append(i)

print(''.join(ans))

Buggy submission (verdict: Runtime Error):
T = input()
ans = []
if T[0]=='?':
    T[0]='D'

for i in range(len(T)-1):
    flg = 1
    if T[i+1]!='?':
        if T[i] != '?':
            ans.append(T[i])
            continue
        else:
            tmp = ans[i-1]
            flg = 0

    if flg:
        tmp = ans[i-1]
    if tmp=='P':
        ans.append('D')
    else:
        ans.append('P')



if T[-1]=='?':
    if ans[-1]=='P':
        ans.append('D')
    else:
        ans.append('P')
else:
    ans.append(T[-1])
print(''.join(ans))
Problem p02684 (python)

Fixed submission:
import sys
N, K = map(int, input().split()) #N: 町の数, K: ちょうどこの回数でたどり着く町

visited = [False for _ in range(N)]

A = list(map(lambda n: int(n)-1, input().split()))
tmp = 0 #次に訪れる番号
visited[0] = True
#cnt = 0 #テレポートの回数
log = [0] #テレポートの記録

for i in range(1, K+1):
    tmp = A[tmp]
    if visited[tmp]:
        start = log.index(tmp)
        break

    visited[tmp] = True
    log.append(tmp)

if i == K:
    print(tmp+1)
else:
    loop = log[start:i+1]
    period = len(loop)
    remain = K - i
    print(loop[remain%period] + 1)

Buggy submission (verdict: Runtime Error):
import sys
N, K = map(int, input().split()) #N: 町の数, K: ちょうどこの回数でたどり着く町

visited = [False for _ in range(N)]

A = list(map(lambda n: int(n)-1, input().split()))
tmp = 0 #次に訪れる番号
visited[0] = True
#cnt = 0 #テレポートの回数
log = [0] #テレポートの記録

for i in range(1, K+1):
    tmp = A[tmp]
    if visited[tmp]:
        start = log.index(tmp)
        break

    visited[tmp] = True
    log.append(tmp)

if i == K:
    print(log[K])
else:
    loop = log[start:i+1]
    period = len(loop)
    remain = K - i
    print(loop[remain%period] + 1)
Problem p02705 (python)

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

pi = math.pi

print(2*R*pi)

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

pi = math.pi

print(2*R*pis)
Problem p02713 (python)

Fixed submission:
K = int(input())

import math

ans = 0
for i in range(1, K+1):
    for j in range(1, K+1):
        a = math.gcd(i, j)
        for k in range(1, K+1):
            ans += math.gcd(a,k)

print(ans)

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

import math

ans = 0
for i in range(1, K+1):
    for j in range(1, K+1):
        a = gcd(i, j)
        for k in range(1, K+1):
            ans += gcd(a,k)

print(ans)
Problem p02936 (python)

Fixed submission:
from collections import deque
N, Q = map(int, input().split())
graph = [[] for _ in range(N)]

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

ans = [0]*N
for _ in range(Q):
    p, x = map(int, input().split())
    ans[p-1] += x

que = deque([0])
parent = [-1]*N
while que:
    node = que.pop()
    for v in graph[node]:
        if v == parent[node]:
            continue
        parent[v] = node
        que.append(v)
        ans[v] += ans[node] 

print(*ans)

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

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

X = [0]*N
for _ in range(Q):
    p, x = map(int, input().split())
    X[p-1] += x

ans = [0]*N

def dfs(u, parent):
    ans[u] = ans[parent] + X[u]
    for v in graph[u]:
        if v != parent:
            dfs(v, u)
dfs(0, 0)
print(*ans)
Problem p03160 (python)

Fixed submission:
N = int(input())
H = tuple(map(int, input().split()))

dp = [0] * N
dp[1] = abs(H[1]-H[0])
if N > 2:
    for i in range(2, N):
        dp[i] = min(dp[i-2] + abs(H[i]-H[i-2]), dp[i-1] + abs(H[i]-H[i-1]))
else:
    print(dp[-1])
    exit()

print(dp[-1])

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

dp = [0, abs(H[1]-H[0])]

if N > 2:
    for i in range(2, N):
        dp[i] = min(dp[i-2] + abs(H[i]-H[i-2]), dp[i-1] + abs(H[i]-H[i-1]))
else:
    print(dp[-1])
    exit()

print(dp[-1])

Buggy submission (verdict: Runtime Error):
N = int(input())
H = tuple(map(int, input(),split()))

dp = [0, abs(H[1]-H[0])]

if N > 2:
    for i in range(2, N):
        dp[i] = min(dp[i-2] + abs(H[i]-H[i-2]), dp[i-1] + abs(H[i]-H[i-1]))
else:
    print(dp[-1])
    exit()

print(dp[-1])

Buggy submission (verdict: Runtime Error):
N = int(input())
H = tuple(map(int, input(),split()))

dp = [0, abs(H[1]-H[0])]

if N > 2:
    for i in range(2, N):
        dp[2] = min(dp[i-2] + abs(H[i]-H[i-2]), dp[i-1] + abs(H[i]-H[i-1]))
else:
    print(dp[-1])
    exit()

print(dp[-1])

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

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

dp = [0]*(N+1)
dp[2] = abs(H[0] - H[1])
if len(H) > 2:
    cnt = 3
    while dp[N] == 0:
        dp[cnt] = min((dp[cnt-1] + abs(H[cnt-1] - H[cnt-2])), dp[cnt-2] + abs(H[cnt-1] - H[cnt-3]))
        cnt += 1
else:
    dp[N] = abs(H[0] - H[1])

print(dp[N])