Harryxun/testdata huggingface dataset:
Buggy python submission (verdict: Runtime Error):
from sys import stdin

a,b,c=map(int,input().split())
print(str(c)+" "+str(a)+" "str(c))

Fixed submission:
from sys import stdin

a,b,c=map(int,input().split())
print(str(c)+" "+str(a)+" "+str(b))
Buggy python submission (verdict: Runtime Error):
from sys import stdin

n,a,b=map(int,input().split())
ans=0
ans+=(n//(a+b))*a
n%=a+b
if n<=a:
    ans+=n
else:
    ans+=a
print(str(ans)+"\n)

Fixed submission:
from sys import stdin

n,a,b=map(int,input().split())
ans=0
ans+=(n//(a+b))*a
n%=a+b
if n<=a:
    ans+=n
else:
    ans+=a
print(str(ans)+"\n")
Buggy python submission (verdict: Runtime Error):
from sys import stdin
import queue
import sys

s,t=input().split()
ans=0
for i in range(3):
    if s[i]==t[i]:
        ans+=1
print(ans)


Fixed submission:
from sys import stdin
import queue
import sys

s=input()
t=input()
ans=0
for i in range(3):
    if s[i]==t[i]:
        ans+=1
print(ans)
Buggy python submission (verdict: Runtime Error):
N,A,B=map(int,input().split())

line =''

for i in range(10**100):
    line += 'b'*A
    line += 'r'*B
    if len(line)>=N:
        print(line[:N].count('b'))
        break

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

ans =N//(A+B)*A
remain = N%(A+B)
ans += min(remain,A)
print(ans)
Buggy python submission (verdict: Runtime Error):
A, B, C =map(int,input().shape())
if A+B+C >=22:
  print('bust')
else:
  print('win')

Fixed submission:
A, B, C =map(int,input().split())
if A+B+C >=22:
  print('bust')
else:
  print('win')
Buggy python submission (verdict: Runtime Error):
def main():
    k = input()
    s = input()
    if(len(s)<k):
        print(s)
    else:
        print(s[0:k] + '...')
    
 
main()

Fixed submission:
def main():
    K = int(input())
    S = input()
    if(len(S)<=K):
        print(S)
    else:
        print(S[0:K] + '...')
    
 
main()

Buggy python submission (verdict: Runtime Error):
def main():
    s = input()
    k = input()
    if(len(s)<=k):
        print(s)
    else:
        print(s[0:k] + '...')
    
 
main()

Fixed submission:
def main():
    K = int(input())
    S = input()
    if(len(S)<=K):
        print(S)
    else:
        print(S[0:K] + '...')
    
 
main()

Buggy python submission (verdict: Runtime Error):
def main():
    s = input()
    k = input()
    if(len(s)<k):
        print(s)
    else:
        print(s[0:k] + '...')
    
 
main()

Fixed submission:
def main():
    K = int(input())
    S = input()
    if(len(S)<=K):
        print(S)
    else:
        print(S[0:K] + '...')
    
 
main()
Buggy python submission (verdict: Runtime Error):
A, B, C, K = map(int, input().split())
num = 0
 
for i in range(K):
    if(A >  i):
        num+=1
    elif(A+B >  i):
        continue
    else:
        num-=1
 
print(num)

Fixed submission:
S = input()
T = input()

if(S==T[:-1]):
    print('Yes')
else:
    print('No')
Buggy python submission (verdict: Runtime Error):
#from fractions import gcd
#A,B = map(int, input().split())
#print(A*B//gcd(A,B))
def gcd(a,b):
    if(a<b):
         b,a=a,b
    if(b==0):
        return a
    r = a%b
    if(r!=0) :
        a,b,r=b,r,b%r
        return gcd(b,r)
    else:
        return b

A,B = map(int, input().split())
print(A*B//gcd(A,B))

Fixed submission:
A = int(input())
B = int(input())

print(6-A-B)
Buggy python submission (verdict: Runtime Error):

import sys

def test(k,s):
    cnt=0

    length = len(s)
    if k<length:
        return s[:k]+'...'
    return s

if __name__ == '__main__':
    print(test(sys.argv[0],sys.argv[1]))

Fixed submission:


if __name__ == '__main__':
    k = int(input());
    s = input();

    cnt=0
    for i in s:
        print(i, end='')
        cnt+=1
        if cnt>=k:
            break

    if k < len(s):
        print('...')
Buggy python submission (verdict: Runtime Error):
now = 0
before = -9999
answer = 1

for a in a_n:
    if a - before == 1:
        answer = 0
        break    
    answer *= Fib( a - 1 - now + 2 )
    answer %= 1000000007
    now = a + 1
    before = a

if answer > 0:
    answer *= Fib( N - now + 2)
    answer %= 1000000007

print(answer )

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

m = sum(w)
b = m
answer = T
for t in range(1, T):
    k = sum(w[0:t+1])
    diff= abs(2*k - m) 
    if diff < b:
        b = diff 
    else:
        break
print(b)
Buggy python submission (verdict: Runtime Error):
N, M = map(int, input().split())
a_n = [int(input()) for i in range(M)]
def Fib(n):    
    if n == 1:
        return 0
    elif n == 2:
        return 1
    else:
        return Fib(n-1)+Fib(n-2)
now = 0
before = -9999
answer = 1

for a in a_n:
    if a - before == 1:
        answer = 0
        break    
    answer *= Fib( a - 1 - now + 2 )
    answer %= 1000000007
    now = a + 1
    before = a

if answer > 0:
    answer *= Fib( N - now + 2)
    answer %= 1000000007

print(answer)

Fixed submission:
N, M = map(int, input().split())
a_n = [int(input()) for i in range(M)]
def Fib(n):
    a, b = 0, 1
    if n == 1:
        return a
    elif n == 2:
        return b
    else:
        for i in range(n-2):
            a, b = b, a + b
        return b
now = 0
before = -9999
answer = 1

for a in a_n:
    if a - before == 1:
        answer = 0
        break

    answer *= Fib( a - 1 - now + 2 )
    answer %= 1000000007
    now = a + 1
    before = a

if answer > 0:
    answer *= Fib( N - now + 2)
    answer %= 1000000007

print(answer)

Buggy python submission (verdict: Runtime Error):
N, M = map(int, input().split())
a_n = [int(input()) for i in range(M)]

def Fib(n):    
    if n == 1:
        return 0
    elif n == 2:
        return 1
    else:
        return Fib(n-1)+Fib(n-2)
      
now = 0
before = -9999
answer = 1

for a in a_n:
    if a - before == 1:
        answer = 0
        break    
    answer *= Fib( a - 1 - now + 2 )
    now = a + 1
    before = a

if answer > 0:
    answer *= Fib( N - now + 2)

print(answer % 1000000007)

Fixed submission:
N, M = map(int, input().split())
a_n = [int(input()) for i in range(M)]
def Fib(n):
    a, b = 0, 1
    if n == 1:
        return a
    elif n == 2:
        return b
    else:
        for i in range(n-2):
            a, b = b, a + b
        return b
now = 0
before = -9999
answer = 1

for a in a_n:
    if a - before == 1:
        answer = 0
        break

    answer *= Fib( a - 1 - now + 2 )
    answer %= 1000000007
    now = a + 1
    before = a

if answer > 0:
    answer *= Fib( N - now + 2)
    answer %= 1000000007

print(answer)
Buggy python submission (verdict: Runtime Error):
import sys

K = int(input())
S = input()
sentence = list(S)
sentencelong = len(sentence)

if K < sentencelong:
  print(sentence[:K] + '...')
elif K > sentencelong:
  print(S)
  
else:
  sys.exit()
  

Fixed submission:
K=int(input())
S=input()

if len(S) > K:
  S = S[:K] + "..."
  
print(S)

Buggy python submission (verdict: Runtime Error):
K = int(input())
S = input()
sentence = list(S)

for i in range(K):
  print(sentence[i], end="")

sentencelong = len(sentence)

if K < sentencelong:
  print("...")

Fixed submission:
K=int(input())
S=input()

if len(S) > K:
  S = S[:K] + "..."
  
print(S)

Buggy python submission (verdict: Runtime Error):
K = int(input())
S = input()
sentence = list(S)

for i in range(K):
  print(sentence[i], end="")
  
print("...")

Fixed submission:
K=int(input())
S=input()

if len(S) > K:
  S = S[:K] + "..."
  
print(S)
Buggy python submission (verdict: Runtime Error):
import math

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

hourdegrees = ( H * 60 + M ) * (0.5)
mindegrees = M*(6)
  
if mindegrees < hourdegrees:
  degree = hourdegrees - mindegrees
elif mindegrees > hourdegrees:
  degree = mindegrees - hourdegrees
  
distance = math.sqrt(A ** 2 + B ** 2 -2 * A * B * math.cos(math.radians(degree) ) )
print(distance)

Fixed submission:
import math
     
A,B,H,M = map(int, input().split())
     
hourdegrees = ( H * 60 + M ) * (0.5)
mindegrees = M*(6)
      
if mindegrees < hourdegrees:
  degree = hourdegrees - mindegrees
elif mindegrees > hourdegrees:
  degree = mindegrees - hourdegrees
elif mindegrees == hourdegrees:
  degree = 0
      
distance = math.sqrt(A ** 2 + B ** 2 -2 * A * B * math.cos(math.radians(degree) ) )
print(distance)

Buggy python submission (verdict: Runtime Error):
import math

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

hourdegrees = H*(30)
mindegrees = M*(6)


if hourdegrees > 180:
  hourdegrees-=180
  
if mindegrees < hourdegrees:
  degree = hourdegrees - mindegrees
elif mindegrees > hourdegrees:
  degree = mindegrees - hourdegrees
  
distance = math.sqrt(A ** 2 + B ** 2 -2 * A * B * math.cos(math.radians(degree) ) )
print(distance)

Fixed submission:
import math
     
A,B,H,M = map(int, input().split())
     
hourdegrees = ( H * 60 + M ) * (0.5)
mindegrees = M*(6)
      
if mindegrees < hourdegrees:
  degree = hourdegrees - mindegrees
elif mindegrees > hourdegrees:
  degree = mindegrees - hourdegrees
elif mindegrees == hourdegrees:
  degree = 0
      
distance = math.sqrt(A ** 2 + B ** 2 -2 * A * B * math.cos(math.radians(degree) ) )
print(distance)
Buggy python submission (verdict: Time Limit Exceeded):
#!/usr/bin/env python


def pow(m, n):
    if n == 0:
        return 1
    elif n % 2 == 0:
        return (pow(m, int(n / 2)) ** 2) % mod
    elif n % 2 == 1:
        return (pow(m, int((n - 1) * 0.5)) ** 2 * m) % mod


def conb(n, a):
    mod1 = 1
    mod2 = 1
    for i in range(a):
        mod1 *= n - i
        mod2 *= i + 1
    mod2 = pow(mod2, mod - 2)
    return (mod1 * mod2) % mod


n, a, b = (int(val) for val in input().split())


ans = 1
noa = 1
nob = 1
mod = 1000000007
ans = pow(2, n) - 1 - conb(n, a) - conb(n, b)
ans %= mod
print(ans)


Fixed submission:
#!/usr/bin/env python


def pow(m, n):
    if n == 0:
        return 1
    elif n % 2 == 0:
        return (pow(m, int(n / 2)) ** 2) % mod
    elif n % 2 == 1:
        return (pow(m, int((n - 1) * 0.5)) ** 2 * m) % mod


def conb(n, a):
    mod1 = 1
    mod2 = 1
    for i in range(a):
        mod1 *= n - i
        mod1 %= mod
        mod2 *= i + 1
        mod2 %= mod
    mod2 = pow(mod2, mod - 2)
    return (mod1 * mod2) % mod


n, a, b = (int(val) for val in input().split())


ans = 1
noa = 1
nob = 1
mod = 1000000007
ans = pow(2, n) - 1 - conb(n, a) - conb(n, b)
ans %= mod
print(ans)
Buggy python submission (verdict: Runtime Error):
n,m=input().split()
h_list = []
h_list = input().split(" ")
result =[True]*n
count = 0
for i in range(int(m)):
    temp1,temp2=input().split()
    if h_list[int(temp1)-1] < h_list[int(temp2)-1]:
        result[int(temp1)-1] = False
    elif h_list[int(temp1)-1] == h_list[int(temp2)-1]:
        result[int(temp1) - 1] = False
        result[int(temp2) - 1] = False
    else:
        result[int(temp2)-1] = False
for i in range(int(n)):
    if(result[i]==True):
        count += 1
print(count)

Fixed submission:
n,m = map(int,input().split())
h = list(map(int,input().split()))
p = [0 for i in range(n)]
for i in range(m):
    a,b = map(int,input().split())
    if h[a-1] >= h[b-1]:
        p[b-1] = -1
    if h[a-1] <= h[b-1]:
        p[a-1] = -1
print(p.count(0))
Buggy python submission (verdict: Time Limit Exceeded):
n=int(input())
heights=list(map(int,input().split(" ")))
res=0
for i in range(n):
    for j in range(n):
        if abs(j-i)==heights[i]+heights[j]:
            res+=1
print(int(res/2))

Fixed submission:
n=int(input())
heights=list(map(int,input().split(" ")))
dic={}
res=0
for i in range(n):
    if heights[i]-i not in dic:
        dic[heights[i]-i]=1
    else:
        dic[heights[i]-i]+=1
for j in range(n):
    if -heights[j]-j in dic:
        res+=dic[-heights[j]-j]
print(res)
Buggy python submission (verdict: Runtime Error):
TH,TS,AH,AS = map(int,input().split())
while Ture:
  AH -= TS
  if AH <= 0:
    print('Yes')
    break
  else:
    TH -= AS
    if TH <= 0:
      print('No')
      break

Fixed submission:
TH,TS,AH,AS = map(int,input().split())
while True:
  AH -= TS
  if AH <= 0:
    print('Yes')
    break
  else:
    TH -= AS
    if TH <= 0:
      print('No')
      break

Buggy python submission (verdict: Runtime Error):
th,ts,ah,as = map(int,input().split())
while Ture:
  ah -= ts
  if ah <= 0:
    print('Yes')
    break
  else:
    th -= as
    if th <= 0:
      print('No')
      break

Fixed submission:
TH,TS,AH,AS = map(int,input().split())
while True:
  AH -= TS
  if AH <= 0:
    print('Yes')
    break
  else:
    TH -= AS
    if TH <= 0:
      print('No')
      break
Buggy python submission (verdict: Time Limit Exceeded):
A,B,C,K = map(int, input().split())
sum = 0

for i in range(K):
  if i < A:
  	sum = sum + 1
  if A+B <= i < A+B+C:
  	sum = sum - 1
  
print(sum)


Fixed submission:
A,B,C,K = map(int, input().split())
sum = 0
x = K - A
if x > 0:
	sum += A
else:
	sum += K
x = x - B
if x > 0 :
	sum -= x
print(sum)
Buggy python submission (verdict: Runtime Error):
X = int(input())
m = 100
count = 0
while i in 32:
  m = math.floor(m * 1.01)
  if m > X:
    count = i + 1
    break
print(count)

Fixed submission:
X = int(input())
m = 100
count = 0
import math
while m < X:
  m = m * 101 //100
  count += 1
print(count)
Buggy python submission (verdict: Runtime Error):
import math
A,B = (int(i) for i in input().split())
g = math.gcd(A,B)
print(A*B//g)


Fixed submission:
A,B = (int(i) for i in input().split())
def gcd(a,b):
    if a % b == 0:
        return b
    else:
        r = a% b
        return gcd(b,r)
print(A*B//gcd(A,B))

Buggy python submission (verdict: Runtime Error):
import math
A,B = (int(i) for i in input().split())
g = math.gcd(A,B)
print(A*B/g)


Fixed submission:
A,B = (int(i) for i in input().split())
def gcd(a,b):
    if a % b == 0:
        return b
    else:
        r = a% b
        return gcd(b,r)
print(A*B//gcd(A,B))
Buggy python submission (verdict: Runtime Error):
r = input()
print(3 * r**2)

Fixed submission:
r =int(input())
print(3* r**2)

Buggy python submission (verdict: Runtime Error):
r = input()
print(3 * a**2)

Fixed submission:
r =int(input())
print(3* r**2)
Buggy python submission (verdict: Time Limit Exceeded):
N = int(input())
S = list(input())
numbers = []
for i in range(N):
    S_left = S[:i]
    S_right = S[i+1:]
    number = S_left.count("W")+S_right.count("E")
    numbers.append(number)
print(min(numbers))

Fixed submission:
N = int(input())
S = list(input())
origin = S[1:]
summary = [origin.count("E")]
for i in range(N-1):
    s = summary[-1]
    if S[i] == "W":
        if S[i+1] == "E":
            delta = 0
        else:
            delta = 1
    else:
        if S[i+1] == "E":
            delta = -1
        else:
            delta = 0
    summary.append(delta+s)
print(min(summary))
Buggy python submission (verdict: Runtime Error):
a = list(map(int,input().split()))
N,A,B = a[0],a[1],a[2]
k = 1
x = True
while x:
    if 10**(k-1) <= N and N < 10**k:
        x = False
    else:
        k += 1
u = 1
M = 0
while u <= k:
    if u == 1:
        v = 1
        while v <= 9:
            if v>= A and v <= B and v <= N:
               M += v
            v += 1
    elif u == 2:
        v,w = 1,0
        while v <= 9:
            while w <= 9:
                 if v+w <=B and v+w >= A and 10*v+w<=N:
                     M += 10*v +w
                 w += 1
            w=0
            v += 1
    else:
        v,w,x =1,0,0
        while v<=9:
            while w <= 9:
                while x <= 9:
                    if v+w+x >= A and v+w+x <= B and 100*v+10*w+x<=N:
                        M += 100*v + 10*w + x
                    x += 1
                x=0
                w += 1
            w=0
            v += 1
    u += 1
print(M)

Fixed submission:
u = [int(input()) for i in range(4)]
A,B,C,X = u[0],u[1],u[2],u[3]
count=[]
a ,b = 0,0
i = 0
while X-500*a >=0 and a<= A:
    X_1 = X-500*a
    while X_1-100*b>= 0 and b<= B:
        X_2 = X_1-100*b
        if X_2 % 50 == 0 and X_2 / 50 <= C:
            i += 1
        else:
             pass
        b += 1
    b = 0
    count.append(i)
    a += 1
    i=0
print(sum(count))
Buggy python submission (verdict: Time Limit Exceeded):
N,Y = (int(i) for i in input().split())
n_10000,n_5000 = 0,0
n_1000 = N-n_10000-n_5000
x = True
while x:
    while x:
        if n_1000 < 0:
            print(-1,-1,-1)
            x = False
        elif n_10000 +n_5000 +n_1000 == N and 10000*n_10000+5000*n_5000+1000*n_1000 == Y:
            print(n_10000,n_5000,n_1000)
        n_5000 += 1
    n_10000 += 1
    
        

Fixed submission:
N,Y = (int(i) for i in input().split())
a,b,c = -1,-1,-1
for n_10000 in range(N+1):
    for n_5000 in range(N-n_10000+1):
        n_1000 = N-n_10000-n_5000
        if 10000*n_10000+5000*n_5000 +1000*n_1000 == Y:
            a,b,c = n_10000,n_5000,n_1000
print(a,b,c)
Buggy python submission (verdict: Runtime Error):
def div_count(a):
  i= 0
  while a%2 == 0:
    a = a/2
    i+=1
  return i
N = int(input())
list = int(input().split())
count=[]
for u in range(N):
  count.append(div_count(list[u]))
print(max(count))

  
     

Fixed submission:
def div_count(a):
  i= 0
  while a%2 == 0:
    a = a/2
    i+=1
  return i
N = int(input())
numbers = list(map(int,input().split()))
count=[]
for u in range(N):
  count.append(div_count(numbers[u]))
print(min(count))

Buggy python submission (verdict: Runtime Error):
N = input()
list = input.split()
i = 0
def div_list(your_list=list):
     for v in range(N):
       if list[v] % 2 == 0:
          list_a[v] = list[v] / 2
          if v== N-1:
             i+= 1
             div_list(list_a)
      
       else:
            break
      return i
print(div_list())
  

Fixed submission:
def div_count(a):
  i= 0
  while a%2 == 0:
    a = a/2
    i+=1
  return i
N = int(input())
numbers = list(map(int,input().split()))
count=[]
for u in range(N):
  count.append(div_count(numbers[u]))
print(min(count))
Buggy python submission (verdict: Runtime Error):
A,B,C,D = (int(i) for i in input().split())
Alice_time = set(range(A,B+1))
Bob_time = set(range(C,D+1))
common_time = Alice_time & Bob_time
common_time_list = list(common_time)
common_time_list_sorted = sorted(common_time_list)
print(common_time_list_sorted[-1]-common_time_list_sorted[0])


Fixed submission:
A,B,C,D = (int(i) for i in input().split())
Alice_time = set(range(A,B+1))
Bob_time = set(range(C,D+1))
common_time = Alice_time & Bob_time
common_time_list = list(common_time)
common_time_list_sorted = sorted(common_time_list)
if len(common_time_list_sorted) > 1:
    print(common_time_list_sorted[-1]-common_time_list_sorted[0])
else:
    print(0)
Buggy python submission (verdict: Runtime Error):
a,b,c = list(map(int,input().split()))

if a + b + c <= 21:
    print("win")

else:
    print("bust")12 

Fixed submission:
a,b,c = list(map(int,input().split()))

if a + b + c <= 21:
    print("win")

else:
    print("bust")
Buggy python submission (verdict: Runtime Error):
N, K = map(int, input().split())
A = list(map(int, input().split()))
l=[]           
seen={}
k=1
for i in range (K):
  l.append(k)
  if not k in seen.keys():
      seen[k]=i
      k=A[k-1]
  else:
    r_start=seen[k]
    roop=i-r_start
    c=K//roop
    K=K-roop*c
    break
ans=l[K]
print(ans)

Fixed submission:
N, K = map(int, input().split())
A = list(map(int, input().split()))
l=[1]           
seen={}
k=1
for i in range (K):
  if not k in seen.keys():
      seen[k]=i
      k=A[k-1]
      l.append(k)
  else:
    r_start=seen[k]
    roop=i-r_start
    K=(K-r_start)%roop+r_start
    break
ans=l[K]
print(ans)

Buggy python submission (verdict: Runtime Error):
N, K = map(int, input().split())
A = list(map(int, input().split()))
l=[]           
seen={}
k=1
for i in range (K):
  if not k in seen.keys():
      l.append(k)
      seen[k]=i
      k=A[k-1]
  else:
    r_start=seen[k]
    roop=i-r_start
    c=K//roop
    K=K-roop*c
    break
ans=l[K]
print(ans)

Fixed submission:
N, K = map(int, input().split())
A = list(map(int, input().split()))
l=[1]           
seen={}
k=1
for i in range (K):
  if not k in seen.keys():
      seen[k]=i
      k=A[k-1]
      l.append(k)
  else:
    r_start=seen[k]
    roop=i-r_start
    K=(K-r_start)%roop+r_start
    break
ans=l[K]
print(ans)

Buggy python submission (verdict: Runtime Error):
N, K = map(int, input().split())
A = list(map(int, input().split()))
l=[]           
seen = {}
k=A[0]
for i in range (K):
  if not k in seen.keys():
      l.append(k)
      seen[k]=i
      k=A[k-1]

  else:
    r_start=seen[k]
    roop=i-r_start
    break
c=K//roop
K=K-roop*c
ans=l[K-1]
print(ans)

Fixed submission:
N, K = map(int, input().split())
A = list(map(int, input().split()))
l=[1]           
seen={}
k=1
for i in range (K):
  if not k in seen.keys():
      seen[k]=i
      k=A[k-1]
      l.append(k)
  else:
    r_start=seen[k]
    roop=i-r_start
    K=(K-r_start)%roop+r_start
    break
ans=l[K]
print(ans)

Buggy python submission (verdict: Runtime Error):
N, K = map(int, input().split())
A = list(map(int, input().split()))
l=[]           
seen = {}
k=A[0]
for i in range (K):
  if not k in seen.keys():
      l.append(k)
      seen[k]=i
      k=A[k-1]

  else:
    r_start=seen[k]
    roop=i-r_start
    break
K=4
c=K//roop
K=K-roop*c
ans=l[K]
print(ans)

Fixed submission:
N, K = map(int, input().split())
A = list(map(int, input().split()))
l=[1]           
seen={}
k=1
for i in range (K):
  if not k in seen.keys():
      seen[k]=i
      k=A[k-1]
      l.append(k)
  else:
    r_start=seen[k]
    roop=i-r_start
    K=(K-r_start)%roop+r_start
    break
ans=l[K]
print(ans)

Buggy python submission (verdict: Runtime Error):
print(kari)

Fixed submission:
N, K = map(int, input().split())
A = list(map(int, input().split()))
l=[1]           
seen={}
k=1
for i in range (K):
  if not k in seen.keys():
      seen[k]=i
      k=A[k-1]
      l.append(k)
  else:
    r_start=seen[k]
    roop=i-r_start
    K=(K-r_start)%roop+r_start
    break
ans=l[K]
print(ans)
Buggy python submission (verdict: Runtime Error):
N = int(input())
R=[["1","2","3","4","5","6","7","8","9"]]
count=9
for i in range(N):
  if count>=N:
    break
  else:
    temp=[]
    for r in R[i]:
      if r[-1]=="9":
        temp.append(str(r)+str(int(r[-1])-1))
        temp.append(str(r)+str(int(r[-1])))
      elif r[-1]=="0":
        temp.append(str(r)+str(int(r[-1])))
        temp.append(str(r)+str(int(r[-1])+1))
      else:
        temp.append(str(r)+str(int(r[-1])-1))
        temp.append(str(r)+str(int(r[-1])))
        temp.append(str(r)+str(int(r[-1])+1))
    R.append(temp)
    count+=len(temp)
N=N-(count-len(temp))
print(R[-1][N-1])

Fixed submission:
N = int(input())
R=[["1","2","3","4","5","6","7","8","9"]]
count=9
temp=[]
for i in range(N):
  if count>=N:
    break
  else:
    temp=[]
    for r in R[i]:
      if r[-1]=="9":
        temp.append(str(r)+str(int(r[-1])-1))
        temp.append(str(r)+str(int(r[-1])))
      elif r[-1]=="0":
        temp.append(str(r)+str(int(r[-1])))
        temp.append(str(r)+str(int(r[-1])+1))
      else:
        temp.append(str(r)+str(int(r[-1])-1))
        temp.append(str(r)+str(int(r[-1])))
        temp.append(str(r)+str(int(r[-1])+1))
    R.append(temp)
    count+=len(temp)
N=N-(count-len(temp))
print(R[-1][N-1])
Buggy python submission (verdict: Runtime Error):
N = int(input()) 
a = list(map(int, input().split()))
a[0:0] = [-1, -1, -1]
x=1
for i in range(3,N+2):
  b=a[0:i-1]
  x = x*((b.count(a[i]-1)-b.count(a[i])))
  if x=0:x=1
x = x % 1000000007
print(x)

Fixed submission:
N = int(input()) 
a = list(map(int, input().split()))
b = [-1, -1, -1]
x=1
for i in range(N):
  x = x*b.count(a[i]-1) % 1000000007
  if b[0]==(a[i]-1):
    b[0]+=1
  elif b[1]==(a[i]-1):
    b[1]+=1
  else:
    b[2]+=1
print(x)