Harryxun/stf_run huggingface dataset:
import math
import collections
import fractions
import itertools
import functools
import operator
import bisect

def solve():
    n = int(input())
    ans = ["a"]
    alt = [chr(ord("a") + i) for i in range(n)]
    for i in range(n-1):
        ans = [s+x for s in ans for x in alt [0:len(set(ans))+1]]
    for i in ans:
        print(ans)
    return 0

if __name__ == "__main__":
    solve()

### FIXED CODE ###

import math
import collections
import fractions
import itertools
import functools
import operator
import bisect

def solve():
    n = int(input())
    sushi = ["a"]
    alt = [chr(ord("a") + i) for i in range(n)]
    for i in range(n-1):
        sushi = [ans + x for ans in sushi for x in alt[:len(set(ans)) + 1]]
    for i in sushi:
        print(i)
    return 0

if __name__ == "__main__":
    solve()
N = int(input())
if N > 15:
    discount = N // 15
print(N * 800 - discount * 200)


### FIXED CODE ###

N = int(input())
discount = 0
if N > 15:
    discount = N // 15
print(N * 800 - discount * 200)
s = input()
t = 'keyence'
cnt = 0
j = False
p = 0
for i in range(len(s)):
  if t[p] == s[i]:
    if j == True:
      j = False
      cnt = cnt + 1
    p = p + 1
  else:
    j = True
print('YES' if p == len(t) and cnt <= 1 else 'N0')

### FIXED CODE ###


def solve(s):
  t = 'keyence'
  if t in s[0:7] or t in s[-7:]:
    return 'YES'

  p = 0
  for i in range(len(s)):
    if t[p] == s[i]:
      p = p + 1
    else:
      if t[p:] in s[-7+p:]:
        return 'YES'
      else:
        return 'NO'
  return 'NO'

print(solve(input()))
a,b,c,d,e,mv=map(int,input().split())
ans=0
for i in range(31):
    for j in range(31):
        for k in range(31):
            for l in range(31):
                water=100*(a*i+b*j)
                sugar=k*c+l*d
                if water+sugar > mv:
                    break
                pp= 100*sugar/(water+sugar)
                if e<= pp and ans<pp:
                    ans1= water+sugar
                    ans2= sugar
print(ans1,ans2)

### FIXED CODE ###

a,b,c,d,e,mv=map(int,input().split())
e= e/(e+100)

ans=-1
for i in range(31):
    if 100*i*a> mv: continue
    for j in range(31):
        if i+j==0:continue
        if 100*(i*a+j*b)> mv:continue
        for k in range(2801):
            if 100*(i*a+j*b)+k*c> mv:continue
            for l in range(2801):
                water=100*(a*i+b*j)
                sugar=k*c+l*d
                if water+sugar > mv:
                    break
                pp= sugar/(water+sugar)
                
                if e>= pp and ans<pp:
                    #print("water",water,"sugar",sugar,pp)
                    ans=pp
                    ans1= water+sugar
                    ans2= sugar
print(ans1,ans2)
a = [[j for j in map(int,input().split())] for i in range(3)]
n = int(input())
b = [[int(j) for j in input()] for i in range(n)]

for i in range(3):
    for j in range(3):
        for k in range(n):
            if a[i][j] == b[k]:
                a[i][j] = 0

if sum(a[0]) == 0 or sum(a[1]) == 0 or sum(a[2]) == 0:
    print('Yes')
elif a[0][0] + a[1][1] + a[2][2] == 0 or a[0][2] + a[1][1] + a[3][0] == 0:
    print('Yes')
else:
    print('No')

### FIXED CODE ###

import numpy as np
a = [[j for j in map(int,input().split())] for i in range(3)]
n = int(input())
b = [int(input()) for i in range(n)]

for i in range(3):
    for j in range(3):
        for k in range(n):
            if a[i][j] == b[k]:
                a[i][j] = 0
a = np.array(a)
if sum(a[0,:]) == 0 or sum(a[1,:]) == 0 or sum(a[2,:]) == 0:
    print('Yes')
elif sum(a[:,0]) == 0 or sum(a[:,1]) == 0 or sum(a[:,2]) == 0:
    print('Yes')
elif (a[0][0] + a[1][1] + a[2][2]) == 0 or (a[0][2] + a[1][1] + a[2][0]) == 0:
    print('Yes')
else:
    print('No')
N,*L = open('0').read().split()

ans = 0
a = 0
b = 0
for s in L:
  for j in range(len(s)-1):
    if s[j]=='A' and s[j+1]=='B':
      ans += 1
  if s[-1]=='A':
    a += 1
  if s[0]=='B':
    b += 1
ans += min(a,b)
print(ans)
  

### FIXED CODE ###

N,*L = open(0).read().split()

ans = 0
a = 0
b = 0
c = 0
for s in L:
  for j in range(len(s)-1):
    if s[j]=='A' and s[j+1]=='B':
      ans += 1
  if s[-1]=='A' and s[0]=='B':
    c += 1
  elif s[-1]=='A':
    a += 1
  elif s[0]=='B':
    b += 1
if c!=0:
  if a+b>0:
    ans += c+min(a,b)
  else:
    ans += c-1
else:
  ans += min(a,b)
print(ans)
ans=0
for i in range(1000000):
    cnt=N.count("BW")
    ans=ans+cnt
    N=N.replace("BW","WB")
    N=N.lstrip("W")
    N=N.rstrip("B")
    if cnt==0:
        break
print(ans)

### FIXED CODE ###

from sys import stdin
N=(stdin.readline().rstrip())
N=list(N)
cnt=0
ans=0
for i in N:
    if i=="B":
        cnt+=1
    else:
        ans+=cnt
print(ans)
A, B, C, D, E, F = map(int, input().split())
def gcd(x, y):
    xx = (abs(x+y)-abs(x-y)) // 2
    yy = (abs(x+y)+abs(x-y)) // 2
    if yy % xx == 0:
        return xx
    else:
        return gcd(yy % xx, xx)

g = gcd(C, D)
Cmax = 0
Hmax = 0
Smax = 0
for p in range(F // (100*A) + 2):
    for q in range((F - 100*p*A) // (100*B) + 2):
        H2O = 100 * p * A + 100 * q * B
        lev = min([F - H2O, E*H2O // 100])
        sugar = 0
        if lev > 0 and H2O != 0:
            if lev < C:
                sugar = 0
            elif lev < C + D - q:
                sugar = max([(lev // C)*C, (lev//D)*D,])
            else:
                sugar = (lev // g) * g
            if Cmax*(H2O+sugar) <= sugar:
                Cmax = sugar / (H2O+sugar)
                Hmax = H2O
                Smax = sugar

print("{0} {1}".format(Smax+Hmax, Smax))


### FIXED CODE ###

N = int(input())
A = int(input())
print(N ** 2 - A)
N = int(input())
a = [int(i) for i in input().split()]

a.sort()
for i in range(N):
    if 

### FIXED CODE ###

import bisect

N = int(input())
a = [int(i) for i in input().split()]

a.sort()
pullout = 0
#print(a)

for i in list(set(a)):
    numi = bisect.bisect_right(a,i) - bisect.bisect_left(a,i)
    #print(i,numi)
    if numi == 0 or numi == i:
        continue
    elif numi > i:
        pullout += numi - i
    elif numi < i:
        pullout += numi

print(pullout)
n,k,q=map(int,input().split())
A=[int(input()) for i in range(q)]

tokuten=[0]*n

for i in range(q):
    tokuten[A[i-1]-1]=tokuten[A[i-1]-1]+1

for i in range(n):
    if tokuten[i]>=q-k+1
        print("Yes")
    else:
        print("No")

### FIXED CODE ###

n,k,q=map(int,input().split())
A=[int(input()) for i in range(q)]

tokuten=[0]*n

for i in range(q):
    tokuten[A[i-1]-1]=tokuten[A[i-1]-1]+1

for i in range(n):
    if tokuten[i]>q-k:
        print("Yes")
    else:
        print("No")
n,v=[int(k) for k in input().split()]
li=[]
for i in range(n):
  li.append([int(k) for k in input().split()])
  
dp=[[0 for i in range(v+1)] for j in range(n+1)]
for a in range(1,n+1):
  for b in range(1,v+1):
    if(li[a-1][0]<=b):
      dp[a][b]=max(li[a-1][1]+dp[a-1][b-li[a-1][0]],dp[a-1][b])
    else:
      dp[a][b]=dp[a-1][b]
print(dp[n][v]%mod)      
      
  


### FIXED CODE ###

n,v=[int(k) for k in input().split()]
li=[]
for i in range(n):
  li.append([int(k) for k in input().split()])
  
dp=[[0 for i in range(v+1)] for j in range(n+1)]
for a in range(1,n+1):
  for b in range(1,v+1):
    if(li[a-1][0]<=b):
      dp[a][b]=max(li[a-1][1]+dp[a-1][b-li[a-1][0]],dp[a-1][b])
    else:
      dp[a][b]=dp[a-1][b]
print(dp[n][v])
s=input()
print("Yes" if s.count(s[0])==2 and s.count(s[1])==2 s.count(s[2])==2 s.count(s[3])==2 else "No"   )

### FIXED CODE ###

s=input()
print("Yes" if s.count(s[0])==2 and s.count(s[1])==2 and s.count(s[2])==2 and s.count(s[3])==2 else "No"   )
#要素の探索はlistで→stringでできんか？
list=["A","B","C","D","E","F"]
x=list.index(input())
y=list.index(input())
print("=" if x==y else ">" if x>y else "<")


### FIXED CODE ###

x,y=map(str,input().split())
print("=" if x==y else ">" if x>y else "<")
import math
a,b=map(float,input().split())
int(round(a*b,0))
print(x)

### FIXED CODE ###

a,b=input().split()
a=int(a)
b=float(b)
b=int(b*1000)
print(a*b//1000)
import math

k=int(input())
cnt=0
for a in range(k):
  a=a+1
  for b in range(k):
    b=b+1
    for c in range(k):
      c=c+1
      cnt=cnt+math.gcd(a,b,c)
print(cnt)
      
      
  

### FIXED CODE ###

import math
 
k=int(input())
cnt=0
tmp=[]
for a in range(k):
  a=a+1
  for b in range(k):
    b=b+1
    tmp.append(math.gcd(a,b))
for i in tmp:
  if i==1:
    cnt=cnt+k
  else:
    for j in range(k):
      j=j+1
      cnt=cnt+math.gcd(i,j)
print(cnt)
n,k = map(int, input().split())
V = list(map(int, input().split()))

maxsum = -10**13
for i in range(min(n+1,k+1)):
    for j in range(min(n+1-i,k+1-i)):
        su = (V[:i] + V[:n-j-1:-1])
        su.sort()
        sumsu = sum(su)
        #print("i,j:",i,j,su)
        if k-i-j > 0:
            for l in range(k-i-j):
                if len(su) > l and su[l] < 0: sumsu -= su[l]
        maxsum = sumsu if maxsum < sumsu else maxsum
print(maxsum)

### FIXED CODE ###

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

maxsum = -10**13
for i in range(min(n+1,k+1)):
    for j in range(min(n+1-i,k+1-i)):
        su = (V[:i] + V[:n-j-1:-1])
        su.sort()
        sumsu = sum(su)
        #print("i,j:",i,j,su)
        if k-i-j > 0:
            for l in range(k-i-j):
                if len(su) > l and su[l] < 0: sumsu -= su[l]
        maxsum = sumsu if maxsum < sumsu else maxsum
print(maxsum)
input = x:
if '7' in x:
    print('Yes')
else:
    print('No')

### FIXED CODE ###

x = input()
if '7' in x:
    print('Yes')
else:
    print('No')
n = int(input())

xlist=[]
sum=0
for i in range(n):
    xlist.append(input().split())
    if xlist[i][1] == "BTC":
        sum = sum + int(xlist[i][0])*380000
    else:
        sum = sum + int(xlist[i][0])

print(sum)


### FIXED CODE ###


n = int(input())

xlist=[]
sum=0
for i in range(n):
    xlist.append(input().split())
    if xlist[i][1] == "BTC":
        sum = sum + float(xlist[i][0])*380000
    else:
        sum = sum + float(xlist[i][0])

print(sum)
room,path = map(int,input().split())
dic = {}
ans_dic = {}
g = [1]
g_m = []

def re(li,i):
    if li[0] == i:
        return li[1]
    else:
        return li[0]

def pile_del(g):
    t = []
    for key,i in dic.items():
        if i[0] in g and  i[1] in g:
            t.append(key)
    for i in t:
        dic.pop(i)
    return 0

def main(ans_dic,dic,k):
    dele = []
    for key,j in dic.items():
        if k in j :
            ans_dic[re(j,k)] = j
            dele.append(key)
            g.append(re(j,k))
            g_m.append(re(j,k))
    for i in dele:
        dic.pop(i)
    pile_del(g_m)

for i in range(path):
    dic[i+1] = list(map(int,input().split()))

for key,i in dic.items():
    if 1 in i :
        if i[0] == 1:
            g.append(re(i,i[0]))
            # g_m.append(re(i,i[0]))
            ans_dic[i[1]] = i
        else:
            g.append(re(i,i[1]))
            # g_m.append(re(i,i[1]))
            ans_dic[i[0]] = i

pile_del(g)

li_c = len(dic)

if li_c != 0:
    for k in g:
        main(ans_dic,dic,k)

while li_c != len(dic) and li_c != 0:
    li_c = len(dic)
    for k in g:
        main(ans_dic,dic,k)



if len(ans_dic) == room-1:
    print("Yes")
    for i in range(room-1):
        print(re(ans_dic[i+2],i+2))
else:
    print("No")
# print(ans_dic)

### FIXED CODE ###

s = str(input())
hon = [2,4,5,7,9]
pon = [0,1,6,8]


if int(s[-1]) in hon:
    print("hon")
elif int(s[-1]) in pon:
    print("pon")
else:
    print("bon")
import sys;input=sys.stdin.readline
from bisect import*

n,q=map(int,input().split())
event=[]
stopped={-1}

def doevent(l):
    global stopped
    if l[1]==1:
        if stopped=={-1}:
            stopped=set()
        stopped.add(l[2])
    elif l[1]==-1:
        stopped.remove(l[2])
        if len(stopped)==0:
            stopped={-1}
            
for i in range(n):
    s,t,x=map(int,input().split())
    event.append((s-x,1,x))
    event.append((t-x,-1,x))
event.append((-float("inf"),"x","x"))
event.append((float("inf"),"x","x"))
event.sort(key=lambda x:x[0])
eventtime=[i[0]for i in event]
#print(eventtime)
query=[bisect_right(eventtime,int(input()))-1 for i in range(q)]
#print(query)
c=0
#print(event)
for i in range(2*n):
    doevent(event[i])
    while i==query[c]:
        print(min(stopped))
        c+=1
for i in range(query.count(2*n)):
    print(-1)

### FIXED CODE ###

import sys;input=sys.stdin.readline

n,q=map(int, input().split())
event=[]
for _ in range(n):
    s,t,x=map(int,input().split())
    event.append((s-x-0.5,1,x))
    event.append((t-x-0.5,-1,x))
for i in range(q):
    event.append((int(input()),0,i))
    
event.sort()
is_stop=False
stop=set()
minstop=float('inf')
ans=[-1]*q
for t,e,x in event:
    if e > 0:
        stop.add(x)
        if x<minstop:
            minstop=x
            is_stop=True
    elif e<0:
        stop.remove(x)
        if minstop==x:
            is_stop=False
    elif len(stop)>0:
        if not is_stop:
             minstop=min(stop)
             is_stop=True
        ans[x]=minstop
        
print('\n'.join(map(str, ans)))
from math import factorial

def cmb(n,k):
    if n < k or n < 0 or k < 0:
        return 0
    return int(factorial(n)/(factorial(k)*factorial(n-k)))

N, K = map(int, input().split())

for i in range(1, K+1):
    ans = cmb(K-1, i-1) * cmb(N-K+1, i)
    print(ans%(10**9+7))

### FIXED CODE ###

from math import factorial

def cmb(n,k):
    if n < k or n < 0 or k < 0:
        return 0
    return factorial(n)//(factorial(k)*factorial(n-k))

N, K = map(int, input().split())

for i in range(1, K+1):
    ans = cmb(K-1, i-1) * cmb(N-K+1, i)
    print(ans%(10**9+7))
N,K = [int(i) for i in input().split()]
D = [int(i) for i in input().split()]
use = [0,1,2,3,4,5,6,7,8,9]
Keta = []
Keta.append(N // 1000)
Keta.append(N % 1000 // 100)
Keta.append(N % 1000 % 100 // 10)
Keta.append(N % 1000 % 100 % 10)
#print("Keta is {}".format(Keta))
Keta_Min = []

for i in range(len(D)):
    use.remove(D[i])
#print("use is {}".format(use))
for i in range(4):
    A = []
    for j in range(len(use)):
        if Keta[i] <= use[j]:
            A.append(use[j])
    print(i,A)
    Keta_Min.append(min(A))

Answer = 0
Answer = Keta_Min[0] * 1000 + Keta_Min[1] * 100 + Keta_Min[2] * 10 + Keta_Min[3]
print(Answer)


### FIXED CODE ###

N,K = [int(i) for i in input().split()]
#D = [int(i) for i in input().split()]は数値代入
#文字列を複数代入
D = input().split()
#集合に置き換える(型はset)
D = set(D)
use = set(['0','1','2','3','4','5','6','7','8','9'])
use -= D

for i in range(N,100*N):
    if use >= set(str(i)):
        print(i)
        break
def divisor(m,k):
  divisor=[]
  for i in range(1,k+1):
    if m%i==0:
      divisor.append(i)
  return divisor

n,m=(int(i) for i in input().split(' '))
print(divisor(m,m//n))
for i in divisor(m)[::-1]:
  if i==1:
    break
  if m%i==0 and m//i>=n:
    print(i)
    break


### FIXED CODE ###

import random

def is_prime(q,k=50):
    if q == 2: return True
    if q < 2 or q&1 == 0: return False
    d = (q-1)>>1
    while d&1 == 0:
        d >>= 1
    for i in range(k):
        a = random.randint(1,q-1)
        t = d
        y = pow(a,t,q)
        while t != q-1 and y != 1 and y != q-1: 
            y = pow(y,2,q)
            t <<= 1
        if y != q-1 and t&1 == 0:
            return False
    return True

n,m=(int(i) for i in input().split(' '))
for i in range(1,n):
  if m%i==0 and (is_prime(i) or i==1) and is_prime(m//i) and (i==1 or m//i<n):
    print('1')
    exit()
for i in range(n,m+1):
  if i==m:
    print(1)
    break
  if m%i==0:
    print(m//i)
    break
  if m-i-n>0 and m%(m-i-n)==0 and m//(m-i-n)>n:
    print(m-i-n)
    break
H, W = map(int, input().split())
A = [list(map(int, input().split())) for _ in range(H)]
B = [list(map(int, input().split())) for _ in range(H)]

C = [[] for _ in range(H)]
for i in range(H):
  for j in range(W):
    C[i].append(abs(A[i][j] - B[i][j]))
#print(C)

ww = max([sum(C[i]) for i in range(H)])
hh = max([sum([C[j][i] for j in range(H)]) for i in range(W)])

dp = [[[0 for _ in range(hh + ww + 1)] for _ in range(W)] for _ in range(H)]
#print(dp)

dp[0][0][C[0][0]] = 1
for i in range(H):
  for j in range(W):
    for k in range(hh + ww + 1):
      if dp[i-1][j][k]:
        dp[i][j][k + C[i][j]] = 1
        dp[i][j][abs(k - C[i][j])] = 1
      if dp[i][j-1][k]:
        dp[i][j][k + C[i][j]] = 1
        dp[i][j][abs(k - C[i][j])] = 1

for i in range(hh + ww + 1):
  if dp[H-1][W-1][i]:
    print(i)
    exit()

### FIXED CODE ###

H, W = map(int, input().split())
A = [list(map(int, input().split())) for _ in range(H)]
B = [list(map(int, input().split())) for _ in range(H)]

dp = [[0 for _ in range(W)] for _ in range(H)]

SIZE = 20000

D = abs(A[0][0] - B[0][0])
dp[0][0] = 1 << SIZE - D | 1 << SIZE + D
#print("dp:", dp)

for i in range(H):
  for j in range(W):
    D = abs(A[i][j] - B[i][j])
    dp[i][j] |= dp[i - 1][j] << D | dp[i - 1][j] >> D
    dp[i][j] |= dp[i][j - 1] << D | dp[i][j - 1] >> D

#for i in range(H):
#  a = list(map(lambda x: bin(x)[2::], dp[i]))
#  print(a)

for i in range(SIZE):
  if (dp[-1][-1] >> (SIZE + i)) & 1:
    print(i)
    exit()
L,R = map(int,input().split())
tmp = list(range(L,R+1))
mod = []
rem = []
for i in tmp:
    if i%2019 not in mod:
        mod.append(i%2019)
        rem.append(i)
    if len(mod) == 2019:
        break
ans = 2019
for i in rem:
    for j in rem:
        if i*j%2019 < ans and i < j:
            ans = i*j%2019
        if ans == 0:
            break
print(ans)

### FIXED CODE ###

L,R = map(int,input().split())
if R - L > 2019:
        print(0)
else:
    ans = 10**9
    for i in range(L,R):
        for j in range(i+1,R+1):
            if ans > i*j%2019:
                ans = i*j%2019
                if ans == 0:
                    break
    print(ans)
x, n = map(int, input().split())
p = list(map(int, input().split()))
ans = []
sortlist = []
p.sort()
p1 = p[0]
pn = p[n-1]
new = [i for i in range(p1-1, pn+1)]
nolist = set(new) ^ set(p)
nolist = list(nolist)
print(nolist)
for i in range(0, len(nolist)):
    d = abs(nolist[i] - x)
    sortlist.append(d)

k = sortlist.index(min(sortlist))
print(nolist[k])

### FIXED CODE ###

x, n = map(int, input().split())
p = list(map(int, input().split()))
ans = []
sortlist = []
if n == 0:
    print(x)
else:
    p.sort()
    p1 = p[0]
    pn = p[n-1]
    new = [i for i in range(0, 102)]
    nolist = set(new) ^ set(p)
    nolist = list(nolist)

    for i in range(0, len(nolist)):
        d = abs(nolist[i] - x)
        sortlist.append(d)

        k = sortlist.index(min(sortlist))
    print(nolist[k])
import sys
input = sys.stdin.readline
def main():
    N, K = map(int, input().split())
    x = list(map(int, input().split()))
    neg_dists = []
    pos_dists = []
    for xi in x:
        if xi < 0:
            neg_dists.append(abs(xi))
        else:
            pos_dists.append(abs(xi))
    neg_dists.sort()
    pos_dists.sort()
    ans = 10 ** 9
    d = 0
    for i in range(K):
        if i >= len(neg_dists):continue
        d += neg_dists[i]
        if K-2-i >= len(pos_dists):continue
        d += pos_dists[K-2-i] + neg_dists[i]
        ans = min(ans, d)
    if K <= len(neg_dists):ans = min(ans, neg_dists[K-1])
    if K <= len(pos_dists):ans = min(ans, pos_dists[K-1])
    print(ans)
            
if __name__ == "__main__":
    main()

### FIXED CODE ###

import sys
input = sys.stdin.readline
def main():
    N, K = map(int, input().split())
    x = list(map(int, input().split()))
    neg_dists = []
    pos_dists = []
    exists_zero = False
    for xi in x:
        if xi < 0:
            neg_dists.append(abs(xi))
        elif xi > 0:
            pos_dists.append(abs(xi))
        else:
            exists_zero = True
    neg_dists.sort()
    pos_dists.sort()
    ans = 10 ** 9
    count = K - int(exists_zero)
    for i in range(count):
        d = 0
        if i >= len(neg_dists):continue
        d += neg_dists[i]
        if len(pos_dists) == 0 or count-2-i >= len(pos_dists):continue
        d += pos_dists[count-2-i] + neg_dists[i]
        ans = min(ans, d)
    for i in range(count):
        d = 0
        if i >= len(pos_dists):continue
        d += pos_dists[i]
        if len(neg_dists) == 0 or count-2-i >= len(neg_dists):continue
        d += neg_dists[count-2-i] + pos_dists[i]
        ans = min(ans, d)
    if len(neg_dists) > 0 and count <= len(neg_dists):ans = min(ans, neg_dists[count-1])
    if len(pos_dists) > 0 and count <= len(pos_dists):ans = min(ans, pos_dists[count-1])
    if exists_zero and len(neg_dists) == 0 and len(pos_dists) == 0:ans = 0
    print(ans)
            
if __name__ == "__main__":
    main()
N, K = map(int, input().split())
list_A = list(map(int, input().split()))

l = [1]
s = {1}

while True:
    next = list_A[l[-1] - 1]

    if not next in s:
        l.append(next)
        s.add(next)

    else:
        start = l.index(next)
        roop = len(l) - start
        break

if len(l) == 1:
    print(1)
    exit()

elif len(l) >= K:
    print(l[K])
    exit()

else:
    roop_remainder = (K + 1 - start) % roop
    if roop_remainder == 0:
        print(l[-1])
    else:
        print(l[start + roop_remainder -1])


### FIXED CODE ###

N, K = map(int, input().split())
list_A = list(map(int, input().split()))

l = [1]
s = {1}

while True:
    next = list_A[l[-1] - 1]

    if not next in s:
        l.append(next)
        s.add(next)

    else:
        start = l.index(next)
        roop = len(l) - start
        break

if len(l) == 1:
    print(1)
    exit()

elif len(l) > K:
    print(l[K])
    exit()

else:
    roop_remainder = (K + 1 - start) % roop
    if roop_remainder == 0:
        print(l[-1])
    else:
        print(l[start + roop_remainder -1])
import string

c = raw_input()



ls = string.ascii_lowercase

for i in range(len(ls)):
    if ls[i] == c:
        print(ls[i + 1])
        break



### FIXED CODE ###



c = input()



ls = [chr(ord('a') + i) for i in range(26)]

for i in range(len(ls)):
    if ls[i] == c:
        print(ls[i + 1])
        break
N = int(input())

if N == 3:
    print("2 3 25")
    exit()

MAX = 30000
v2, v3, v6 = [], [], []

for x in range(2, MAX+1):
    if x%6 == 0:
        v6.append(x)
    elif x%3 == 0:
        v3.append(x)
    elif x%2 == 0:
        v2.append(x)

ans = []
j = 0

while j < len(v2) and N > 3:
    ans.append(v2[j*2])
    ans.append(v2[j*2+1])
    j += 1
    N -= 2

j = 0
while j < len(v3) and N > 1:
    ans.append(v3[j*2])
    ans.append(v3[j*2+1])
    j += 1
    N -= 2

if N == 1:
    ans.append(6)

print(" ".join(map(str, ans)))

### FIXED CODE ###

N = int(input())

if N == 3:
    print("2 5 63")
    exit()

MAX = 30000
v2, v3, v6 = [], [], []

for x in range(2, MAX+1):
    if x%6 == 0:
        v6.append(x)
    elif x%3 == 0:
        v3.append(x)
    elif x%2 == 0:
        v2.append(x)

ans = []
j = 0

while j < len(v2)//2 and N > 3:
    ans.append(v2[j*2])
    ans.append(v2[j*2+1])
    j += 1
    N -= 2

j = 0
while j < len(v3)//2 and N > 1:
    ans.append(v3[j*2])
    ans.append(v3[j*2+1])
    j += 1
    N -= 2

for j in range(N):
    ans.append(v6[j])


print(" ".join(map(str, ans)))
N,K = list(map(int,input().split(" ")))
hs = list(map(int,input().split(" ")))
dp = [] 

dp[0] = 0
for i in range(1,N):

    stepLim = min(K,i)
    temp = 9999999999999999999
    for j in range(1,stepLim + 1):
        c = dp[i-j]+abs(hs[i]-hs[i-j])
        if temp >c:
                temp = c
    dp.append(temp)
print(dp[-1])

### FIXED CODE ###

N,K = list(map(int,input().split(" ")))
hs = list(map(int,input().split(" ")))
dp = [9999999999999] * N

dp[0] = 0
for i in range(1,N):
#ind → i-1 ~ i-stepLim -1   [i-stepLim -1:i]
    stepLim = min(K,i)
    temp = 9999999999999999999
    dp[i] = min([d+abs(hs[i]-h) for d,h in zip(dp[i-stepLim:i],hs[i-stepLim:i])])
print(dp[-1])
A, B= [int(input() )for _ in range(2)]
S = str(input())

try:
    if (type((int(S[:A])+int(S[A+1:])))== int):
        if S[A]=="-": 
                print('Yes')
    else:
        print('No')
except:
    print("No")

### FIXED CODE ###

g = list(map(int,input().split()))
S = str(input())
 
if ((S[:g[0]]+S[g[0]+1:]).isdigit()) &  (S[g[0]]=="-"):
    print("Yes")
else:
    print("No")