Harryxun/testdata huggingface dataset:
Buggy python submission (verdict: Runtime Error):

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

L = [0]*(N+2)
R = [0]*(N+2)
M = [0]*(N+2)

import fractions

for i in range(1,N+1):
    L[i] = fractions.gcd(L[i-1],A[i-1])
for i in range(0,N)[::-1]:
    R[i] = fractions.gcd(R[i+1],A[i])

M = [gractions.gcd(L[i-1],R[i]) for i in range(1,N+1)]
print(max(M))

Fixed submission:
N = int(input())
A = list(map(int, input().split()))
 
L = [0]*(N+2)
R = [0]*(N+2)
 
import fractions
 
for i in range(1,N+1):
    L[i] = fractions.gcd(L[i-1],A[i-1])
for i in range(0,N)[::-1]:
    R[i] = fractions.gcd(R[i+1],A[i])
 
M = [fractions.gcd(L[i-1],R[i]) for i in range(1,N+1)]
print(max(M))

Buggy python submission (verdict: Runtime Error):
N = int(input())
A = list(map(int, input().split()))
G = []

for i in range(N):
    for j in range(N):
        if i == j:
            pass
        else:
            G.append(gcd(A[i], A[j]))
            

print(max(G))

Fixed submission:
N = int(input())
A = list(map(int, input().split()))
 
L = [0]*(N+2)
R = [0]*(N+2)
 
import fractions
 
for i in range(1,N+1):
    L[i] = fractions.gcd(L[i-1],A[i-1])
for i in range(0,N)[::-1]:
    R[i] = fractions.gcd(R[i+1],A[i])
 
M = [fractions.gcd(L[i-1],R[i]) for i in range(1,N+1)]
print(max(M))

Buggy python submission (verdict: Runtime Error):
N = int(input())
A = list(map(int, input().split()))
max_gcd = 1

import math

for i in range(N):
    for j in range(N):
        if i == j:
            pass
        else:
            if math.gcd(A[i], A[j]) > max_gcd:
                max_gcd = math.gcd(A[i], A[j])

print(max_gcd)

Fixed submission:
N = int(input())
A = list(map(int, input().split()))
 
L = [0]*(N+2)
R = [0]*(N+2)
 
import fractions
 
for i in range(1,N+1):
    L[i] = fractions.gcd(L[i-1],A[i-1])
for i in range(0,N)[::-1]:
    R[i] = fractions.gcd(R[i+1],A[i])
 
M = [fractions.gcd(L[i-1],R[i]) for i in range(1,N+1)]
print(max(M))
Buggy python submission (verdict: Runtime Error):
N = int(input())
S = list(str(input()))
K = int(input())

for i in range(N):
    if S[i] == S[K]:
        pass
    else:
        S[i] = '*'
print(''.join(map(str, S)))

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

for i in range(0, N):
    if S[i] == S[K-1]:
        pass
    else:
        S[i] = '*'
print(''.join(map(str, S)))
Buggy python submission (verdict: Runtime Error):
S = list(input())
N = len(S)
for i in range(N):
    if S[i] is not 'A' or 'T' or 'G' or 'C':
        S.remove(S[i])
print(len(S))

Fixed submission:
S = list(input())
N = len(S)
H = list('ATGC')
m = 0
ans = 0
for i in range(N):
    if S[i] in H:
        m += 1
        if ans < m:
            ans = m
    else:
        m = 0
print(ans)
Buggy python submission (verdict: Time Limit Exceeded):
n, q = map(int, input().split())
s = str(input())
l = []
r = []

for i in range(q):
    l_e, r_e = map(int, input().split())
    l_e -= 1
    l.append(l_e)
    r.append(r_e)

for i in range(q):
    count = 0
    for j in range(l[i], r[i] - 1):
        if s[j] == "A" and s[j+1] == "C":
            count += 1
    print(count)

Fixed submission:
n, q = map(int, input().split())
s = str(input())

count = [0] * n
for i in range(n - 1):
    if s[i:i+2] == "AC":
        count[i+1] = count[i] + 1
    else:
      count[i+1] = count[i]

for i in range(q):
    l, r = map(int, input().split())
    l -= 1
    r -= 1
    print(count[r] - count[l])

Buggy python submission (verdict: Time Limit Exceeded):
n, q = map(int, input().split())
s = str(input())
l = []
r = []

for i in range(q):
    l_e, r_e = map(int, input().split())
    l_e -= 1
    l.append(l_e)
    r.append(r_e)

for i in range(q):
    count = 0
    for j in range(l[i], r[i] - 1):
        if s[j] == "A" and s[j+1] == "C":
            count += 1
    print(count)



Fixed submission:
n, q = map(int, input().split())
s = str(input())

count = [0] * n
for i in range(n - 1):
    if s[i:i+2] == "AC":
        count[i+1] = count[i] + 1
    else:
      count[i+1] = count[i]

for i in range(q):
    l, r = map(int, input().split())
    l -= 1
    r -= 1
    print(count[r] - count[l])

Buggy python submission (verdict: Time Limit Exceeded):
N, Q = map(int, input().split())
S = list(input())
m = []
for i in range(Q):
 l, r = map(int, input().split())
 Sc = S[l-1:r]
 m = []
 for j in range(len(Sc)-1):
        if Sc[j] == 'A' and Sc[j+1] == 'C':
            m.append(1)
        else:
            m.append(0)
 print(sum(m))

Fixed submission:
n, q = map(int, input().split())
s = str(input())

count = [0] * n
for i in range(n - 1):
    if s[i:i+2] == "AC":
        count[i+1] = count[i] + 1
    else:
      count[i+1] = count[i]

for i in range(q):
    l, r = map(int, input().split())
    l -= 1
    r -= 1
    print(count[r] - count[l])
Buggy python submission (verdict: Time Limit Exceeded):
k = str(input())
d = int(input())
 
l = len(k)
 
mod = 10 ** 9 + 7
 
#less than: 1, else: 0
dp = [[[0] * 2 for _ in range(d)] for i in range(l+1)]
dp[0][0][0] = 1
 
for i in range(l):
    lim = int(k[i])
    for j in range(d):
        for num in range(10):
            dp[i+1][(j+num) % d][1] = (dp[i+1][(j+num) % d][1] + dp[i][j][1]) % mod
        for num in range(lim):
            dp[i+1][(j+num) % d][1] = (dp[i+1][(j+num) % d][1] + dp[i][j][0]) % mod
        
        dp[i+1][(j+lim) % d][0] = (dp[i+1][(j+lim) % d][0] + dp[i][j][0]) % mod
                
ans = (dp[l][0][0] + dp[l][0][1] + mod - 1) % mod
 
print(ans)

Fixed submission:
k = str(input())
d = int(input())
 
l = len(k)
 
mod = 10 ** 9 + 7
 
#less than: 1, else: 0
dp = [[[0] * 2 for _ in range(d)] for i in range(l+1)]
dp[0][0][0] = 1
 
for i in range(l):
    lim = int(k[i])
    for j in range(d):
        for num in range(10):
            dp[i+1][(j+num) % d][1] = (dp[i+1][(j+num) % d][1] + dp[i][j][1]) % mod
        for num in range(lim):
            dp[i+1][(j+num) % d][1] = (dp[i+1][(j+num) % d][1] + dp[i][j][0]) % mod
        
        dp[i+1][(j+lim) % d][0] = (dp[i+1][(j+lim) % d][0] + dp[i][j][0]) % mod
                
ans = (dp[l][0][0] + dp[l][0][1] + mod - 1) % mod
 
print(ans)
Buggy python submission (verdict: Runtime Error):
def dfs(i, total, S, remain):
    global ans
    if i == D:
        if S < G:
           use = max(remain)
           N = min(L[use-1][0], (G-S)//(100*use))
           S += 100 * N * use
           total += N
           
        if S >= G:
           ans = min(ans, total)
    else:
        dfs(i+1, total, S, remain)
        dfs(i+1, total + L[i][0], S + 100 * (i+1) * L[i][0] + L[i][1], remain - {i+1})
 
D, G = map(int, input().split())
L = [list(map(int, input().split())) for _ in range(D)]
ans = 10 ** 9
 
dfs(0, 0, 0, set(range(1, D+1)))
 
print(ans)

Fixed submission:
r = int(input())

rate = [1200, 2800, 4209]
contest = ['ABC', 'ARC', 'AGC']

for i in range(3):
    if r < rate[i]:
        break
print(contest[i])
Buggy python submission (verdict: Runtime Error):
from operator import itemgetter

n, m = map(int, input().split())
r = sorted([list(map(int, input().split())) for _ in range(m)], key = itemgetter(0))

if m == 0:
    print(0)
    exit()

last = r[1][0]
i = 1
count = 0
for i in range(m):
    if last <= r[i][0]:
        last = r[i][1]
        count += 1

print(count)

Fixed submission:
from operator import itemgetter

n, m = map(int, input().split())
r = sorted([list(map(int, input().split())) for _ in range(m)], key = itemgetter(0))


last = 0
count = 0
for i in range(m):
    if last > r[i][1]:
        last = r[i][1]
    elif last <= r[i][0]:
        count += 1
        last = r[i][1]

print(count)
Buggy python submission (verdict: Runtime Error):
x = int(input())
l = set([])
i = 1
while i < x:
    j = 2
    while j < 10:
        if i**j <= x:
            l.add(i**j)
        j += 1
    i += 1

print(max(l))

Fixed submission:
x = int(input())
l = set([1])
i = 1
while i < x:
    j = 2
    while j < 10:
        if i**j <= x:
            l.add(i**j)
        j += 1
    i += 1

print(max(l))
Buggy python submission (verdict: Runtime Error):
n = int(input())
x = list(map(int, input().split()))
xsort = sorted(x)
 
for i in range(n):
    if xsort[n//2] > x[i]
        print(xsort[2//n])
    else:
        print(xsort[n//2-1])

Fixed submission:
N = int(input())
X = list(map(int, input().split()))
Y = sorted(X)
m1 = Y[N//2]
m2 = Y[N//2-1]
 
for i in range(N):
    if m1 > X[i]:
        print(m1)  # left
    else:
        print(m2)  # right

Buggy python submission (verdict: Time Limit Exceeded):
def C(m):
    if xsort[m] > x[i]: 
        return True
    return False
 
 
n = int(input())
x = list(map(int, input().split()))

xsort = sorted(x)

for i in range(n):
    mb = 0
    lb = n
    m = (mb+lb) // 2
    for j in range(100):
        if C(m):
            lb = m
        else: 
            mb = m
    if mb < n//2:
        print(xsort[n//2])
    else:
        print(xsort[n//2-1])

Fixed submission:
N = int(input())
X = list(map(int, input().split()))
Y = sorted(X)
m1 = Y[N//2]
m2 = Y[N//2-1]
 
for i in range(N):
    if m1 > X[i]:
        print(m1)  # left
    else:
        print(m2)  # right

Buggy python submission (verdict: Time Limit Exceeded):
def C(m):
    if xsort[m] > x[i]: 
        return True
    return False


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

for i in range(n):
    mb = 0
    lb = n
    m = (mb+lb) // 2
    xsort = sorted(x)
    for j in range(100):
        if C(m):
            lb = m
        else: 
            mb = m
    if mb < n//2:
        print(xsort[n//2])
    else:
        print(xsort[n//2-1])

Fixed submission:
N = int(input())
X = list(map(int, input().split()))
Y = sorted(X)
m1 = Y[N//2]
m2 = Y[N//2-1]
 
for i in range(N):
    if m1 > X[i]:
        print(m1)  # left
    else:
        print(m2)  # right

Buggy python submission (verdict: Time Limit Exceeded):
def C(m):
    if xsort[m] > x[i]: 
        return True
    return False


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

for i in range(n):
    mb = 0
    lb = n
    m = (mb+lb) // 2
    xsort = sorted(x)
    for j in range(100):
        if C(m):
            lb = m
        else: 
            mb = m
    if mb < n//2:
        print(xsort[n//2])
    else:
        print(xsort[n//2-1])

Fixed submission:
N = int(input())
X = list(map(int, input().split()))
Y = sorted(X)
m1 = Y[N//2]
m2 = Y[N//2-1]
 
for i in range(N):
    if m1 > X[i]:
        print(m1)  # left
    else:
        print(m2)  # right

Buggy python submission (verdict: Time Limit Exceeded):
def C(m):
    if xsort[m] > x[i]: 
        return True
    return False


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

for i in range(n):
    mb = 0
    lb = n
    m = (mb+lb) // 2
    xsort = sorted(x)
    for j in range(1000):
        if C(m):
            lb = m
        else: 
            mb = m
    if mb < n//2:
        print(xsort[n//2])
    else:
        print(xsort[n//2-1])

Fixed submission:
N = int(input())
X = list(map(int, input().split()))
Y = sorted(X)
m1 = Y[N//2]
m2 = Y[N//2-1]
 
for i in range(N):
    if m1 > X[i]:
        print(m1)  # left
    else:
        print(m2)  # right
Buggy python submission (verdict: Runtime Error):
from operator import itemgetter

n = int(input())
R = [list(map(int, input().split())) for i in range(n)]
B = sorted([list(map(int, input().split())) for _ in range(n)], key = itemgetter(0))
pair = 0

for b in B:
   L = [r for r in R if r[0] < b[0] and r[1]<b[1]]
   if len(L) > 0:
       s = L[0]
       for l in L:
           if s[1] < l[1]:
               s = l
           R.remove(s)
           pair += 1
           
print(pair)

Fixed submission:
from operator import itemgetter

n = int(input())
R = [list(map(int, input().split())) for i in range(n)]
B = sorted([list(map(int, input().split())) for _ in range(n)], key = itemgetter(0))
pair = 0

for b in B:
   L = [r for r in R if r[0] < b[0] and r[1]<b[1]]
   if len(L) != 0:
       s = L[0]
       for l in L:
           if s[1] < l[1]:
               s = l
       R.remove(s)
       pair += 1
           
print(pair)
Buggy python submission (verdict: Runtime Error):
from ath import sqrt

a, b = map(str, input().split())
f = int(a+b)

for i in range(1, 101):
  if sqrt(f) / i == i:
    print('Yes')
    exit()
print('No')

Fixed submission:
a, b = map(str, input().split())
f = int(a+b)
#print(f)
 
for i in range(1, 318):
  if i ** 2 == f:
    print('Yes')
    exit()
print('No')
Buggy python submission (verdict: Runtime Error):
s = str(input())
t = str(input())
s_l =[]
for i in range(len(s)):
    s_l.append(s[i])

a = len(s) - len(t)

while a >= 0:
    insert = False
    string = True
    i = 0
    while i < len(t):
        if s[a + i] != "?" and s[a + i] != t[i]:
            string = False
            break
        i += 1
        
    if string == True:
        for i in range(len(t)):
                s_l[a+i] = t[i]
        insert = True
        break
    a -= 1

f = ""
if insert == True:
    for i in range(len(s)):
        if s_l[i] == "?":
            f += "a"
        else:
            f += s_l[i]
    print(f)
else:
    print("UNRESTORABLE")

Fixed submission:
s = str(input())
t = str(input())
s_l =[]
for i in range(len(s)):
    s_l.append(s[i])

if len(s) < len(t):
    print("UNRESTORABLE")
    exit()

a = len(s) - len(t)

while a >= 0:
    insert = False
    string = True
    i = 0
    while i < len(t):
        if s[a + i] != "?" and s[a + i] != t[i]:
            string = False
            break
        i += 1
        
    if string == True:
        for i in range(len(t)):
                s_l[a+i] = t[i]
        insert = True
        break
    a -= 1

f = ""
if insert == True:
    for i in range(len(s)):
        if s_l[i] == "?":
            f += "a"
        else:
            f += s_l[i]
    print(f)
else:
    print("UNRESTORABLE")

Buggy python submission (verdict: Runtime Error):
s = str(input())
t = str(input())
s_l =[]
for i in range(len(s)):
    s_l.append(s[i])

a = len(s) - len(t)

while a >= 0:
    insert = False
    count = 0
    for i in range(0, len(t)):
        if s[a + i] == "?" or s[a + i] == t[i]:
            count += 1
    if count == len(t):
        for i in range(len(t)):
                s_l[a+i] = t[i]
        insert = True
        break
    i -= 1

f = ""

if insert:
    for i in range(len(s)):
        if s[i] == "?":
            f += "a"
        else:
            f += s_l[i]
    print(f)
else:
    print("UNRESTORABLE")

Fixed submission:
s = str(input())
t = str(input())
s_l =[]
for i in range(len(s)):
    s_l.append(s[i])

if len(s) < len(t):
    print("UNRESTORABLE")
    exit()

a = len(s) - len(t)

while a >= 0:
    insert = False
    string = True
    i = 0
    while i < len(t):
        if s[a + i] != "?" and s[a + i] != t[i]:
            string = False
            break
        i += 1
        
    if string == True:
        for i in range(len(t)):
                s_l[a+i] = t[i]
        insert = True
        break
    a -= 1

f = ""
if insert == True:
    for i in range(len(s)):
        if s_l[i] == "?":
            f += "a"
        else:
            f += s_l[i]
    print(f)
else:
    print("UNRESTORABLE")
Buggy python submission (verdict: Runtime Error):
from collections import deque

def dfs():
    global color
    global edge
    color = [-1] * n
    edge = [[] for _ in range(n)]

    q = deque([])
    q.append(0)
    color[0] = 1
    
    while q:
        p = q.pop()
        for u in edge[p]:
            if color[u] == -1:
                color[u] = (color[p] + 1) % 2
                q.append(u)
            else:
                if color[u] == color[p]:
                    return False
    return True

n, m = map(int, input().split())

for i in range(m):
    a, b = map(int, input().split())
    a -= 1
    b -= 1
    edge[a].append(b)
    edge[b].append(a)


if dfs():
    B = 0
    W = 0
    for i in range(n):
        if color[i] == 1:
            B += 1
        else:
            W += 1
    print(B*W - m)
else:
    print(n * (n-1) // 2 - m)

Fixed submission:
from collections import deque

def dfs():
    global color
    color = [-1] * n
    q = deque([])
    q.append(0)
    color[0] = 1
    
    while q:
        p = q.pop()
        for u in edge[p]:
            if color[u] == -1:
                color[u] = (color[p] + 1) % 2
                q.append(u)
            else:
                if color[u] == color[p]:
                    return False
    return True

n, m = map(int, input().split())
edge = [[] for _ in range(n)]

for i in range(m):
    a, b = map(int, input().split())
    a -= 1
    b -= 1
    edge[a].append(b)
    edge[b].append(a)


if dfs():
    B = 0
    W = 0
    for i in range(n):
        if color[i] == 1:
            B += 1
        else:
            W += 1
    print(B*W - m)
else:
    print(n * (n-1) // 2 - m)
Buggy python submission (verdict: Runtime Error):
N = int(input())


for h in range(1, 3501):
    for n in range(1, 14000):
        if 4/N - 1/h -1/n == 0:
            continue
        else:
            w = N * h * n /(4*h*n-N*n-N*h)
            if 4/N != 1/h + 1/n + 1/w:
                continue
            elif w > 0 and w.is_integer():
                print(h, n, int(w))
                exit()

Fixed submission:
N = int(input())


for h in range(1, 3501):
    for n in range(1, 3501):
        if 4*h*n-N*n-N*h == 0:
            continue
        else:
            w = N * h * n /(4*h*n-N*n-N*h)
            if w > 0 and w.is_integer():
                print(h, n, int(w))
                exit()
Buggy python submission (verdict: Time Limit Exceeded):
n = int(input())
a = sorted(list(map(int, input().split())))

ans = 0
for i in range(n-2):
    for j in range(i+2, n):
        if a.count(a[i]) < 2:
            continue
        if a[j:n].count(a[j]) < 2:
            continue
        ans = max(ans, a[i] * a[j])

print(ans)


Fixed submission:
from collections import Counter

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

s = sorted(Counter(a).items(), reverse = True)


count = 0
ans = 0
for i, j in s:
        if count == 2:
            break
        if count == 1 and j >= 2:
            ans *= i
            count += 1
        if count == 0:
            if j >= 4:
                ans = i**2
                count += 2
            elif j >= 2:
                ans = i
                count += 1
print(ans)
Buggy python submission (verdict: Time Limit Exceeded):
n = int(input())
num = 0
count = 0
a_list = []

for i in range(n):
    a = int(input())
    a -= 1
    a_list.append(a)

if a_list.count(1) == 0:
    print(-1)
    exit()

while num != 1:
    num = a_list[num]
    count += 1

print(count)

Fixed submission:
n = int(input())
num = 0
count = 0
a_list = []

for i in range(n):
    a = int(input())
    a -= 1
    a_list.append(a)

OK = False

for i in range(n):
    num = a_list[num]
    count += 1
    if num == 1:
        OK = True
        break
if OK:    
    print(count)
else:
    print(-1)
Buggy python submission (verdict: Time Limit Exceeded):
n=int(input())
ans=0
for i in range(1,n+1):
    A=n//i
    ans+=((A**2+A)*i//2)
print(ans)

Fixed submission:
n=int(input())
ans=0
for i in range(1,n+1):
    m=n//i
    m*=i
    for j in range(i,m+1,i):
        ans+=j
print(ans)

Buggy python submission (verdict: Runtime Error):
from sympy import divisor_count
n=int(input())
ans=0
for i in range(1,n+1):
    ans+=i*(divisor_count(i))
print(ans)

Fixed submission:
n=int(input())
ans=0
for i in range(1,n+1):
    m=n//i
    m*=i
    for j in range(i,m+1,i):
        ans+=j
print(ans)

Buggy python submission (verdict: Time Limit Exceeded):
n=int(input())
ans=0
for i in range(1,n+1):
    m=n//i
    m*=i
    for j in range(i,m+1,i):
        ans+=j
print(ans)

Fixed submission:
n=int(input())
ans=0
for i in range(1,n+1):
    m=n//i
    m*=i
    for j in range(i,m+1,i):
        ans+=j
print(ans)
Buggy python submission (verdict: Runtime Error):
n=int(input())
 
#11桁で足りる
 
alp=[chr(ord('a') + i) for i in range(26)]
lst=[0]*11
 
for i in range(11):
    if n>=26**(10-i):
        a,n=divmod(n,26**(10-i))
        lst[i]=alp[a-1]
 
switch=0
for i in range(10):
    if lst[i]==0:
        if switch==0:
            lst.remove(0)
        else:
            lst[i]="a"
    else:
        switch=1
 
print("".join(lst))

Fixed submission:
alp=[chr(i) for i in range(97,123)]
n=int(input())

for i in range(1,12):
    if n>26**i:
        n-=26**i
    else:
        keta=i
        break
#その桁数の名前のなかでn番目
n-=1
lst=[]
#このnを26進数で表し、0~25にa~zをあてはめる
for i in range(keta):
    p,n=divmod(n,26**(keta-i-1))
    lst.append(alp[p])
    
print("".join(lst))

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

#11桁で足りる

alp=[chr(ord('a') + i) for i in range(26)]
lst=[0]*11

for i in range(11):
    if n>=26**(10-i):
        a,n=divmod(n,26**(10-i))
        lst[i]=alp[a]

switch=0
for i in range(10):
    if lst[i]==0:
        if switch==0:
            lst.remove(0)
        else:
            lst[i]="a"
    else:
        switch=1

print("".join(lst))

Fixed submission:
alp=[chr(i) for i in range(97,123)]
n=int(input())

for i in range(1,12):
    if n>26**i:
        n-=26**i
    else:
        keta=i
        break
#その桁数の名前のなかでn番目
n-=1
lst=[]
#このnを26進数で表し、0~25にa~zをあてはめる
for i in range(keta):
    p,n=divmod(n,26**(keta-i-1))
    lst.append(alp[p])
    
print("".join(lst))
Buggy python submission (verdict: Time Limit Exceeded):
n = int(input())
a = list(map(int, input().split()))

ans = 1

for i in range(n):
    ans *= a[i]

if ans > 10**18:
    print(-1)

else:
    print(ans)

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

ans = 1

for i in range(n):
    ans *= int(a[i])
    if ans > 10**18:
        if "0" in a:
            print(0)
            exit()
        else:
            print(-1)
            exit()

print(ans)
Buggy python submission (verdict: Runtime Error):
n, k = map(int, input().split())
a = [int(i)-1 for i in input().split()]

p = 0

if n>=k:
    for i in range(k):
        p = a[p]
    print(p+1)

else:
    lst = [-1]*n
    lst[0] = 0
    
    for i in range(1,n+1):
        p = a[p]
        if lst[p] == -1:
            lst[p] = i
        else:
            loop = i - lst[p]
            k -= lst[p]
            extra = k % loop
            break

for i in range(extra):
    p = a[p]
print(p+1)

Fixed submission:
n, k = map(int, input().split())
a = [int(i)-1 for i in input().split()]

p = 0

if n>=k:
    for i in range(k):
        p = a[p]
    print(p+1)

else:
    lst = [-1]*n
    lst[0] = 0
    
    for i in range(1,n+1):
        p = a[p]
        if lst[p] == -1:
            lst[p] = i
        else:
            loop = i - lst[p]
            k -= lst[p]
            extra = k % loop
            break

    for i in range(extra):
        p = a[p]
    print(p+1)

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

place = 0
memory = [0]

for i in range(n):
    place = a[place]-1
    if not place in memory:
        memory.append(place)
    else:
        if a[place] in memory:
            loopstart = memory.index(a[place])
            k -= loopstart
            extra = k % (len(memory) - loopstart)
            if extra == 0:
                ans = memory[-1]+1
            else:
                ans = memory[place+extra-1]+1
            break
        else:
            ans = a[place]
            break
print(ans)

Fixed submission:
n, k = map(int, input().split())
a = [int(i)-1 for i in input().split()]

p = 0

if n>=k:
    for i in range(k):
        p = a[p]
    print(p+1)

else:
    lst = [-1]*n
    lst[0] = 0
    
    for i in range(1,n+1):
        p = a[p]
        if lst[p] == -1:
            lst[p] = i
        else:
            loop = i - lst[p]
            k -= lst[p]
            extra = k % loop
            break

    for i in range(extra):
        p = a[p]
    print(p+1)
Buggy python submission (verdict: Runtime Error):
r = input()
r = r * 6.282

print(r)

Fixed submission:
r = int(input())
r = 6.28 * r
print(r)
Buggy python submission (verdict: Time Limit Exceeded):
n, k = map(int, input().split())

while n>0:
    n -= k

n = abs(n)

print(min(n, abs(n-k)))

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

n %= k

n = abs(n)

print(min(n, abs(n-k)))