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

Fixed submission:
N = int(input())

def ame(N):
    total = 0
    for i in range(1, N + 1):
        total += i
    return total
    
print(ame(N))

Buggy submission (verdict: Runtime Error):
# https://atcoder.jp/contests/abc043/tasks/abc043_a
N = int(input())

print(ame(N))

def ame(N):
    sum = 0
    for i = 1 To N:
        sum += i
Problem p04043 (python)

Fixed submission:
inputs = [int(i) for i in input().split()]
inputs.sort()

if inputs == [5,5,7]:
    print("YES")
else:
    print("NO")

Buggy submission (verdict: Runtime Error):
N, L = [int(i) for i in input().split()]

S = []
for s in range(0, N):
    S.append(input())
S.sort()

print(''.join(S))
Problem p02694 (python)

Fixed submission:
X=int(input())
sum=0
n=100
for i in range(10000):
    if n<X:
        n=n*1.01//1
        sum += 1
print(sum)

Buggy submission (verdict: Runtime Error):
X=int(input())
sum=0
for i in range(10000)
    if (100*((1.01)**i))<X:
        sum += 1
print(sum)
Problem p02705 (python)

Fixed submission:
R=int(input())
print(2*R*3.14)

Buggy submission (verdict: Runtime Error):
R=int(input().split())
print(2*R*3.14)
Problem p02812 (python)

Fixed submission:
N=int(input())
S=str(input())
cnt=0
for i in range(N-2):
    if S[i]=="A" and S[i+1]=="B" and S[i+2]=="C":
        cnt += 1
print(cnt)

Buggy submission (verdict: Runtime Error):
N=int(input())
S=str(input())
cnt=0
for i in range(N):
    if S[i]=="A" and S[i+1]=="B" and S[i+2]=="C":
        cnt += 1
print(cnt)
Problem p03359 (python)

Fixed submission:
a,b=map(int,input().split())
if a<=b:
    print(a)
else:
    print(a-1)

Buggy submission (verdict: Runtime Error):
a,b,x=map(int,input().split())
x=0
for i in range(a):
    for j in range(b):
        if i==j:
            x += 1
print(x)
Problem p03632 (python)

Fixed submission:
A,B,C,D = map(int, input().split())
x=min(B,D)-max(A,C)
if x>0:
    print(x)
else:
    print("0")

Buggy submission (verdict: Runtime Error):
A=input()
B=input()
C=input()
D=input()
print(int(B)-int(C) if C<B else "0")
Problem p02630 (python)

Fixed submission:
import sys
from collections import Counter
input = sys.stdin.readline


N = int(input())
alist = list(map(int, input().split()))
Q = int(input())


sumA = sum(alist)
adict = Counter(alist)

for _ in range(Q):
    b, c = map(int, input().split())

    if b not in adict:
        print(sumA)
        continue

    bnum = adict.pop(b)
    if c in adict:
        adict[c] += bnum
    else:
        adict[c] = bnum

    sumA -= bnum * (b - c)
    print(sumA)

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


N = int(input())
alist = list(map(int, input().split()))
Q = int(input())


sumA = sum(alist)
adict = Counter(alist)

for _ in range(Q):
    b, c = map(int, input().split())

    bnum = adict.pop(b)
    if c in adict:
        adict[c] += bnum
    else:
        adict[c] = bnum

    sumA -= bnum * (b - c)
    print(sumA)

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


N = int(input())
alist = list(map(int, input().split()))
Q = int(input())


sumA = sum(alist)
adict = Counter(alist)

for _ in range(Q):
    b, c = map(int, input().split())

    bnum = adict.pop(b)
    if c in adict:
        adict[c] += bnum
    else:
        adict[c] = bnum

    sumA -= bnum * (b - c)
    print(sumA)
Problem p02874 (python)

Fixed submission:
import sys
input = sys.stdin.readline

_n = int(input())
lrlist = [list(map(int, input().split())) for _ in range(_n)]
Lp, Rq = max(l for l, r in lrlist), min(r for l, r in lrlist)

st = sorted([(max(r - Lp + 1, 0), max(Rq - l + 1, 0)) for l, r in lrlist], key=lambda x: (x[0], -x[1]))
ans = max([r - l + 1 for l, r in lrlist]) + max(Rq - Lp + 1, 0)

min_b = 10 ** 9
for i in range(_n - 1):
    min_b = min(st[i][1], min_b)
    ans = max(ans, min_b + st[i + 1][0])

print(ans)

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

_n, *lrlist = map(int, open(0).read().split())
Lp, Rq = max(lrlist[::2]), min(lrlist[1::2])

st = sorted([(max(r - Lp + 1, 0), max(Rq - l + 1, 0)) for l, r in lrlist])
ans = max([r - l + 1 for l, r in lrlist]) + max(Rq - Lp + 1, 0)

for index, (a, b) in enumerate(st):
    if index:
        continue


for i in range(1, _n):
    s, t = st[:i], st[i:]
    min_b, min_a = sorted(s, key=itemgetter(1))[0][1], t[0][0]

    ans = max(min_a + min_b, ans)

print(ans)
Problem p02883 (python)

Fixed submission:
import numpy as np
import sys
input = sys.stdin.readline

_n, _k = map(int, input().split())
alist = [int(item) for item in input().split()]
flist = [int(item) for item in input().split()]


def chker(costs, diffs, max_k):
	costs = np.sort(costs)[::-1]
	diffs = np.sort(diffs)
	
	_min, _max = 0, 10 ** 12
	while _min < _max:
		_mid = (_min + _max) // 2
		cnt = costs - _mid // diffs
		if cnt[cnt > 0].sum() <= max_k:
			_max = _mid
		else:
			_min = _mid + 1


	print(_min)


chker(alist, flist, _k)

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

_n, _k = map(int, input().split())
_a = input()[:-1]
_f = input()[:-1]
alist = [item for item in _a]
flist = [item for item in _f]


def chker(costs, diffs, max_k):
    if sum(costs) <= max_k:
        print(0)

    costs.sort()
    diffs.sort(reverse=True)
    sclist = [(item1, item2, item1 * item2) for item1, item2 in zip(costs, diffs)].sort(key=lambda x:x[2], reverse=True)
    k = max_k
    while k > 0:
        k -= 1
        sclist[0][0] = sclist[0][0] - 1
        if sclist[0][0] == 0:
            sclist = sclist[1:]
        else:
            sclist[0][2] = sclist[0][0] * sclist[0][1]
            sclist.sort(key=lambda x:x[2], reverse=True)

    print(sclist[0][2])


chker(alist, flist, _k)
Problem p02778 (python)

Fixed submission:
S = input()
for i in range(len(S)):
  print('x', end="")

Buggy submission (verdict: Runtime Error):
S = input()
for i in len(S):
  print(x, end="")
Problem p02945 (python)

Fixed submission:
a,b = map(int,input().split())
print(max([a+b,a-b,a*b]))

Buggy submission (verdict: Runtime Error):
a,b = map(int,input().split())
print(max[a+b,a-b,a*b])

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

print(max(list(a+b,a-b,a*b)))
Problem p02687 (python)

Fixed submission:
N=input()

print("ABC" if N=="ARC" else "ARC")

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

print("ABC" if S=="ARC" else "ARC")
Problem p04030 (python)

Fixed submission:
S=input()

result = []
for c in list(S):
   if c == 'B' and len(result)>0:
     result.pop(-1)
   elif c== 'B':
     result = []
   else :
     result.append(c)

print("".join(result))

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

result = []
for c in list(S):
   if c == 'B' and len(result)>0:
     result.pop(-1)
   elif c== 'B':
     result = ""
   else :
     result.append(c)

print("".join(result))
Problem p02628 (python)

Fixed submission:
a,b=(int(x) for x in input().split())
num_list = list(map(int, input().split()))
num_list.sort()
ans = 0
 
for i in range(b):
  ans += num_list[i]
 
print(ans)

Buggy submission (verdict: Runtime Error):
a,b=(int(x) for x in input().split())
num_list = list(map(int, input().split())).sort()
ans = 0
 
for i in range(b):
  ans += num_list[i]
 
print(ans)

Buggy submission (verdict: Runtime Error):
a,b=(int(x) for x in input().split())
num_list = list(map(int, input().split())).sort
ans = 0

for i in range(b):
  ans += num_list[i]

print(ans)

Buggy submission (verdict: Runtime Error):
a,b=(int(x) for x in input().split())
num_list = list(map(int, input().split())).sort
ans = 0

for i in range(b):
  ans += num_list[b]

print(ans)
Problem p02910 (python)

Fixed submission:
s = input()
ans = 1

for i in range(len(s)):
  if i % 2 == 0:
    if s[i] == 'L':
      ans -= 1
  else:
    if s[i] == 'R':
      ans -= 1
     
if ans < 1:
  print("No")
else: print("Yes")

Buggy submission (verdict: Runtime Error):
s = input()
ans = 1

for i in range(len(s)):
  if i % 2 == 0:
    if s[i] != 'R' OR 'U' OR 'D':
      ans -= 1
  else:
    if s[i] != 'L' OR 'U' OR 'D':
      ans -= 1
      
if ans < 1:
  print("No")
else: print("Yes")
Problem p03085 (python)

Fixed submission:
b = str(input())

if b == "A" :
    print("T")
elif b == "T" :
    print("A")
elif b == "C" :
    print("G")
else :
    print("C")

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

if b == "A" :
    print("T")
elif b == "T" :
    print("A")
elif b == "C" :
    print("G")
else print("C")
Problem p02713 (python)

Fixed submission:
def euc(i, j):
    if i > j:
        i, j = j, i
    while j%i != 0:
        k = j - i
        if k > i:
            i, k = k, i
        j = i%k
        if j == 0:
            return(k)
        i = k
        if i > j:
            i, j = j, i
    return i


N = int(input())
sum = 0
for i in range(1, N + 1):
    for j in range(1, N + 1): 
        ij = euc(i, j)
        for k in range(1, N + 1):
            sum += euc(ij, k)
print(sum)

#print(euc(2, 3))

Buggy submission (verdict: Runtime Error):
def euc(i, j):
    if i > j:
        i, j = j, i
    while j%i != 0:
        k = abs(j - i)
        j = i%k
        i = k
        if i > j:
            i, j = j, i
    return i


N = int(input())
sum = 0
for i in range(1, N + 1):
    for j in range(1, N + 1): 
        ij = euc(i, j)
        for k in range(1, N + 1):
            sum += euc(ij, k)
print(sum)

#print(euc(9, 18))
Problem p02756 (python)

Fixed submission:
S = input()
Q = int(input())
I = 0
L = ''
R = ''
for i in range(Q):
    Query = input().split()
    if Query[0] == "1":
        I = I + 1
    else:
        if (int(Query[1]) + I) % 2 == 0:
            R = R + Query[2]
        else:
            L = L + Query[2]
L = L[::-1]
S = L + S + R

if I % 2:
    S = S[::-1]
print(S)

Buggy submission (verdict: Runtime Error):
S = input()
Q = int(input())
I = 0
for i in range(Q):
    Query = input().split()
    if Query[0] == 1:
        I = I + 1
    else:
        if (int(Query[1]) + I) % 2 == 0:
            S = S + Query[2]
        else:
            S = Query[2] + S
if I % 2:
    S = S[::-1]
print(S)
Problem p02921 (python)

Fixed submission:
S = input()
T = input()
itti = 0
for i in range(3):
    if S[i] == T[i]:
        itti = itti + 1
print(itti)

Buggy submission (verdict: Runtime Error):
N = int(input())
A = [list(map(int, input().split(" "))) for i in range(N)]
count = [0 for i in range(N)]
Ns = [N - 1 for i in range(N)]
days = 0
alert = 0

while count != Ns:
    alert = 0
    already = [0 for i in range(N)]
    days = days + 1
    for i in range(N):
        if count[i] == N - 1:
            continue
        for j in range(i, N):
            if count[j] == N - 1:
                continue
            if count[j] == N - 1:
                continue
            if j == i:
                continue
            if already[i] == 0 and already[j] == 0 and j == A[i][count[i]] - 1 and i == A[j][count[j]] - 1:
                count[i] = count[i] + 1
                count[j] = count[j] + 1
                already[i] = 1
                already[j] = 1
                alert = 1
    if alert == 0:
        print(-1)
        break
    if count == Ns:
        print(days)
Problem p03085 (python)

Fixed submission:
b = input()
if b == 'A':
	print('T')
if b == 'C':
	print('G')
if b == 'T':
	print('A')
if b == 'G':
	print('C')

Buggy submission (verdict: Runtime Error):
N, Q = map(int, input().split())
S = input()
output = []
for i in range(Q):
	l, r = map(int, input().split())
	Slr = S[l - 1:r]
	output.append(Slr.count('AC'))
for i in output:
	print(i)

Buggy submission (verdict: Runtime Error):
N, Q = map(int, input().split())
S = input()
output = []
for i in range(Q):
	l, r = map(int, input().split())
	Slr = S[l - 1:r]
	output.append(Slr[l - 1:r].count('AC'))
for i in output:
	print(i)

Buggy submission (verdict: Runtime Error):
N, Q = map(int, input().split())
S = input()
output = []
for i in range(Q):
	l, r = map(int, input().split())
	Slr = S[l - 1:r]
	output.append(Slr[l - 1:r].count('AC'))
for i in output:
	print(i)
Problem p02646 (python)

Fixed submission:
in_a = [int(x) for x in input().split(' ')]
in_b = [int(x) for x in input().split(' ')]
t = int(input())

result = False

p_a = in_a[0]
p_b = in_b[0]
m_a = in_a[1]
m_b = in_b[1]
end_p_a = m_a*t
end_p_b = m_b*t

diff_s = abs(p_a-p_b)

if end_p_a-end_p_b>=diff_s:
  print('YES')
else:
  print('NO')

Buggy submission (verdict: Runtime Error):
in_a = [int(x) for x in input().split(' ')]
in_b = [int(x) for x in input().split(' ')]
t = int(input())

result = False

p_a = in_a[0]
p_b = in_b[0]
m_a = in_a[1]
m_b = in_b[1]

def to_right():
  for i in range(t):
    if m_a <= m_b:
      break
    p_a += m_a
    p_b += m_b

def to_left():
  for i in range(t):
    if m_a <= m_b:
      break
    p_a -= m_a
    p_b -= m_b

if p_a < p_b:
  to_right()
else:
  to_left()

if result:
  print('YES')
else:
  print('NO')
Problem p02657 (python)

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

Buggy submission (verdict: Runtime Error):
A, B = input().split()
print(A*B)

Buggy submission (verdict: Runtime Error):
A, B = input().split()
return A*B
Problem p03456 (python)

Fixed submission:
num = int(''.join(input().split()))

for i in range(1, num):
    if num / i == i:
        print('Yes')
        exit()

print('No')

Buggy submission (verdict: Runtime Error):
num = int(''.join(input().split()))

for i in range(num):
    if num / i == i:
        print('Yes')
        exit()

print('No')
Problem p03493 (python)

Fixed submission:
x = input()

counter = 0
for i in x:
    if i == '1':
        counter += 1

print(counter)

Buggy submission (verdict: Runtime Error):

x = input()

counter = 0

a = [counter +=1 for i in x if i == '1']

print(counter)
Problem p03494 (python)

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

counter = 0

while all(number % 2 == 0 for number in numbers):
    numbers = [number / 2 for number in numbers]
    counter += 1

print(counter)

Buggy submission (verdict: Runtime Error):

N = int(input())

numbers = list(map(int, input()))
counter = 0

while all(number % 2 == 0 for number in numbers):
    numbers = [number / 2 for number in numbers]
    counter += 1

print(counter)
Problem p03760 (python)

Fixed submission:
O, E = [input() for _ in range(2)]
E += " "

for i in range(len(O)):
    print(O[i], end='')
    print(E[i], end='')

Buggy submission (verdict: Runtime Error):
O, E = [input() for _ in range(2)]
E += " "

length = max(len(O), len(E))

for i in range(length):
    print(O[i], end='')
    print(E[i], end='')

Buggy submission (verdict: Runtime Error):
O, E = [input() for _ in range(2)]
E += ""

length = max(len(O), len(E))

for i in range(length):
    print(O[i], end='')
    print(E[i], end='')
Problem p04001 (python)

Fixed submission:
def dfs(i, formula):
    if i + 1 == num_digits:
        return sum(list(map(int, formula.split("+"))))

    return dfs(i + 1, formula + "+" + s[i + 1]) + dfs(i + 1, formula + s[i + 1])


s = input()
num_digits = len(s)

print(dfs(0, s[0]))

Buggy submission (verdict: Runtime Error):
def dfs(formula, index):
    if index + 1 == max_index:
        return sum(list(map(int, formula.split("+"))))

    return dfs(formula + "+" + S[index], index + 1) + dfs(formula + S[index], index)


S = input()
max_index = len(S)
dfs(S[0], 0)

Buggy submission (verdict: Runtime Error):
def dfs(i, formula):
    if i + 1 == num_digits:
        return sum(list(map(int, formula.split("+"))))

    return sum(dfs(i + 1, formula + "+" + s[i + 1]), dfs(i + 1, formula + s[i + 1]))


s = input()
num_digits = len(s)

print(dfs(0, s[0]))

Buggy submission (verdict: Runtime Error):
number = int(input())
num_digits = len(str(number))


def dfs(i, sum_number):
    if i == num_digits:
        return sum_number
    dfs(i + 1, sum_number)
    dfs(i + 1, sum_number + str(number)[i])


print(dfs(0, 0))
Problem p02639 (python)

Fixed submission:
X=list(map(int,input().split()))
print(X.index(0)+1)

Buggy submission (verdict: Runtime Error):
N=int(input())
A=list(map(int,input().split()))
ans=0
dup = [x for x in set(A) if A.count(x) > 1]

A=set(A)
for i in range(len(dup)):
    A.remove(dup[i])


A=sorted(set(A))

if A==0:
    print(0)
else:
    for i in range(len(A)):
        k=0
        for j in range(i):
            if A[i]%A[j]==0:
                k=1
                break


        if k==0:
            
            ans+=1
    print(ans)
Problem p02645 (python)

Fixed submission:
S=str(input())
print(S[0:3])

Buggy submission (verdict: Runtime Error):
import math

A,V= map(int, input().split())
B,W= map(int, input().split())
T=int(input())
ans=0

if A>B:
    C=A
    A=B
    B=C

if A==B:
    print("YES")
else:

    if V<=W:
        print("NO")
    else:
        x=(1-(A-B)/(V-W))
        xint=math.floor(1-(A-B)/(V-W))
        A=A+(xint-1)*V
        B=B+(xint-1)*W

        if (xint-1)>T:
            print("NO")
        else:
            
            for i in range (3):
                if A<B:
                    A=A+V
                    B=B+W
                else:
                    A=A-V
                    B=B-W
                if xint+i>T:
                    ans=0
                    break
                if A==B:
                    ans=1
                    break
                
            print("YES" if ans==1 else "NO")
Problem p02658 (python)

Fixed submission:
N = int(input())
A = list(map(int, input().split()))
ans=1
i=0
while ans<=1000000000000000000 and i<N:
    ans=ans*A[i]
    i+=1

if A.count(0)>0:
    print(0)
else:
    print(ans if ans<=1000000000000000000 else "-1")

Buggy submission (verdict: Runtime Error):
N = int(input())
A = list(map(int, input().split()))
ans=1
i=0
while ans<=1000000000000000000:
    ans=ans*A[i]
    i+=1

if A.count(0)>0:
    print(0)
else:
    print(ans if ans<=1000000000000000000 else "-1")
Problem p02705 (python)

Fixed submission:
import math
a = int(input())
print(2*a*math.pi)

Buggy submission (verdict: Runtime Error):
N = int(input()) 
A=list(map(int,input().split())) 
i=0 
s=[] 
for i in range(N): 
    s.append(0)  
    s[i]=A.count(i+1) 
    print(s[i])

Buggy submission (verdict: Runtime Error):
N = int(input()) 
A=list(map(int,input().split())) 
i=0 
s=[] 
for i in range(N): 
    s.append(0) 
for i in range(N): 
    s[i]=A.count(i+1) 
for i in range(N): 
    print(s[i])

Buggy submission (verdict: Runtime Error):
N = int(input()) 
A=list(map(int,input().split())) 
i=0 
s=[] 
for i in range(N): 
    s.append(0) 
for i in range(N): 
    s[i]=A.count(i+1) 
for i in range(N): 
    print(s[i])
Problem p04043 (python)

Fixed submission:
a=list(sorted(map(int,input().split()))[::-1])
if a[0]==7 and a[1]==5 and a[2]==5 :
    print("YES")
else:
    print("NO")

Buggy submission (verdict: Runtime Error):
a=[]
N,L=map(int,input().split())
for _ in range (N):
    a.append(str(input()))
    a=sorted(a)
print(*a,sep='')
Problem p02630 (python)

Fixed submission:
N = int(input())
A = list(map(int, input().split()))
Q = int(input())
BC = [list(map(int, input().split())) for i in range(Q)]

def calc(A):
    ans = 0
    for i in range(len(A)):
        ans += A[i] * (i + 1)

    return ans

VALUE = [0 for i in range(100000)]

for i in range(N):
    VALUE[A[i] - 1] += 1

ANS = []
ANS.append(calc(VALUE))

for i in range(Q):
    VALUE[BC[i][1] - 1] += VALUE[BC[i][0] - 1]
    ANS.append(ANS[i] + (BC[i][1] - BC[i][0]) * VALUE[BC[i][0] - 1])
    VALUE[BC[i][0] - 1] = 0

for i in range(1, Q + 1):
    print(ANS[i])

Buggy submission (verdict: Runtime Error):
N = int(input())
A = list(map(int, input().split()))
Q = int(input())
BC = [list(map(int, input().split())) for i in range(Q)]

def calc(A):
    ans = 0
    for i in range(len(A)):
        ans += A[i] * (i + 1)

    return ans



VALUE = [0 for i in range(100)]

for i in range(N):
    VALUE[A[i] - 1] += 1

for i in range(Q):
    VALUE[BC[i][1] - 1] += VALUE[BC[i][0] - 1]
    VALUE[BC[i][0] - 1] = 0
    print(calc(VALUE))
Problem p02677 (python)

Fixed submission:
import math

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

theta = (H * 30 - M * 5.5) * math.pi / 180

ans = math.sqrt(A * A + B * B - 2 * A * B * math.cos(theta))

print(ans)

Buggy submission (verdict: Runtime Error):
import math

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

theta = (H * 30 - M * 9.5) * math.pi / 180

ans = math.sqrt(A * A + B * B - 2 * A * B * math.cos(theta))

print(ans)
~                                                                                                                       ~                                                                                                                       ~                                                                                                                       ~                                                                                                                       ~
Problem p02684 (python)

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

place = 1
road = [0 for i in range(N)]
cycle = 0

road[0] = 1

while K != 0:
    place = A_i[place - 1]
    K -= 1
    if road[place - 1] == 1:
        loop_place = place
        break
    road[place - 1] = 1

while K != 0:
    loop_place = A_i[loop_place - 1]
    cycle += 1

    if place == loop_place:
        break

if cycle != 0:
    K = K % cycle

while K != 0:
    place = A_i[place - 1]
    K -= 1

print(place)

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

place = 1
road = [0 for i in range(N)]
cycle = 0

road[0] = 1

while K != 0:
    place = A_i[place - 1]
    K -= 1

    if road[place - 1] == 1:
        loop_place = place
        break
    road[place - 1] = 1

while K != 0:
    loop_place = A_i[loop_place - 1]
    cycle += 1

    if place == loop_place:
        break

K = K % cycle

while K != 0:
    place = A_i[place - 1]
    K -= 1

print(place)

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

place = 1
road = [0 for i in range(N)]
cycle = 0

road[0] = 1

while K != 0:
    place = A_i[place - 1]
    K -= 1

    if road[place - 1] == 1:
        loop_place = place
        break
    road[place - 1] = 1

while 1:
    loop_place = A_i[loop_place - 1]
    cycle += 1

    if place == loop_place:
        break

K = K % cycle

while K != 0:
    place = A_i[place - 1]
    K -= 1

print(place)

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

place = 1
road = []
cycle = 0

while K != 0:
    road.append(place)
    place = A_i[place - 1]
    K -= 1

    if place in road:
        loop_place = place
        break

while 1:
    loop_place = A_i[loop_place - 1]
    cycle += 1

    if place == loop_place:
        break

K = K % cycle

while K != 0:
    place = A_i[place - 1]
    K -= 1

print(place)

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

place = 1
road = []
cycle = 0
begin = 0

while K != 0:
    road.append(place)
    place = A_i[place - 1]
    K -= 1

    if place in road:
        cycle = len(road) - road.index(place)
        begin = road.index(place)
        break

K = begin + (K - begin) % cycle

while K !=0:
    place = A_i[place - 1]
    K -= 1

print(place)
Problem p02924 (python)

Fixed submission:
N = int(input())

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

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

if N == 1:
    print(0)

else:
    print(int((N / 2) * (N - 1))