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

Fixed submission:
from copy import deepcopy
N, M = map(int, input().split())
INF = 10**9+7
graph = [[INF for _ in range(N)] for l in range(N)]

for i in range(M):
  a, b, c = map(int, input().split())
  a -= 1
  b -= 1

  graph[b][a] = c
  graph[a][b] = c

newGraph = deepcopy(graph)

for k in range(N):
  for i in range(N):
    for j in range(N):
      newGraph[i][j] = min(newGraph[i][j], newGraph[i][k] + newGraph[k][j])

res = 0
for (i, row) in enumerate(newGraph):
  for (j, weight) in enumerate(row):
    if graph[i][j] != weight and graph[i][j] != INF:
      res += 1
print(res//2)

Buggy submission (verdict: Runtime Error):
from copy import deepcopy
N, M = map(int, input().split())
graph = [[10000 for _ in range(N)] for l in range(N)]

for i in range(M):
  a, b, c = map(int, input().split())
  a -= 1
  b -= 1

  graph[b][a] = c
  graph[a][b] = c

newGraph = deepcopy(graph)

for k in range(N):
  for i in range(N):
    for j in range(N):
      graph[i][j] = min(graph[i][j], graph[i][k] + graph[k][j])

res = 0
for (i, row) in enumerate(newGraph):
  for (j, weight) in row:
    if (graph[i][j] != weight):
      res += 1

print(res/2)
Problem p02683 (python)

Fixed submission:
from itertools import combinations

N, M, X = map(int, input().split())
skill = [0] * M
N_list = []
C_sum = 0
all_list = [0] * (M+1)

res_list = 0
for i in range(N):
  list_ = list(map(int, input().split()))
  N_list.append(list_)
  all_list = [all_list[i]+list_[i] for i in range(M+1)]

result = []  
for i in range(1, N+1):
  ref = list(combinations(N_list, i))
  for j in range(len(ref)):
    sums = [0] * (M+1)
    for k in range(i):
      sums = [sums[l]+ref[j][k][l] for l in range(M+1)]
    result.append(sums)
kekka = []
for i in range(len(result)):
  if all(result[i][j]>=X for j in range(1, M+1)):
    kekka.append(result[i][0])
if kekka != []:
  print(min(kekka))
else:
  print(-1)

Buggy submission (verdict: Runtime Error):
from itertools import combinations

N, M, X = map(int, input().split())
skill = [0] * M
N_list = []
C_sum = 0
all_list = [0] * (M+1)

res_list = 0
for i in range(N):
  list_ = list(map(int, input().split()))
  N_list.append(list_)
  all_list = [all_list[i]+list_[i] for i in range(M+1)]
if all(all_list[j] < X for j in range(1, M+1)):
  print(-1)
  exit()
result = []  
for i in range(1, N+1):
  ref = list(combinations(N_list, i))
  for j in range(len(ref)):
    sums = [0] * (M+1)
    for k in range(i):
      sums = [sums[l]+ref[j][k][l] for l in range(M+1)]
    result.append(sums)
kekka = []
for i in range(len(result)):
  if all(result[i][j]>=X for j in range(1, M+1)):
    kekka.append(result[i][0])
print(min(kekka))
Problem p02690 (python)

Fixed submission:
X = int(input())
A = [(i**5) for i in range(0, 1000)]
res = []
for i in range(len(A)):
  a = A[i]
  for j in range(len(A)):
    b = -A[j]
    cal = a - b
    cal2 = a + b
    if cal == X:
      print(i, -j)
      exit()
    elif cal2 == X:
      print(i, j)
      exit()

Buggy submission (verdict: Runtime Error):
X = int(input())
A = [(2 * i + 1) for i in range(0, 1000)]


res = []
if X % 2 == 0:
  for i in range(len(A)):
    a = A[i]
    for j in range(len(B)):
      b = -A[j] - 1
      cal = a ** 5 - b ** 5
      if cal == X:
        print(a, b)
        exit()
else:
  for i in range(len(A)):
    a = A[i] - 1
    for j in range(len(B)):
      b = -A[j] - 1
      cal = a ** 5 - b ** 5
      if cal == X:
        print(a, b)
        exit()

Buggy submission (verdict: Runtime Error):
X = int(input())
A = [i for i in range(0, 100)]
B = [-i for i in range(0, 100)]
res = []
for i in range(len(A)):
  a = A[i]
  for j in range(len(B)):
    b = B[j]
    cal = a ** 5 - b ** 5
    if cal == X:
      res.append([a, b])
print(' '.join(map(str, res[0])))
Problem p02719 (python)

Fixed submission:
N, K = map(int, input().split())
cand1 = N % K
cand2 = K - (N % K)
print(min(cand1, cand2))

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

if N % K == 0:
  print(0)

if N > K:
  b = N % K
  print(int(K/b))

res = [N]
if N < K:
  while True:
    res.append(abs(N - K))
    N = abs(N - K)
    if N in res:
      break
print(min(res))
Problem p02742 (python)

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

if (H*W) % 2 == 0:
  if H == 1 or W == 1:
    res = 1
  else:
    res = int(H * W / 2)
else:
  if H == 1 or W == 1:
    res = 1
  else:
    res =  int(H * (W//2) + int(H/2) + 1)
print('{0:d}'.format(res))

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

if W % 2 == 0:
  res = H * W / 2
else:
  res =  H * (W//2) + int(H/2) + 1
print('{0:d}'.format(res))
Problem p03086 (python)

Fixed submission:
S = list(input())
S.append('')
res = []
count = 0
for i in S:
  if i in ['A', 'T', 'G', 'C']:
    count += 1
  else:
    res.append(count)
    count = 0
print(max(res))

Buggy submission (verdict: Runtime Error):
S = list(input())
res = []
count = 0
for i in S:
  if i in ['A', 'T', 'G', 'C']:
    count += 1
  else:
    res.append(count)
    count = 0
print(max(res))
Problem p02618 (python)

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

d=int(input().rstrip())
c=[int(i) for i in input().split()]
for _ in range(d):
    s=[int(i) for i in input().split()]
    print(s.index(max(s))+1)

Buggy submission (verdict: Runtime Error):
import sys
#sys.setrecursionlimit(10**6)
input=sys.stdin.readline

d=int(input().rstrip())
c=[int(i)for i in input().split()]
s=[[int(i)for i in input().split()]for _ in range(d)]
last=[0]*26
for i in range(d):
    now=[s[i][j]-(c[j]*(i-last[j]))for j in range(26)]
    #print(now)
    kouho=now.index(max(now))+1
    print(kouho)
    last[kouho]=i
    #print(last)

Buggy submission (verdict: Runtime Error):
import sys
sys.setrecursionlimit(10**6)
input=sys.stdin.readline

d=int(input().rstrip())
c=[int(i)for i in input().split()]
s=[[int(i)for i in input().split()]for _ in range(d)]
last=[1]*26
for i in range(1,d+1):
    now=[s[i-1][j]-(c[j]*(i-last[j]))for j in range(26)]
    kouho=now.index(max(now))+1
    print(kouho)
    last[kouho]=i
Problem p02952 (python)

Fixed submission:
import os,re
from collections import Counter,deque
from operator import itemgetter
from itertools import accumulate,combinations
from sys import stdin,setrecursionlimit
from copy import deepcopy
setrecursionlimit(10**6)

n=int(input())
cnt=0
for i in range(1,n+1):
    if len(str(i))%2==1:
        cnt+=1
print(cnt)

Buggy submission (verdict: Runtime Error):
import os,re
from collections import Counter,deque
from operator import itemgetter
from itertools import accumulate,combinations
from sys import stdin,setrecursionlimit
from copy import deepcopy
import pysnooper
setrecursionlimit(10**6)

n=int(input())
cnt=0
for i in range(1,n+1):
    if len(str(i))%2==1:
        cnt+=1
print(cnt)
Problem p02995 (python)

Fixed submission:
from fractions import gcd

def lcm(n,m):
    return (n*m)//gcd(n,m)

def main():
    a,b,c,d=map(int,input().split())
    num=b-a+1
    moda1=(a-1)//c
    moda2=(a-1)//d
    moda3=(a-1)//(lcm(c,d))
    modat=moda1+moda2-moda3
    modb1=b//c
    modb2=b//d
    modb3=b//(lcm(c,d))
    modbt=modb1+modb2-modb3
    mod=modbt-modat
    return num-mod

print(main())

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

def lcm(n,m):
    return (n*m)//gcd(n,m)

def main():
    a,b,c,d=map(int,input().split())
    num=b-a+1
    moda1=(a-1)//c
    moda2=(a-1)//d
    moda3=(a-1)//(lcm(c,d))
    modat=moda1+moda2-moda3
    modb1=b//c
    modb2=b//d
    modb3=b//(lcm(c,d))
    modbt=modb1+modb2-modb3
    mod=modbt-modat
    return num-mod

print(main())
Problem p03059 (python)

Fixed submission:
a,b,t=map(int,input().split())
cnt=0
for i in range(a,t+1,a):
    cnt+=b
print(cnt)

Buggy submission (verdict: Runtime Error):
a,b,t=map(int,input().split())
cnt=0
for i in range(1,t+0.5,a):
    cnt+=b
print(cnt)
Problem p03061 (python)

Fixed submission:
from fractions import gcd
n=int(input())
a=list(map(int,input().split()))+[0]
left=[0]*(n+1)
right=[0]*(n+1)
for i in range(1,n):
    left[i]=gcd(left[i-1],a[i-1])
for i in range(n,0,-1):
    right[i-1]=gcd(right[i],a[i])
ans=[gcd(right[i],left[i]) for i in range(n)]
print(max(ans))

Buggy submission (verdict: Runtime Error):
from fractions import gcd
n=int(input())
a=list(map(int,input().split()))
left=right=[0]*n
for i in range(1,n):
    left[i]=gcd(left[i-1],a[i-1])
for i in range(n-1)[::-1]:
    right[i]=gcd(right[i+1],a[i+1])
ans=[gcd(x[i],y[i]) for i in range(n)]
print(max(ans))
Problem p03069 (python)

Fixed submission:
n=int(input())
s=input()
r=s.count(".")
a=r
for i in range(n):
  if s[i]=="#":r+=1
  else:r-=1
  a=min(a,r)
print(a)

Buggy submission (verdict: Runtime Error):
n=int(input())
s=input()
r=S.count(".")
a=r
for i in range(n):
  if s[i]=="#":r+=1
  else:r-=1
  a=min(a,r)
print(a)
Problem p03106 (python)

Fixed submission:
a,b,k=map(int,input().split())
inte=[];mini=min(a,b);j=1
for i in range(1,mini+1):
  if a%i==0 and b%i==0:
    inte.append(i)
inte.sort(reverse=True)
print(inte[k-1])

Buggy submission (verdict: Runtime Error):
a,b,k=map(int,input().split())
m=max(a,b)
ans=[]
for i in range(1,m):
  if a%i==0 and b%i==0:
    ans.append(i)
ans.reverse()
print(ans[k-1])
Problem p03150 (python)

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

s=input().rstrip()
n=len(s)
t="keyence"
for i in range(n):
    for j in range(i,n):
        if s[:i]+s[j:]==t:
            print("YES")
            exit()
print("NO")

Buggy submission (verdict: Runtime Error):
import sys
sys.setrecursionlimit(10**6)
input=sys.stdin.readline

s=input().rstrip()
t="keyence"
i,j=0,0
while len(s)>i:
    if s[i]==t[j]:
        j+=1
    i+=1
print("YES"if j==7 else "NO")
Problem p03193 (python)

Fixed submission:
n,h,w=map(int,input().split())
cnt=0
for i in range(n):
  a,b=map(int,input().split())
  if h<=a and w<=b:
    cnt+=1
print(cnt)

Buggy submission (verdict: Runtime Error):
n,h,w=map(int,input().split())
cnt=0
for i in range(n):
  a,b=map(int,input().split)
  if h<=a and w<=b:
    cnt+=1
print(cnt)
Problem p03355 (python)

Fixed submission:
s=input()
k=int(input())
cnt=[]
for i in range(len(s)):
    for j in range(min(len(s)-i,k)):
        t=s[i:i+j+1]
        if t not in cnt:
            cnt.append(t)
print(sorted(cnt)[k-1])

Buggy submission (verdict: Runtime Error):
s=input()
k=int(input())
c=[]
for i in range(len(s)):
    for j in range(min(len(s)-i,k)):
        t=s[i:i+j+1]
        if t not in cnt:
            c.append(t)
print(sorted(c)[k-1])
Problem p03389 (python)

Fixed submission:
s=list(map(int,input().split()))
a=max(s)*3-sum(s)
if a%2==1:
    a+=3
print(a//2)

Buggy submission (verdict: Runtime Error):
s=list(map(int,input().split()))
a=max(s)*3-sum(s)
if a%2==1
    a+=3
print(a//2)
Problem p03425 (python)

Fixed submission:
n=int(input())
m=a=r=c=h=0
for i in range(n):
    s=input()
    if s[0]=='M':
        m+=1
    elif s[0]=='A':
        a+=1
    elif s[0]=='R':
        r+=1
    elif s[0]=='C':
        c+=1
    elif s[0]=='H':
        h+=1
print(m*a*r+m*a*c+m*a*h+m*r*c+m*r*h+m*c*h+a*r*c+a*r*h+a*c*h+r*c*h)

Buggy submission (verdict: Runtime Error):
n=int(input())
m=a=r=c=h=0
ls
for i in range(n):
    s=input()
    if s[0]=='M':
        m+=1
    elif a[0]=='A':
        a+=1
    elif a[0]=='R':
        r+=1
    elif a[0]=='C':
        c+=1
    elif a[0]=='H':
        h+=1
print(m*a*r+m*a*c+m*a*h+m*r*c+m*r*h+m*c*h+a*r*c+a*r*h+a*c*h+r*c*h)
Problem p03633 (python)

Fixed submission:
from fractions import gcd
a=1
for _ in[0]*int(input()):
    t=int(input())
    a*=t//gcd(a,t)
print(a)

Buggy submission (verdict: Runtime Error):
from fractions import gcd
def lcm(a,b):
    return a*b//gcd(a,b)
n=int(input())
s=1
for i in range(n):
    t=int(input())
    s=lcm(a,t)
print(s)

Buggy submission (verdict: Runtime Error):
from fractions import gcd
def lcm(a,b):
    return a*b//gcd(a,b)
n=int(input())
s=1
for i in range(n):
    t=int(input())
    s=lcm(a,t)
Problem p03699 (python)

Fixed submission:
n=int(input())
s=[];ans=0
for i in range(n):
  a=int(input())
  if a%10!=0:
    s.append(a)
  ans+=a
s.sort()
if ans%10==0:
  if s:
    ans-=s[0]
  else:
    ans=0
print(ans)

Buggy submission (verdict: Runtime Error):
import sys
n=int(input())
s=[]
for i in range(n):
  s.append(int(input()))
s.sort()
sm=sum(s)
if sm%10!=0:
  print(sm)
  sys.exit()
while 1:
  a=s.pop(0)
  t=sum(s)
  if t%10!=0:
    print(t)
    sys.exit()
Problem p02574 (python)

Fixed submission:
n = int(input())
a = list(map(int,input().split()))
a.sort()
dp = [0 for i in range(a[-1])]
p = [0 for i in range(a[-1])]
for i in range(n):
    p[a[i]-1] += 1
ans = 1
for i in range(2,a[-1]+1):
    if dp[i-1] == 1:
        continue
    u = 0
    k = 1
    while i*k <= a[-1]:
        dp[i*k-1] = 1
        if p[i*k-1] != 0:
            u += p[i*k-1]
        k += 1
    if u == n:
        ans = -1
    elif u > 1:
        ans = min(ans,0)
if ans == 1:
    print('pairwise coprime')
elif ans == 0:
    print('setwise coprime')
elif a[0] == 1:
    print('setwise coprime')
else:
    print('not coprime')

Buggy submission (verdict: Runtime Error):
n = int(input())
a = list(map(int,input().split()))
a.sort()
dp = [0 for i in range(a[-1])]
p = [0 for i in range(a[-1])]
for i in range(n):
    p[a[i]-1] = 1
ans = 1
for i in range(2,a[-1]+1):
    if dp[i-1] == 1:
        continue
    u = 0
    k = 1
    while i*k <= a[-1]:
        dp[i*k-1] = 1
        if p[i*k-1] == 1:
            u += 1
        k += 1
    if u == n:
        ans = -1
    elif u > 1:
        ans = min(ans,0)
elif ans == 1:
    print('pairwise coprime')
elif ans == 0:
    print('setwise coprime')
elif a[0] == 1:
    print('setwise coprime')
else:
    print('not coprime')
Problem p02582 (python)

Fixed submission:
s = input()
s = list(s)
ans = [0 for i in range(3)]
p = 0
for i in range(3):
    if s[i] == 'R':
        ans[p] += 1
    else:
        p += 1
print(max(ans[0],ans[1],ans[2]))

Buggy submission (verdict: Runtime Error):
r,c,k = map(int,input().split())
t = [[0 for i in range(c)] for i in range(r)]
for i in range(k):
    a,b,z = map(int,input().split())
    t[a-1][b-1] = z
dp = [[[0 for i in range(c)]for i in range(r)]for i in range(4)]
dp[0][0][0] = 0
dp[1][0][0] = t[0][0]
dp[2][0][0] = t[0][0]
dp[3][0][0] = t[0][0]
for i in range(r-1):
    dp[0][i+1][0] = dp[1][i][0]
    for j in range(1,4):
        dp[j][i+1][0] = dp[1][i][0]+t[i+1][0]
for i in range(c-1):
    dp[0][0][i+1] = 0
    for j in range(1,4):
        dp[j][0][i+1] = max(dp[1][0][i],t[0][i+1])
    for j in range(2,4):
        dp[j][0][i+1] = max(dp[2][0][i],dp[1][0][i]+t[0][i+1])
    dp[3][0][i+1] = max(dp[3][0][i],dp[2][0][i]+t[0][i+1])
for i in range(r-1):
    for j in range(c-1):
        u = max(dp[0][i+1][j],dp[3][i][j+1])
        for s in range(0,4):
            dp[s][i+1][j+1] =  u
        u = max(dp[0][i+1][j]+t[i+1][j+1],dp[1][i+1][j],dp[3][i][j+1]+t[i+1][j+1])
        for s in range(1,4):
            dp[s][i+1][j+1] = u
        u = max(dp[1][i+1][j]+t[i+1][j+1],dp[2][i+1][j],dp[3][i][j+1]+t[i+1][j+1])
        for s in range(2,4):
            dp[s][i+1][j+1] = u
        dp[3][i+1][j+1] = max(dp[2][i+1][j]+t[i+1][j+1],dp[3][i+1][j],dp[3][i][j+1]+t[i+1][j+1])
print(dp[3][r-1][c-1])

Buggy submission (verdict: Runtime Error):
def run():
    # sys.stdin.readline()
    import sys
    input = sys.stdin.readline
    r,c,k = map(int,input().split())
    t = [[0 for i in range(c)] for i in range(r)]
    for i in range(k):
        a,b,z = map(int,input().split())
        t[a-1][b-1] = z
    t = tuple(t)
    dp = [[[0 for i in range(c)]for i in range(r)]for i in range(4)]
    dp[0][0][0] = 0
    dp[1][0][0] = t[0][0]
    dp[2][0][0] = t[0][0]
    dp[3][0][0] = t[0][0]
    for i in range(r-1):
        dp[0][i+1][0] = dp[1][i][0]
        for j in range(1,4):
            dp[j][i+1][0] = dp[1][i][0]+t[i+1][0]
    for i in range(c-1):
        dp[0][0][i+1] = 0
        for j in range(1,4):
            dp[j][0][i+1] = max(dp[1][0][i],t[0][i+1])
        for j in range(2,4):
            dp[j][0][i+1] = max(dp[2][0][i],dp[1][0][i]+t[0][i+1])
        dp[3][0][i+1] = max(dp[3][0][i],dp[2][0][i]+t[0][i+1])
    for i in range(r-1):
        for j in range(c-1):
            u = max(dp[0][i+1][j],dp[3][i][j+1])
            for s in range(0,4):
                dp[s][i+1][j+1] =  u
            u = max(dp[0][i+1][j]+t[i+1][j+1],dp[1][i+1][j],dp[3][i][j+1]+t[i+1][j+1])
            for s in range(1,4):
                dp[s][i+1][j+1] = u
            u = max(dp[1][i+1][j]+t[i+1][j+1],dp[2][i+1][j],dp[3][i][j+1]+t[i+1][j+1])
            for s in range(2,4):
                dp[s][i+1][j+1] = u
            dp[3][i+1][j+1] = max(dp[2][i+1][j]+t[i+1][j+1],dp[3][i+1][j],dp[3][i][j+1]+t[i+1][j+1])
    print(dp[3][r-1][c-1])

if __name__ == "__main__":
    run()
Problem p02675 (python)

Fixed submission:
n = input()
s = list(n)
s[-1] = int(s[-1])
if s[-1] == 2 or s[-1] == 4 or s[-1] == 5 or s[-1] == 7 or s[-1] == 9:
    print('hon')
elif s[-1] == 3:
    print('bon')
else:
    print('pon')

Buggy submission (verdict: Runtime Error):
n,m = map(int,input().split())
g = [[] for i in range(n)]
for i in range(m):
    a,b = map(int,input().split())
    a -= 1
    b -= 1
    g[a].append(b)
    g[b].append(a)
from collections import deque
d = deque([[0,0]]) # 左は今考えてる部屋、右は前の部屋
ans = [-1 for i in range(n)]
kak = [-100 for i in range(n)]
while d:
    u,v = d.popleft()
    ans[u] = v
    for j in g[u]:
        if  kak[j] == -100:
            kak[j] = 0
            d.append([j,u])
        else:
            continue
print('Yes')
for i in range(1,n):
    print(ans[i]+1)
Problem p02681 (python)

Fixed submission:
S = input()
T = input()
s = list(S)
t = list(T)
p = 1
for i in range(len(s)):
    if s[i] == t[i]:
        continue
    else:
        p = 0
if p == 1:
    print('Yes')
if p == 0:
    print('No')

Buggy submission (verdict: Runtime Error):
n,k = map(int,input().split())
a = list(map(int,input().split()))
p = a[0]
s = a[0]
g = []
q = []
for i in range(n+1):
    g.append(p)
    p = a[p-1]
g.reverse()
for i in range(n):
    if g[0] == g[i+1]:
        mod = i+1
        break
g.reverse()
for i in range(len(g)):
    if g[i] == g[i + mod]:
        d = i
        break
if k <= mod:
    for i in range(k%mod):
        q.append(s)
        s = a[s-1]
    q.reverse()
    q.append(1)
    print(q[0])
else:
    print(g[d+(k-d)%mod+2])
Problem p02684 (python)

Fixed submission:
n,k = map(int,input().split())
a = list(map(int,input().split()))
p = a[0]
s = a[0]
g = [1]
q = []
for i in range(n+1):
    g.append(p)
    p = a[p-1]
g.reverse()
for i in range(n):
    if g[0] == g[i+1]:
        mod = i+1
        break
g.reverse()
for i in range(len(g)):
    if g[i] == g[i + mod]:
        d = i
        break
if k <= n:
    for i in range(k):
        q.append(s)
        s = a[s-1]
    q.reverse()
    print(q[0])
else:
    print(g[d+(k-d)%mod])

Buggy submission (verdict: Runtime Error):
n,k = map(int,input().split())
a = list(map(int,input().split()))
p = a[0]
s = a[0]
g = []
q = []
for i in range(n+1):
    g.append(p)
    p = a[p-1]
for i in range(len(g)):
    if g[i] == g[i] + mod
g.reverse()
for i in range(n):
    if g[0] == g[i+1]:
        mod = i+1
        break
g.reverse()
for i in range(len(g)):
    if g[i] == g[i] + mod:
        d = i
        break
if k <= mod:
    for i in range(k%mod):
        q.append(s)
        s = a[s-1]
    q.reverse()
    q.append(1)
    print(q[0])
else:
    print(g[d+(k-d)%mod])

Buggy submission (verdict: Runtime Error):
n,k = map(int,input().split())
a = list(map(int,input().split()))
p = a[0]
s = a[0]
g = []
q = []
for i in range(n+1):
    g.append(p)
    p = a[p-1]
g.reverse()
for i in range(n):
    if g[0] == g[i+1]:
        mod = i+1
        break
for i in range(k%mod):
    q.append(s)
    s = a[s-1]
q.reverse()
print(q[0])

Buggy submission (verdict: Runtime Error):
n,k = map(int,input().split())
a = list(map(int,input().split()))
p = a[0]
s = a[0]
g = []
q = []
for i in range(n+1):
    g.append(p)
    p = a[p-1]
g.reverse()
for i in range(n):
    if g[0] == g[i+1]:
        mod = i+1
        break
for i in range(k%3):
    q.append(s)
    s = a[s-1]
print(q[-1])
Problem p02691 (python)

Fixed submission:
import collections

n=int(input())
arr=list(map(int,input().split()))
ans=0
cnt=collections.defaultdict(int)
for i in range(1,n+1):
	ans+=cnt[i-arr[i-1]] #すでに見た要素について、i-Aiと等しいものの個数を数える
	cnt[i+arr[i-1]]+=1 #i+Aiを付け加える
print(ans)

Buggy submission (verdict: Runtime Error):
n = int(input())
a = list(map(int,input().split()))
p = []
q = []
d = collections.defaultdict(int)
e = collections.defaultdict(int)
for i in range(n):
    p.append(a[i]+i+1)
for i in range(n):
    q.append(-a[i]+i+1)
ans = 0
for i in range(n):
    d[p[i]] += 1
    e[q[i]] += 1
for i in d.keys():
    ans += d[i]*e[i]
print(ans)
Problem p02696 (python)

Fixed submission:
a,b,n = map(int,input().split())
ans = 0
ans = max(int(a*n/b) - a*int(n/b),ans)
if b == 1:
    print(0)
else:
    for k in range(1,n//(b-1)+1):
        ans = max(int(a*(k*b-1)/b) - a*int((k*b-1)/b),ans)
        if ans == a:
            print(ans)
            break
    if ans != a:
        print(ans)

Buggy submission (verdict: Runtime Error):
a,b,n = map(int,input().split())
ans = 0
ans = max(int(a*n/b) - a*int(n/b),ans)
for k in range(1,n//(b-1)+1):
    ans = max(int(a*(k*b-1)/b) - a*int((k*b-1)/b),ans)
    if ans == a:
        print(ans)
        break
if ans != a:
    print(ans)

Buggy submission (verdict: Runtime Error):
a,b,n = map(int,input().split())
ans = 0
for k in range(1,min(b,n+1)):
    ans = max(int(a*k/b) - a*int(k/b),ans)
    if ans == a:
        print(ans)
        break
if ans == a:
    ans = ans
else:
    for k in range(1,n//(b-1)+1):
        ans = max(int(a*(k*b-1)/b) - a*int((k*b-1)/b),ans)
        if ans == a:
            print(ans)
            break
if ans != a:
    print(ans)

Buggy submission (verdict: Runtime Error):
a,b,n = map(int,input().split())
ans = 0
for k in range(1,n+1):
    ans = max(int(a*k/b) - a*int(k/b),ans)
    if ans == a:
        print(ans)
        break
if ans == a:
    ans = ans
else:
    for k in range(1,n//(b-1)+1):
        ans = max(int(a*(k*b-1)/b) - a*int((k*b-1)/b),ans)
        if ans == a:
            print(ans)
            break
if ans != a:
    print(ans)