Harryxun/testdata huggingface dataset:
Buggy python submission (verdict: Time Limit Exceeded):
from math import floor
A,B,N=list(map(int,input().split()))
ans = 0
for x in range(N+1):
  a = floor(A*x/B)-A*floor(x/B)
  if ans < a:
    ans = a
  if B<x:
    break
print(ans)

Fixed submission:
from math import floor
A,B,N=list(map(int,input().split()))
x=min((B-1),N)
ans=floor(A*x/B)-A*floor(x/B)
print(ans)

Buggy python submission (verdict: Time Limit Exceeded):
from math import floor
A,B,N=list(map(int,input().split()))
ans = 0
for x in range(N,0,-1):
  a = floor(A*x/B)-A*floor(x/B)
  if ans <= a:
    ans = a
print(ans)

Fixed submission:
from math import floor
A,B,N=list(map(int,input().split()))
x=min((B-1),N)
ans=floor(A*x/B)-A*floor(x/B)
print(ans)
Buggy python submission (verdict: Time Limit Exceeded):
N,K=list(map(int,input().split()))
src=[n for n in range(N+1)]
ans=0
for k in range(K,N+2):
  M=sum(src[-k:])
  m=sum(src[0:k])
  ans+=M-m+1

print(ans%(10**9+7))

Fixed submission:
N,K=list(map(int,input().split()))
ans=0
for k in range(K,N+2):
  M=k*N-k*(k-1)//2
  m=k*(k-1)//2
  ans+=M-m+1

print(ans%(10**9+7))
Buggy python submission (verdict: Runtime Error):

src = input()
if src[3] == src[4] and src[5] == src[6]:
  print('Yes')
else:
  print('No')

Fixed submission:
a,b,c,d,e,f = input()
if c == d and e == f:
  print('Yes')
else:
  print('No')
Buggy python submission (verdict: Time Limit Exceeded):
from collections import Counter

N = int(input())
src = list(map(int,input().split()))
sor = Counter(src)

for n in range(N):
  i = src[n]
  count = 0
  for key,value in sor.items():
    if int(key) == i:
      count += (value-1)*(value-2)/2
    else:
      count += value*(value-1)/2
  print(int(count))

Fixed submission:
N = int(input())
src = list(map(int,input().split()))
dic = {}
for n in range(N):
  if dic.get(src[n]) == None:
    dic[src[n]] = 1
  else:
    dic[src[n]] += 1
a = 0
for key, value in dic.items():
  a += value*(value-1)//2
ans = []
for s in src:
  ans.append(a - dic[s]*(dic[s]-1)//2 + (dic[s]-1)*(dic[s]-2)//2)
for b in ans:
  print(b)
Buggy python submission (verdict: Runtime Error):
nums = [int(e) for e in input().split()]
for i in range(5):
  if not xs[i] == i:
    print(i)
    break

Fixed submission:
xs = [int(e) for e in input().split()]
for i in range(5):
  if not xs[i] == i+1:
    print(i+1)
    break

Buggy python submission (verdict: Runtime Error):
nums = [int(e) for e in input().split()]
for i in range(5):
  if not xs[i] == i:
    print(i)
    break

Fixed submission:
xs = [int(e) for e in input().split()]
for i in range(5):
  if not xs[i] == i+1:
    print(i+1)
    break

Buggy python submission (verdict: Runtime Error):
xs[5] = []
for i in range(5):
  xs.append(int(input()))
  if not xs[i] = i:
    print i
    break


Fixed submission:
xs = [int(e) for e in input().split()]
for i in range(5):
  if not xs[i] == i+1:
    print(i+1)
    break

Buggy python submission (verdict: Runtime Error):
xs[5] = []
for i in range(5):
  xs.append(int(input()))
  if not xs[i] == i:
    print i
    break


Fixed submission:
xs = [int(e) for e in input().split()]
for i in range(5):
  if not xs[i] == i+1:
    print(i+1)
    break

Buggy python submission (verdict: Runtime Error):
xs[5] = []
for i in range(5):
  xs.append(int(input()))
  if not xs[i] = i:
    print i
    break

Fixed submission:
xs = [int(e) for e in input().split()]
for i in range(5):
  if not xs[i] == i+1:
    print(i+1)
    break
Buggy python submission (verdict: Time Limit Exceeded):
input_line1 = input()
N = int(input_line1)
input_line2 = input()
numbers = input_line2.split()
num_sum = 1


for i in range(N):
    num_sum *= int(numbers[i])

if num_sum > 10 ** 18:
    num_sum = -1

print(num_sum)

Fixed submission:
input_line1 = input()
N = int(input_line1)
input_line2 = input()
numbers = input_line2.split()
num_sum = 1
 
if '0' in numbers:
    print(0)

else:
    for i in range(N):
        num_sum *= int(numbers[i])
        if num_sum > 10 ** 18:
            num_sum = -1
            break
 
    print(num_sum)
Buggy python submission (verdict: Runtime Error):
from sympy import divisors
input_line1 = input()
N = int(input_line1)
count = 0
D = len(divisors(N))

if D == 2:
    count = 1
else:
    for i in range (2,N):
        if N % i == 0:
            count += 1
            N = int(N / i)
            D = len(divisors(N))
            if D == 2:
                count += 1
                if N <= i:
                    count -= 1
                break
 
print(count)

Fixed submission:
N = int(input())
pf = {}
answer = 0

for i in range(2,int(N**0.5)+1):
    while N % i ==0:
        pf[i] = pf.get(i, 0) + 1
        N //= i
    
    if N < i:
        break
if N > 1:
    answer += 1
    
for j, k in pf.items():
    sq = 1
    for l in range(k):
        answer += 1
        k -= sq
        sq += 1
        if k == 0:
            break
        elif k < 0:
            answer -= 1
            break

print(answer)

Buggy python submission (verdict: Time Limit Exceeded):
input_line1 = input()

N = int(input_line1)
count = 0

for i in range (2,N):
    if N % i == 0:
        count += 1
        N = N / i

print(count)

Fixed submission:
N = int(input())
pf = {}
answer = 0

for i in range(2,int(N**0.5)+1):
    while N % i ==0:
        pf[i] = pf.get(i, 0) + 1
        N //= i
    
    if N < i:
        break
if N > 1:
    answer += 1
    
for j, k in pf.items():
    sq = 1
    for l in range(k):
        answer += 1
        k -= sq
        sq += 1
        if k == 0:
            break
        elif k < 0:
            answer -= 1
            break

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

A, B, K = map(int, input().split())

Max = int(math.gcd(A, B) )


list = [0] * 100

j =0

if A == 1 or B == 1:
    print("1")
    quit()

for i in range(Max):

    if i == 0:
        continue
    if Max % i == 0:
        list[j] = i
        j += 1


print(list[j - K+1])


Fixed submission:
#import math

def gcd(m,n):
    x = max(m, n)
    y = min(m, n)
    if x%y == 0:
        return y
    else:
        while x%y!= 0:
            z = x%y
            x = y
            y =z
        else:
            return z


A, B, K = map(int, input().split())

Max = int(gcd(A, B) )


list = [0] * 1000

j =0

if A == 1 or B == 1:
    print("1")
    quit()

for i in range(Max):

    if i == 0:
        continue
    if Max % i == 0:
        list[j] = i
        j += 1

if K == 1:
    print(Max)
    exit()

print(list[j - K+1])
Buggy python submission (verdict: Runtime Error):
#   AtCoder Beginner Contest 119
#   problem A: Still TBD

S = input() #-> yyyy/mm/dd

date = S.split('/')

year = int(date[0])
month = int(date[1])
day = int(date[2])

if month >= 5:
    print('TBD')
elif:
    print('Heisei')


Fixed submission:
#   AtCoder Beginner Contest 119
#   problem A: Still TBD

S = input() #-> yyyy/mm/dd

date = S.split('/')

year = int(date[0])
month = int(date[1])
day = int(date[2])

if month >= 5:
    print('TBD')
else:
    print('Heisei')

Buggy python submission (verdict: Runtime Error):
#   AtCoder Beginner Contest 119
#   problem A: Still TBD

S = input() #-> yyyy/mm/dd

date = S.split('/')

year = int(date[0])
month = int(date[1])
day = int(date[2])

if month >= 5:
    print('TBD')
elif
    print('Heisei')


Fixed submission:
#   AtCoder Beginner Contest 119
#   problem A: Still TBD

S = input() #-> yyyy/mm/dd

date = S.split('/')

year = int(date[0])
month = int(date[1])
day = int(date[2])

if month >= 5:
    print('TBD')
else:
    print('Heisei')
Buggy python submission (verdict: Runtime Error):
A, B, C = map(int, input().split)

P = min(A+B+1, C)
print(P+B)

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

P = min(A+B+1, C)
print(P+B)
Buggy python submission (verdict: Runtime Error):
a = input()
b = input()

if b[0:-1] == a
	print('Yes')
else:
	print('No')


Fixed submission:
S = input()
T = input()
if T[0:-1] == S:
  print('Yes')
else:
  print('No')

Buggy python submission (verdict: Runtime Error):
if chokudai == chokudai:
  print('no')
elif:
  print('yes')
  

Fixed submission:
S = input()
T = input()
if T[0:-1] == S:
  print('Yes')
else:
  print('No')
Buggy python submission (verdict: Runtime Error):
S = input()
W = input()

def sheep_wold(S=S, W=W):
    if S <= W:
        print('unsafe')
    else:
        print('safe')

Fixed submission:
s, w =  map(int, input().split())
if s <= w:
    print('unsafe')
else:
    print('safe')

Buggy python submission (verdict: Runtime Error):

S = input()
W = input()

if S <= W:
    print('unsafe')
else:
    print('safe')

Fixed submission:
s, w =  map(int, input().split())
if s <= w:
    print('unsafe')
else:
    print('safe')
Buggy python submission (verdict: Runtime Error):
from math import pi
def cicle(hankei):
    return 2 * hankei * pi

circle(1)
circle(73)

Fixed submission:
from math import pi

r = input()
print(2 * int(r) * pi)
Buggy python submission (verdict: Time Limit Exceeded):
from operator import mul
from functools import reduce
N=int(input())
li = list(map(int,input().split()))	
if reduce(mul, li)<=10**18:
  print(reduce(mul, li))
else:
  print("-1")

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

result = As[0]
if 0 in As:
    print(0)
else:
    for i in range(n-1):
        result = result*As[i+1]
        if result > 10**18 :
            print(-1)
            break
        else:
            continue
    if result <= 10**18 :
        print(result)
Buggy python submission (verdict: Runtime Error):
A,B,C,K=map(int,input().split())

if A>=K:
  print (K)
elif K>A and B>=K-A:
  print (A)
else:
  print (2*A-K+B)

Fixed submission:
import re

s=input()
t=input()

if len (t)>=len(s)+1 and re.match(s,t):
  print ("Yes")
else:
  print ("No")
Buggy python submission (verdict: Runtime Error):
a,v = map(int, input().split())
b,w = map(int, input().split())
t = int(input())
d = abs(a-b)
s = v - w
if s > 0 d/s <= t:
  print("YES")
else:
  print("NO")

Fixed submission:
a,v = map(int, input().split())
b,w = map(int, input().split())
t = int(input())
d = abs(a-b)
s = v - w
if s > 0 and d/s <= t:
  print("YES")
else:
  print("NO")

Buggy python submission (verdict: Runtime Error):
a,v = map(int, input().split())
b,w = map(int, input().split())
t = int(input())
d = abs(a-b)
s = v - w
if s > 0 and not d%s and d/ss <= t:
  print("YES")
else:
  print("NO")

Fixed submission:
a,v = map(int, input().split())
b,w = map(int, input().split())
t = int(input())
d = abs(a-b)
s = v - w
if s > 0 and d/s <= t:
  print("YES")
else:
  print("NO")

Buggy python submission (verdict: Runtime Error):
a,v = map(int, input().split())
b,w = map(int, input().split())
t = int(input())
d = abs(a-b)
ss = v+w
ms = abs(w-v)
if not d%ss and d/ss <= t:
  print("YES")
elif not d%ms and d/ms <= t:
  print("YES")
else:
  print("NO")
  

Fixed submission:
a,v = map(int, input().split())
b,w = map(int, input().split())
t = int(input())
d = abs(a-b)
s = v - w
if s > 0 and d/s <= t:
  print("YES")
else:
  print("NO")
Buggy python submission (verdict: Runtime Error):
print(input().index()//2+1)

Fixed submission:
print(input().index("0")//2+1)
Buggy python submission (verdict: Runtime Error):
n,m,k=[int(x) for x in input().split()]
#TODO Mutiply wih m
if m==1:
  if k==n-1: print(1)
  else: print(0)
  exit()
sumi=0
mod=998244353
prodi=pow(m-1,n-1,mod)
invi=pow(m-1,mod-2,mod)
for j in range(n-1,n-1-k-1,-1):
  sumi+=prodi
  sumi%=mod
  prodi*=j
  prodi%=mod
  prodi*=pow(n-j,mod-2,mod)
  prodi%=mod
  prodi*=invi
  prodi%=mod 
sumi*=m
sumi%=mod
print(sumi)
  

Fixed submission:
s=input()
t=input()
if s==t[0:len(t)-1]: print("Yes")
else: print("No")

Buggy python submission (verdict: Runtime Error):
n,m,k=[int(x) for x in input().split()]
#TODO Mutiply wih m
sumi=0
mod=998244353
prodi=pow(m-1,n-1,mod)
invi=pow(m-1,mod-2,mod)
for j in range(n-1,n-1-k-1,-1):
  sumi+=prodi
  sumi%=mod
  prodi*=n-j
  prodi%=mod
  prodi*=pow(j+1,mod-2,mod)
  prodi%=mod
  prodi*=invi
  prodi%=mod
sumi*=m
sumi%=mod
print(sumi)
  

Fixed submission:
s=input()
t=input()
if s==t[0:len(t)-1]: print("Yes")
else: print("No")
Buggy python submission (verdict: Time Limit Exceeded):
n,k=[int(x) for x in input().split()]
p=[(int(x)-1) for x in input().split()]
a=[0]
i=0
while p[i] not in a:
  a.append(p[i])
  i=p[i]
l=a.index(p[i])
if k<=l: print(1+a[k])  
else: print(1+a[l+(k-l)%(len(a)-l)])

Fixed submission:
n,k=[int(x) for x in input().split()]
p=[(int(x)-1) for x in input().split()]
alp=[0 for _ in range(n)]
a=[0]
i=0
alp[0]=1
while alp[p[i]]==0:
  a.append(p[i])
  alp[p[i]]=1
  i=p[i]
l=a.index(p[i])
if k<=l: print(1+a[k])
else: print(1+a[l+(k-l)%(len(a)-l)])

Buggy python submission (verdict: Time Limit Exceeded):
n,k=[int(x) for x in input().split()]
p=[int(x)-1 for x in input().split()]
a=[0]
i=0
while p[i]!=0:
  a.append(p[i])
  i=p[i]
print(a[k%len(a)]+1)

Fixed submission:
n,k=[int(x) for x in input().split()]
p=[(int(x)-1) for x in input().split()]
alp=[0 for _ in range(n)]
a=[0]
i=0
alp[0]=1
while alp[p[i]]==0:
  a.append(p[i])
  alp[p[i]]=1
  i=p[i]
l=a.index(p[i])
if k<=l: print(1+a[k])
else: print(1+a[l+(k-l)%(len(a)-l)])

Buggy python submission (verdict: Time Limit Exceeded):
n,k=[int(x) for x in input().split()]
p=[int(x)-1 for x in input().split()]
a=[0]
i=0
while p[i]!=0:
  a.append(p[i])
  i=p[i]
print(a[k%len(a)]+1)

Fixed submission:
n,k=[int(x) for x in input().split()]
p=[(int(x)-1) for x in input().split()]
alp=[0 for _ in range(n)]
a=[0]
i=0
alp[0]=1
while alp[p[i]]==0:
  a.append(p[i])
  alp[p[i]]=1
  i=p[i]
l=a.index(p[i])
if k<=l: print(1+a[k])
else: print(1+a[l+(k-l)%(len(a)-l)])
Buggy python submission (verdict: Runtime Error):
n,m,k=[int(x) for x in input().split()]
#TODO Mutiply wih m
sumi=0
mod=998244353
prodi=pow(m-1,n-1,mod)
invi=pow(m-1,mod-2,mod)
for j in range(n-1,n-1-k-1,-1):
  sumi+=prodi
  sumi%=mod
  prodi*=n-j/j+1
  prodi%=mod
  prodi*=pow(j+1,mod-2,mod)
  prodi%=mod
  prodi*=invi
  prodi%=mod
sumi+=prodi
sumi%=mod
sumi*=m
sumi%=mod

  

Fixed submission:
n,m,k=[int(x) for x in input().split()]
#TODO Mutiply wih m
if m==1:
  if k==n-1: print(1)
  else: print(0)
  exit()
sumi=0
mod=998244353
prodi=pow(m-1,n-1,mod)
invi=pow(m-1,mod-2,mod)
for j in range(n-1,n-1-k-1,-1):
  sumi+=prodi
  sumi%=mod
  prodi*=j
  prodi%=mod
  prodi*=pow(n-j,mod-2,mod)
  prodi%=mod
  prodi*=invi
  prodi%=mod 
sumi*=m
sumi%=mod
print(sumi)
Buggy python submission (verdict: Runtime Error):
a,b,c=[int(x) for x in input().split()]
if c<=a or c<=b: print("No")
elif 2(a*b+b*c+c*a)<a**2+b**2+c**2: print("Yes")
else: print("No")

Fixed submission:
a,b,c=[int(x) for x in input().split()]
if c<=a or c<=b: print("No")
elif 2*(a*b+b*c+c*a)<a**2+b**2+c**2: print("Yes")
else: print("No")

Buggy python submission (verdict: Runtime Error):
a,b,c=[int(x) for x in input().split()]
if c<=a or c<=b: print("No")
else if 2(a*b+b*c+c*a)<a**2+b**2+c**2: print("Yes")
else: print("No")

Fixed submission:
a,b,c=[int(x) for x in input().split()]
if c<=a or c<=b: print("No")
elif 2*(a*b+b*c+c*a)<a**2+b**2+c**2: print("Yes")
else: print("No")
Buggy python submission (verdict: Runtime Error):
arr = input().spilt()
arr = int(arr)
print(15-sum(arr))

Fixed submission:
arr = list(map(int, input().split()))
print(15-sum(arr))
Buggy python submission (verdict: Runtime Error):
n, k = map(int, input().split())
list = []
for p in range(k):
  m = int(input())
  k_list = list(map(int, input().split()))
  for q in k_list:
    if not q in list:
      list.append(q)
k_l = len(k_list)
print(n-k_l)

Fixed submission:
n, k = map(int, input().split())
list = []
for p in range(k):
  d = int(input())
  k_list = [int(x) for x in input().split()]
  m = len(k_list)
  for q in k_list:
    if not q in list:
      list.append(q)
l = len(list)
print(n - l)
Buggy python submission (verdict: Time Limit Exceeded):
a, b, n = map(int, input().split())
c_0 = 0
m = min(n+1, b)
for x in range(1, m):
  if x % b == 0:
    c = 0
  else:
    c = int(a * x / b)
    if c >= c_0:
      c_0 = c
print(c_0)

Fixed submission:
a, b, n = map(int, input().split())
c_0 = 0
m = min(n, b-1)
x = int(a * m / b)
print(x)

Buggy python submission (verdict: Time Limit Exceeded):
a, b, n = map(int, input().split())
c_0 = 0
m = min(n, b) + 1
for x in range(1, m):
  if x % b == 0:
    c = 0
  else:
    c = int(a * x / b)
    if c >= c_0:
      c_0 = c
print(c_0)

Fixed submission:
a, b, n = map(int, input().split())
c_0 = 0
m = min(n, b-1)
x = int(a * m / b)
print(x)
Buggy python submission (verdict: Time Limit Exceeded):
n = int(input())
list = []
for i in range(n):
  s = input()
  if not s in list:
    list.append(s)
print(len(list))

Fixed submission:
n = int(input())
list = []
for i in range(n):
  s = input()
  list.append(s)
print(len(set(list)))
Buggy python submission (verdict: Runtime Error):
n = int(input())
flag = 0
list = [int(x) for x in input().split()]
for i in range(1, n):
  if flag == n:
    break
  else:
    m = list[i-1:].count(i)
    flag += m
    print(m)
print(0)

Fixed submission:
r =int(input())
print(6.28*r)

Buggy python submission (verdict: Runtime Error):
r =int(imput())
print(6.28*r)

Fixed submission:
r =int(input())
print(6.28*r)
Buggy python submission (verdict: Runtime Error):
n = int(input())
l = [int(x) for x in input().split()]
a = 0
b = 0
for i in range(n):
  if i % 2 == 0:
    a += max(l)
    l = l.remove(max(l))
  elif i % 2 == 1:
    b += max(l)
    l = l.remove(max(l))
print(a-b)

Fixed submission:
n = int(input())
l = [int(x) for x in input().split()]
a = 0
b = 0
for i in range(n):
  if i % 2 == 0:
    a += max(l)
    l.remove(max(l))
  elif i % 2 == 1:
    b += max(l)
    l.remove(max(l))
print(a-b)
Buggy python submission (verdict: Runtime Error):
X,Y=map(int,input().split())
for i in range(X+1):
  if Y==2*i+4*(X-i):
    print('YES')
    exit()
print('NO')

Fixed submission:
l=input().split()
for i in range(5):
  a = str(0)
  if l[i]==a:
    print(i+1)
Buggy python submission (verdict: Runtime Error):
a,v=map(int,input().split())
b,w=map(int,input().split())
t=int(input())
if b-a>=0:
  if (v-w)*t >= b-a:
    print('YES')
  else:
    print('NO')
else:
  print('NO')



Fixed submission:
a=input()
b=list(a)
c=b[0:3]
d="".join(c)
print(d)
Buggy python submission (verdict: Runtime Error):
N = int(input())
A = [int(x) for x in input().split()]
 
for i in N:
  if A[i]==0:
    print int(i)

Fixed submission:
A = [int(x) for x in input().split()]
N = int(len(A))

for i in range(N):
  if A[i]-0==0:
    print(i+1)

Buggy python submission (verdict: Runtime Error):
N = int(input())
A = [int(x) for x in input().split()]

for i in N:
  if A[i]==0:
    return i

Fixed submission:
A = [int(x) for x in input().split()]
N = int(len(A))

for i in range(N):
  if A[i]-0==0:
    print(i+1)
Buggy python submission (verdict: Runtime Error):
# 行数
N = int(input().strip())

# 2次元配列
grid = []
for i in range(N):
    array = list(input().strip().split())
    grid.append(array)
    grid[i][1]=int(grid[i][1])
print(grid)
agrid=sorted(grid)
for i in range(N-1):
  if agrid[i][0]==agrid[i+1][0] and agrid[i][1]<agrid[i+1][1]:
    b=agrid[i+1]
    c=agrid[i]
    agrid[i]=b
    agrid[i+1]=c
for i in range(N):
  print(agrid[i][1])

Fixed submission:
x=input()
xx=x.split()
A=int(xx[0])
P=int(xx[1])
a=(A*3+P)/2
print(int(a))

Buggy python submission (verdict: Runtime Error):
x=input()
xx=x.split()
A=xx[0]
P=xx[1]
a=(A*3+P)/2
print(a)

Fixed submission:
x=input()
xx=x.split()
A=int(xx[0])
P=int(xx[1])
a=(A*3+P)/2
print(int(a))
Buggy python submission (verdict: Runtime Error):
x=input()
b=int(x[0])
c=int(x[2])
a=b-c+1
print(a)

Fixed submission:
x=input()
xx=x.split()
b=int(xx[0])
c=int(xx[1])
a=b-c+1
print(a)

Buggy python submission (verdict: Runtime Error):
import math.factorial as mf

def select(N,K):
  a=mf(N)/(mf(K)*mf(N-K))
  return a

Fixed submission:
x=input()
xx=x.split()
b=int(xx[0])
c=int(xx[1])
a=b-c+1
print(a)
Buggy python submission (verdict: Runtime Error):
N=int(input())
if N[-1] == 3:
  print('bon')
elif N[-1] in [0,1,6,8]:
  print('pon')
else:
  print('hon')

Fixed submission:
N=input()
if N[-1] == '3':
  print('bon')
elif N[-1] in ['0','1','6','8']:
  print('pon')
else:
  print('hon')
Buggy python submission (verdict: Time Limit Exceeded):
N,K=map(int,input().split())
A=list(map(int,input().split()))
A=[-1]+A
still=[1]
before=1
rS=-1
root=[1]
while True:
  dest=A[before]
  if dest in still:
    rS=dest
    break
  else:
    still.append(dest)
    root.append(dest)
    before=dest
#print(root,rS)
num=0
for i in root:
  if i==rS:
    break
  num+=1
#print(num)
if K<=num:
  print(root[K])
else:
  K-=num
  root2=root[num:]
  print(root2[K%len(root2)])
  

Fixed submission:
N,K=map(int,input().split())
A=list(map(int,input().split()))
A=[-1]+A
still=[0]*(N+1)
still[1]=1
before=1
rS=-1
root=[1]
while True:
  dest=A[before]
  if still[dest]==1:
    rS=dest
    break
  else:
    still[dest]=1
    root.append(dest)
    before=dest
#print(root,rS)
num=0
for i in root:
  if i==rS:
    break
  num+=1
#print(num)
if K<=num:
  print(root[K])
else:
  K-=num
  root2=root[num:]
  print(root2[K%len(root2)])
Buggy python submission (verdict: Runtime Error):
S=input()
if S='ABC':
  print('ARC')
else:
  print('ABC')

Fixed submission:
S=input()
if S=='ABC':
  print('ARC')
else:
  print('ABC')
Buggy python submission (verdict: Time Limit Exceeded):
N=int(input())
A=list(map(int,input().split()))
ans=0
for  i in range(N-1):
  for j in range(i+1,N):
    if abs(i-j)==A[i]+A[j]:
      ans+=1
print(ans)

Fixed submission:
import bisect
N=int(input())
A=list(map(int,input().split()))
A1=[]
A2=[]
for i in range(N):
  A1.append(i+1+A[i])
  A2.append(i+1-A[i])
A1.sort()
#A2.sort()
ans=0
for i in range(N):
  ai=A[i]
  i+=1
  ans+=bisect.bisect_right(A1,i-ai)-bisect.bisect_left(A1,i-ai)
  #ans+=bisect.bisect_right(A2,i+ai)-bisect.bisect_left(A2,i+ai)
print(ans)
Buggy python submission (verdict: Time Limit Exceeded):
S=input()
unko=[0]*2019
tmp=0
num=1
for s in S[::-1]:
  s=int(s)
  tmp+=num * s
  num=num*10
  unko[tmp%2019]+=1
ans=0
ans+=(unko[0]+1)*unko[0]/2
for i in unko[1:]:
  ans+=i*(i-1)/2
print(int(ans))

Fixed submission:
S=input()
unko=[0]*2019
tmp=0
num=1
for s in S[::-1]:
  s=int(s)
  tmp=(tmp+s*num)%2019
  num=(num*10)%2019
  unko[tmp]+=1
ans=0
ans+=(unko[0]+1)*unko[0]/2
for i in unko[1:]:
  ans+=i*(i-1)/2
print(int(ans))

Buggy python submission (verdict: Time Limit Exceeded):
S=input()
ans=0
for i in range(len(S)):
  for j in range(len(S)-i):
    j+=i+1
    tmp=S[i:j]
    tmp=int(tmp)
    if tmp%2019==0:
      ans+=1
print(ans)

Fixed submission:
S=input()
unko=[0]*2019
tmp=0
num=1
for s in S[::-1]:
  s=int(s)
  tmp=(tmp+s*num)%2019
  num=(num*10)%2019
  unko[tmp]+=1
ans=0
ans+=(unko[0]+1)*unko[0]/2
for i in unko[1:]:
  ans+=i*(i-1)/2
print(int(ans))
Buggy python submission (verdict: Time Limit Exceeded):
N=int(input())
S=input()
ans=0
RGB_dict={'R':0,'G':0,'B':0}
for s in S:
  RGB_dict[s]+=1
ans=RGB_dict['R']*RGB_dict['G']*RGB_dict['B']

for i in range(N-1):
  s1=S[i]
  for j in range(i+1,N):
    s2=S[j]
    if s1==s2: continue
    k=j+(j-i)
    if k>N-1: continue
    #print(k)
    s3=S[k]
    if s1!=s3 and s2!=s3:
      ans-=1
print(ans)

Fixed submission:
N=int(input())
S=input()
ans=0
RGB_dict={'R':0,'G':0,'B':0}
for s in S:
  RGB_dict[s]+=1
ans=RGB_dict['R']*RGB_dict['G']*RGB_dict['B']

for i in range(N-1):
  s1=S[i]
  for j in range(i+1,N):
    s2=S[j]
    if s1==s2: continue
    k=j+(j-i)
    if k>N-1: continue
    #print(k)
    s3=S[k]
    if s1!=s3 and s2!=s3:
      ans-=1
print(ans)

Buggy python submission (verdict: Time Limit Exceeded):
N=int(input())
S=input()
ans=0
for j in range(1,N-1):
  s1=S[j]
  for i in range(0,j):
    s2=S[i]
    if s1==s2: continue
    jmi=j-i
    for k in range(j+1,N):
      if k-j==jmi: continue
      s3=S[k]
      if s1!=s3 and s2!=s3:
        ans+=1
print(ans)

Fixed submission:
N=int(input())
S=input()
ans=0
RGB_dict={'R':0,'G':0,'B':0}
for s in S:
  RGB_dict[s]+=1
ans=RGB_dict['R']*RGB_dict['G']*RGB_dict['B']

for i in range(N-1):
  s1=S[i]
  for j in range(i+1,N):
    s2=S[j]
    if s1==s2: continue
    k=j+(j-i)
    if k>N-1: continue
    #print(k)
    s3=S[k]
    if s1!=s3 and s2!=s3:
      ans-=1
print(ans)