Harryxun/testdata huggingface dataset:
Buggy python submission (verdict: Runtime Error):
# C - Multiple Clocks
# import math mathはatcoderでは使えない
from fractions import gcd
N = int(input())
T = [int(input()) for i in range(N)]
# 最小公倍数を求める
DP = [0]*(N-1)
DP[0] = (T[0]*T[1])//gcd(T[0],T[1])
for i in range(1,N-1):
    DP[i] = (DP[i-1]*T[i+1]) // gcd(DP[i-1],T[i+1])

print(DP[-1])

Fixed submission:
# C - Multiple Clocks
# import math mathはatcoderでは使えない
from fractions import gcd
N = int(input())
T = [int(input()) for i in range(N)]
# 最小公倍数を求める
if N == 1:
    print(T[0])
else:
    DP = [0]*(N-1)
    DP[0] = (T[0]*T[1])//gcd(T[0],T[1])
    for i in range(1,N-1):
        DP[i] = (DP[i-1]*T[i+1]) // gcd(DP[i-1],T[i+1])
    print(DP[-1])

Buggy python submission (verdict: Runtime Error):
# C - Multiple Clocks
import math
N = int(input())
T = [int(input()) for i in range(N)]
# 最小公倍数を求める
DP = [0]*(N-1)
DP[0] = (T[0]*T[1])//math.gcd(T[0],T[1])
for i in range(1,N-1):
    DP[i] = (DP[i-1]*T[i+1]) // math.gcd(DP[i-1],T[i+1])

print(DP[-1])

Fixed submission:
# C - Multiple Clocks
# import math mathはatcoderでは使えない
from fractions import gcd
N = int(input())
T = [int(input()) for i in range(N)]
# 最小公倍数を求める
if N == 1:
    print(T[0])
else:
    DP = [0]*(N-1)
    DP[0] = (T[0]*T[1])//gcd(T[0],T[1])
    for i in range(1,N-1):
        DP[i] = (DP[i-1]*T[i+1]) // gcd(DP[i-1],T[i+1])
    print(DP[-1])
Buggy python submission (verdict: Time Limit Exceeded):
# C - Cat Snuke and a Voyage
N,M = map(int, input().split())
A = [list(map(int, input().split())) for i in range(M)]
goal2 = []
goal1 = []
for i in range(M):
    if A[i][1] == N:
        goal2.append(A[i][0])
    elif A[i][0] == 1:
        goal1.append(A[i][1])
    else:
        pass

for k in range(len(goal1)):
    if goal1[k] in goal2:
        print("POSSIBLE")
        exit()
print("IMPOSSIBLE")


Fixed submission:
# C - Cat Snuke and a Voyage
N,M = map(int, input().split())
A = [list(map(int, input().split())) for i in range(M)]
goal2 = []
goal1 = []
for i in range(M):
    if A[i][1] == N:
        goal2.append(A[i][0])
    elif A[i][0] == 1:
        goal1.append(A[i][1])
    else:
        pass

if len(set(goal1)&set(goal2)) != 0:
    print("POSSIBLE")
else:
    print("IMPOSSIBLE")

Buggy python submission (verdict: Time Limit Exceeded):
# C - Cat Snuke and a Voyage
N,M = map(int, input().split())
A = [list(map(int, input().split())) for i in range(M)]
goal2 = []
goal1 = []
for i in range(M):
    if A[i][1] == N:
        goal2.append(A[i][0])
    else:
        pass

for j in range(M):
    if A[j][0] == 1:
        goal1.append(A[j][1])
    else:
        pass


for k in range(len(goal1)):
    if goal1[k] in goal2:
        print("POSSIBLE")
        exit()
print("IMPOSSIBLE")


Fixed submission:
# C - Cat Snuke and a Voyage
N,M = map(int, input().split())
A = [list(map(int, input().split())) for i in range(M)]
goal2 = []
goal1 = []
for i in range(M):
    if A[i][1] == N:
        goal2.append(A[i][0])
    elif A[i][0] == 1:
        goal1.append(A[i][1])
    else:
        pass

if len(set(goal1)&set(goal2)) != 0:
    print("POSSIBLE")
else:
    print("IMPOSSIBLE")

Buggy python submission (verdict: Time Limit Exceeded):
# C - Cat Snuke and a Voyage
N,M = map(int, input().split())
A = [list(map(int, input().split())) for i in range(M)]
goal = []
for i in range(M):
    if A[i][1] == N:
        goal.append(A[i][0])
    else:
        pass

for i in range(len(goal)):
    for j in range(M):
        if A[j][1] == goal[i]:
            if A[j][0] == 1:
                print("POSSIBLE")
                exit()
print("IMPOSSIBLE")


Fixed submission:
# C - Cat Snuke and a Voyage
N,M = map(int, input().split())
A = [list(map(int, input().split())) for i in range(M)]
goal2 = []
goal1 = []
for i in range(M):
    if A[i][1] == N:
        goal2.append(A[i][0])
    elif A[i][0] == 1:
        goal1.append(A[i][1])
    else:
        pass

if len(set(goal1)&set(goal2)) != 0:
    print("POSSIBLE")
else:
    print("IMPOSSIBLE")
Buggy python submission (verdict: Runtime Error):
 C - Splitting Pile
N = int(input())
a = list(map(int, input().split()))
sum_s = a[0]
tmp = sum(a)//2
for i in range(1,N):
    if sum_s < tmp:
        sum_s += a[i]
    else:
        break
sum_a = sum(a) - sum_s
ans = abs(sum_s - sum_a)
print(ans)

Fixed submission:
# C - Splitting Pile
N = int(input())
a = list(map(int, input().split()))
sum_s = a[0]
tmp = sum(a)
sum_a = tmp - sum_s
ans = abs(sum_s - sum_a)

for i in range(1,N):
    sum_a = tmp - sum_s
    if ans > abs(sum_s - sum_a):
        ans = abs(sum_s - sum_a)
        sum_s += a[i]
    else:
        sum_s += a[i]
print(ans)
Buggy python submission (verdict: Time Limit Exceeded):
# C - pushpush
n = int(input())
a = list(map(int, input().split()))
b = []
for i in range(n):
    if n % 2 == 0:
        if i % 2 == 0:
            b.append(a[i])
        else:
            b.insert(0, a[i])
    else:
        if i % 2 != 0:
            b.append(a[i])
        else:
            b.insert(0, a[i])

for s in b:
    print(s, end=" ")

Fixed submission:
# C - pushpush
from collections import deque
n = int(input())
a = list(map(int, input().split()))
b = deque()
for i in range(n):
    if n % 2 == 0:
        if i % 2 ==0:
            b.append(a[i])
        else:
            b.appendleft(a[i])
    else:
        if i % 2 !=0:
            b.append(a[i])
        else:
            b.appendleft(a[i])

print(*b, end=" ")

Buggy python submission (verdict: Runtime Error):
# C - pushpush
n = int(input())
a = list(map(int, input().split()))
b = []
for i in range(n):
    if n % 2 == 0:
        if i % 2 ==0:
            b.append(a[i])
        else:
            b.insert(0,a[i])
    else:
        if i % 2 !=0:
            b.append(a[i])
        else:
            b.insert(0,a[i])


print(' '.join(map(int, b)))

Fixed submission:
# C - pushpush
from collections import deque
n = int(input())
a = list(map(int, input().split()))
b = deque()
for i in range(n):
    if n % 2 == 0:
        if i % 2 ==0:
            b.append(a[i])
        else:
            b.appendleft(a[i])
    else:
        if i % 2 !=0:
            b.append(a[i])
        else:
            b.appendleft(a[i])

print(*b, end=" ")
Buggy python submission (verdict: Time Limit Exceeded):
# C - Reconciled?
N, M = map(int, input().split())
ans_N = 1
ans_M = 1

if abs(N - M) >= 2:
    print(0)
else:
    for i in range(N):
        ans_N_1 = (M-i)*(N-i) % (10**9+7)
        ans_N = ans_N * ans_N_1

    for j in range(M):
        ans_M_1 = (M-j)*(N-j) % (10**9+7)
        ans_M = ans_M * ans_M_1
    print(ans_N+ans_M)

Fixed submission:
# C - Reconciled?
N, M = map(int, input().split())
ans_N = 1
ans_M = 1
mod = 10**9+7

if abs(N - M) >= 2:
    print(0)
else:
    for i in range(N):
        ans_N = ans_N * ((M - i) * (N - i)) % mod
    for j in range(M):
        ans_M = ans_M * ((M - j) * (N - j)) % mod
    print((ans_N+ans_M)% mod)
Buggy python submission (verdict: Runtime Error):
# B - Traveling AtCoDeer Problem
N = int(input())
a = list(map(int, input().split()))
A = set(a)
A1 = sorted(A)
count = 0
for i in range(N-1) :
    count += A1[i+1]-A1[i]

print(count)

Fixed submission:
# B - Traveling AtCoDeer Problem
N = int(input())
a = list(map(int, input().split()))
A = set(a)
A1 = sorted(A)
count = 0
for i in range(len(A)-1) :
    count += A1[i+1]-A1[i]

print(count)
Buggy python submission (verdict: Runtime Error):
A, B, C = map(str, input().split())

if A[-1] == B[0] and B[-1] == c[0]:
    print("YES")
else:
    print("NO")

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

if A[-1] == B[0] and B[-1] == C[0]:
    print("YES")
else:
    print("NO")
Buggy python submission (verdict: Time Limit Exceeded):
# C - Digits in Multiplication
N = int(input())

A = int(N**0.5)
ans = 1
for i in range(A,N):
    if N % i == 0:
        ans = len(str(i))
        break
    else:
        ans = len(str(i))

print(ans)

Fixed submission:
# C - Digits in Multiplication
N = int(input())

A = int(N**0.5)
# print(A)
ans = 1
for i in range(A,0,-1):
    if N % i == 0:
        tmp = N / i
        ans = len(str(int(tmp)))
        break
    else:
        pass

print(ans)
Buggy python submission (verdict: Time Limit Exceeded):
# Training CampTraining Camp
N = int(input())

p = 1
for i in range(1, N+1):
    p = p * i

p = float(p % (10**9 + 7))
print(int(p))

Fixed submission:
# Training CampTraining Camp
N = int(input())

p = 1
for i in range(1, N+1):
    p = p * i
    p = float(p % (10**9 + 7))

print(int(p))
Buggy python submission (verdict: Time Limit Exceeded):
# Between a and b ...
a, b, x = map(int, input().split())
count = 0

for i in range(a, b+1):
    if i % x == 0:
        count = count +1
    else:
        pass
print(count)

Fixed submission:
# Between a and b ...

a, b, x = map(int, input().split())
c = a // x
if a == 0:
    ans = (b // x) + 1
else:
    ans = (b // x) - ((a - 1) // x )
print(ans)
Buggy python submission (verdict: Runtime Error):
import sys
input = sys.stdin.readline
mod = int(1e9)+7

def solve():
    n=int(input())
    if n<3:
        print(0)
        return
    dp=[0]*2001
    dp[3]=dp[4]=dp[5]=1
    for i in range(6,n+1):
        dp[i]=(dp[i-1]+dp[i-3])%mod
    print(dp[n])

if __name__=="__main__":
    solve()





Fixed submission:
import sys
import math
input = sys.stdin.readline
mod = int(1e9)+7

def solve():
    n=int(input())
    ans = pow(10,n,mod)-(2*pow(9,n,mod)-pow(8,n,mod))
    print(ans%mod)

    
if __name__=="__main__":
    solve()
Buggy python submission (verdict: Time Limit Exceeded):
import sys
input = sys.stdin.readline
mod = int(1e9+7)
n=int(input())
L=list(map(int,input().split()))
total = 0
for i in range(n):
    for j in range(i+1,n):
        total+=((L[i]%mod)*(L[j]%mod))%mod
print(total%mod)





Fixed submission:
import sys
input = sys.stdin.readline
mod = int(1e9+7)
n=int(input())
L=list(map(int,input().split()))
total = 0
hb = sum(L)
val = 0
for i in range(n-1):
    val +=L[i]
    total += L[i]*(hb-val)
print(total%mod)

Buggy python submission (verdict: Time Limit Exceeded):
import sys
input = sys.stdin.readline
mod = int(1e9+7)
n=int(input())
L=list(map(int,input().split()))
total = 0
for i in range(n):
    for j in range(i+1,n):
        total+=((L[i]%mod)*(L[j]%mod))
print(total%mod)





Fixed submission:
import sys
input = sys.stdin.readline
mod = int(1e9+7)
n=int(input())
L=list(map(int,input().split()))
total = 0
hb = sum(L)
val = 0
for i in range(n-1):
    val +=L[i]
    total += L[i]*(hb-val)
print(total%mod)

Buggy python submission (verdict: Time Limit Exceeded):
import sys
input = sys.stdin.readline
mod = int(1e9+7)
n=int(input())
L=list(map(int,input().split()))
total = 0
for i in range(n):
    for j in range(i+1,n):
        total+=(L[i]*L[j])
print(total%mod)





Fixed submission:
import sys
input = sys.stdin.readline
mod = int(1e9+7)
n=int(input())
L=list(map(int,input().split()))
total = 0
hb = sum(L)
val = 0
for i in range(n-1):
    val +=L[i]
    total += L[i]*(hb-val)
print(total%mod)
Buggy python submission (verdict: Runtime Error):
import sys
input = sys.stdin.readline
n,m=map(int,input().split())
M=set(tuple(map(int,input().split())) for _ in range(m))
d={i:set() for i in range(1,n+1)}

for a,b in M:
    if a>b:
        a,b=b,a
    d[a].add(b)

val = max(d,key=d.get)
for i in d[val]:
    if d[i]!=set():
        d[val]|=d[i]
print(len(d[val])+1)



Fixed submission:
n,m=map(int,input().split())
d={i:set() for i in range(1,n+1)}
for i in range(m):
    a,b=map(int,input().split())
    d[a].add(b)
    d[b].add(a)

vis = set()
res = 0
for i in range(1,n+1):
    if i not in vis:
        stack=[i]
        ans=1
        vis.add(i)
        while stack:
            cur=stack.pop()
            for j in d[cur]:
                if j not in vis:
                    vis.add(j)
                    ans+=1
                    stack.append(j)
        res=max(res,ans)
print(res)

Buggy python submission (verdict: Runtime Error):
import sys
input = sys.stdin.readline
n,m=map(int,input().split())
M=set(tuple(map(int,input().split())) for _ in range(m))
d={i:set() for i in range(1,n+1)}

for a,b in M:
    if a>b:
        a,b=b,a
    d[a].add(b)

val = max(d,key=d.get)
for i in d[val]:
    d[val]|=d[i]
print(len(d[val])+1)



Fixed submission:
n,m=map(int,input().split())
d={i:set() for i in range(1,n+1)}
for i in range(m):
    a,b=map(int,input().split())
    d[a].add(b)
    d[b].add(a)

vis = set()
res = 0
for i in range(1,n+1):
    if i not in vis:
        stack=[i]
        ans=1
        vis.add(i)
        while stack:
            cur=stack.pop()
            for j in d[cur]:
                if j not in vis:
                    vis.add(j)
                    ans+=1
                    stack.append(j)
        res=max(res,ans)
print(res)
Buggy python submission (verdict: Time Limit Exceeded):
import sys
input = sys.stdin.readline

r,c,m=map(int,input().split())
q=[list(map(lambda x:int(x)-1,input().split())) for _ in range(m)]
M=[[0 for i in range(c)] for _ in range(r)]
for i,j in q:
    M[i][j]=1

rows = [0]*r
cols = [0]*c

for i in range(r):
    rows[i]=sum(M[i])

for i in range(c):
    A = [M[j][i] for j in range(r)]
    cols[i] = sum(A)


#print(rows,cols)
MAX = 0
for i in range(r):
    for j in range(c):
        if M[i][j]==1:
            MAX = max(MAX,rows[i]+cols[j]-1)
        else:
            MAX = max(MAX,rows[i]+cols[j])
print(MAX)
    



    


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

r,c,m=map(int,input().split())
q=set(tuple(map(lambda x :int(x)-1,input().split())) for _ in range(m))
rows = [0]*r
cols = [0]*c

for i,j in q:
    rows[i]+=1
    cols[j]+=1

MAXR = max(rows)
MAXC = max(cols)

ans = MAXR+MAXC-1

rlist=[]
clist=[]

for i in range(r):
    if rows[i]==MAXR:
        rlist.append(i)

for j in range(c):
    if cols[j]==MAXC:
        clist.append(j)
   
for i in rlist:
    for j in clist:
        if (i,j) in q:
            continue
        else:
            ans+=1
            print(ans)
            sys.exit()
print(ans)
Buggy python submission (verdict: Time Limit Exceeded):
import sys
input = sys.stdin.readline
x,k,d=map(int,input().split())
for i in range(k):
    v1 = x-d
    v2 = x+d
    x=min(abs(v1),v2)
print(abs(x))



Fixed submission:
import sys
input = sys.stdin.readline
x,k,d=map(int,input().split())
x=abs(x)
if x<d:
    if k&1==0:
        print(x)
    else:
        print(abs(x-d))
    sys.exit()

val = x//d

if val>k:
    x-=(k*d)
    print(x)
    sys.exit()

x-=(val*d)
k-=val
if k&1==0:
    print(x)

else:
    ans = min(x+d,abs(x-d))
    print(ans)
Buggy python submission (verdict: Time Limit Exceeded):
import sys
input = sys.stdin.readline

n=int(input())
s=list(input().strip())
count = 0
for i in range(n):
    if s[i]=='W':
        for j in range(n-1,i,-1):
            if s[j]=='R':
                s[i],s[j]=s[j],s[i]
                count+=1
                break
        else:
            break
        
print(count)



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

n=int(input())
s=list(input().strip())
count = 0
cw = s.count('W')
cr = n-cw

for i in range(cr):
    if s[i]=='W':
        count+=1

print(count)
Buggy python submission (verdict: Runtime Error):
import sys
input = sys.stdin.readline
n=int(input())
count = 0

L=list(range(400,2000,200))
val=len(L)
count=0
for i in range(val-1):
    if L[i]<=n<L[i+1]:
        ans=8-count
        break
    else:
        count+=1
print(ans)


Fixed submission:
import sys
input = sys.stdin.readline
n=int(input())
count = 0

L=list(range(400,2001,200))
val=len(L)
ans = 0
for i in range(val-1):
    if L[i]<=n<L[i+1]:
        ans=8-count
        break
    else:
        count+=1
print(ans)
Buggy python submission (verdict: Time Limit Exceeded):
import sys
from itertools import accumulate
import operator as op
input = sys.stdin.readline

n,k=map(int,input().split())
L=list(map(int,input().split()))
N=[1]+list(accumulate(L,op.mul))

ans=[]
for i in range(k,n+1):
    val = N[i]/N[i-k]
    ans.append(val)

N=len(ans)
for i in range(1,N):
    if ans[i]>ans[i-1]:
        print('Yes')
    else:
        print('No')


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

n,k=map(int,input().split())
L=list(map(int,input().split()))

ans=[]
for i in range(k,n):
    if L[i]>L[i-k]:
        print('Yes')
    else:
        print('No')
Buggy python submission (verdict: Runtime Error):
import sys
input = sys.stdin.readline
mod = int(1e9+7)
n,k = map(int,input().split())
L=list(map(int,input().split()))

ans = 1

pos = []
neg = []
for i in L:
    if i>=0:
        pos.append(i)
    else:
        neg.append(i)
pos.sort(reverse=True)
neg.sort()
if len(pos) == 0 and k%2!=0:
    for i in range(1,k+1):
        ans*=neg[-i]
        ans%=mod
    print(ans%mod)
    sys.exit()
if k%2!=0:
    ans*=pos.pop(0)
    k-=1
l=[]
for i in range(1,len(pos),2):
    l.append(pos[i]*pos[i-1])

for i in range(1,len(neg),2):
    l.append(neg[i]*neg[i-1])

l.sort(reverse = True)
for i in range(k//2):
    ans*=l[i]
    ans%=mod

print(ans%mod)


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

h,w,k = map(int,input().split())
M=[input().rstrip() for _ in range(h)]
ans = 0
for ib in range(1<<h):
    for jb in range(1<<w):
        cc = 0 
        for i in range(h):
            if ib&(1<<i):continue
            for j in range(w):
                if jb&(1<<j):continue
                cc+=M[i][j]=='#'
        if cc==k:
            ans+=1
print(ans)
Buggy python submission (verdict: Time Limit Exceeded):
import sys
import math
input = sys.stdin.readline

def countdiv(n):
    i=1
    count = 0
    while i<=math.sqrt(n):
        if n%i==0:
            if n/i==i:
                count+=1
            else:
                count+=2
        i+=1
    return count

dp = [0]*int(1e7+1)
n=int(input())
Sum = 0
for i in range(1,n+1):
    val = countdiv(i)
    Sum+=i*val
print(Sum)



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

n = int(input())
ans = 0
for i in range(1,n+1):
    val = n//i
    total = (val*(val+1))//2
    ans += i*total
print(ans)
Buggy python submission (verdict: Time Limit Exceeded):
import sys
input = sys.stdin.readline

n = int(input())
A = list(map(int,input().split()))
q = int(input())
M=[list(map(int,input().split())) for _ in range(q)]
Sum = sum(A)
d={}
for i in range(n):
    if A[i] not in d:
        d[A[i]]=1
    else:
        d[A[i]]+=1
for i in M:
    a,b=i[0],i[1]
    if a not in d:
        L = list(d.items())
        print(sum([x*y for x,y in L]))
        continue
    elif b in d:
        d[b]+=d[a]
    else:
        d[b]=d[a]
    d.pop(a)
    L = list(d.items())
    print(sum([x*y for x,y in L]))


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

n = int(input())
A = list(map(int,input().split()))
q = int(input())
M=[list(map(int,input().split())) for _ in range(q)]
Sum = sum(A)
d={}

for i in range(n):
    if A[i] not in d:
        d[A[i]]=1
    else:
        d[A[i]]+=1

for i in M:
    prev = 0
    a,b=i[0],i[1]
    if a not in d:
        print(Sum)
        continue
    
    elif b in d:
        prev = d[b]*b
        d[b]+=d[a]
    else:
        d[b]=d[a]
    
    Sum += d[b]*b-d[a]*a-prev

    d.pop(a)
    print(Sum)
Buggy python submission (verdict: Time Limit Exceeded):
import sys
input = sys.stdin.readline

n = int(input())
L=list(map(int,input().split()))
count = 0
for i in range(n):
    val = L[i]
    for j in range(n):
        if j!=i:
            if L[i]%L[j]!=0:
                continue
            else:
                count+=1
                break
print(n-count)
            

    


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

n=int(input())
L=list(map(int,input().split()))
L.sort()
hb = L[-1]
dp = [-1 for i in range(hb+1)] 
for i in L:
    if dp[i]!=0:
        if dp[i]==1:
            dp[i]=0
            continue
        dp[i]=1
        for j in range(2*i,hb+1,i):
            dp[j]=0
ans=0
for i in L:
    if dp[i]==1:
        ans+=1
print(ans)
Buggy python submission (verdict: Time Limit Exceeded):
n=int(input())
L=list(map(int,input().split()))
ans=1
for i in range(n):
    ans=ans*L[i]
    if L[i]==0:
        break

if ans > 1e18:
    print(-1)
else:
    print(ans)



Fixed submission:
n=int(input())
L=list(map(int,input().split()))
L.sort()
if L[0]==0:
    print(0)
else:
    ans=1
    for i in range(n-1,-1,-1):
        ans=ans*L[i]
        if ans >1e18:
            print(-1)
            break
    else:
        print(ans)

Buggy python submission (verdict: Time Limit Exceeded):
n=int(input())
L=list(map(int,input().split()))
ans=1
for i in range(n):
    ans=ans*L[i]
if ans > 1e18:
    print(-1)
else:
    print(ans)



Fixed submission:
n=int(input())
L=list(map(int,input().split()))
L.sort()
if L[0]==0:
    print(0)
else:
    ans=1
    for i in range(n-1,-1,-1):
        ans=ans*L[i]
        if ans >1e18:
            print(-1)
            break
    else:
        print(ans)
Buggy python submission (verdict: Runtime Error):
import sys
input = sys.stdin.readline

a,b = input().strip().split()
a = int(a)
b = b.replace('.','')
ans = (a*b)//100
print(ans)


Fixed submission:
import math
from decimal import *
a,b=input().split()
print(math.floor(Decimal(a)*Decimal(b)))
Buggy python submission (verdict: Time Limit Exceeded):
n,k=map(int,input().split())
L=list(map(int,input().split()))
L.insert(0,0)
#print(L)
prev=L[1]
for i in range(1,k):
	nex = L[prev]
	prev = nex
print(nex)


Fixed submission:
#very important question
n,k=map(int,input().split())
L=list(map(int,input().split()))

visit=[False]*(n+1)

town=[]

next=1
while 1:
    next = L[next-1]
    if not visit[next]:
        town.append(next)
        visit[next] = True
    else:
        town.append(next)
        break
#print(town)
for i in range(n):
    if town[i]==town[-1]:
        mod=i
        index=i
        loop=len(town)-i-1
        loop_array = town[i:-1]
        break

fin_len = (k-mod)%loop
if k<=mod:
    print(town[k-1])
else:
    print(loop_array[fin_len-1])
Buggy python submission (verdict: Runtime Error):
s,w=map(int,input().split())
if s>w:
  print('safe')
 else:
  print('unsafe')

Fixed submission:
s,w=map(int,input().split())
if s>w:
	print('safe')
else:
	print('unsafe')
Buggy python submission (verdict: Runtime Error):
import sys
from collections import deque
input = sys.stdin.readline

n=int(input())
L=deque(list(range(1,10)))
if n<=9:
    ans = L[n-1]
else:
    cnt = 9
    for i in range(1,n):
        c=L.popleft()
        
        if c%10!=0:
            L.append(c*10+(c%10)-1)
            cnt+=1
            if cnt>=n:
                break
        L.append(c*10+(c%10))
        cnt+=1
        if cnt>=n:
            break
        
        if c%10!=9:
            L.append(c*10+(c%10)+1)
            cnt+=1
            if cnt>=n:
                break
        print(L)
    ans = L[-1]
print(ans)


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

n=int(input())
L=deque(list(range(1,10)))
if n<=9:
    ans = L[n-1]
else:
    cnt = 9
    for i in range(1,n):
        c=L.popleft()
        
        if c%10!=0:
            L.append(c*10+(c%10)-1)
            cnt+=1
            if cnt>=n:
                break
        L.append(c*10+(c%10))
        cnt+=1
        if cnt>=n:
            break
        
        if c%10!=9:
            L.append(c*10+(c%10)+1)
            cnt+=1
            if cnt>=n:
                break
    ans = L[-1]
print(ans)