Harryxun/stf_run huggingface dataset:
N, M = list(map(int, input().split()))

ab = []
for i in range(N):
    ab.append(list(map(int, input().split())))

cd = []
for i in range(M):
    cd.append(list(map(int, input().split())))

for ab_list in ab:
    min_distance = 200000000
    checkpoint = 0
    for cd_list in cd:
        checkpoint += 1
        distance = abs(ab_list[0] - cd_list[0]) + abs(ab_list[1] - cd_list[1])
        if distance < min_distance:
            min_distance = distance
            ans = checkpoint
    print(ans)


### FIXED CODE ###

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

ab = []
for i in range(N):
    ab.append(list(map(int, input().split())))

cd = []
for i in range(M):
    cd.append(list(map(int, input().split())))

for ab_list in ab:
    min_distance = 400000000
    checkpoint = 0
    for cd_list in cd:
        checkpoint += 1
        distance = abs(ab_list[0] - cd_list[0]) + abs(ab_list[1] - cd_list[1])
        if distance < min_distance:
            min_distance = distance
            ans = checkpoint
    print(ans)
r, D, X = list(map(int, input().split()))
for i in range(10):
    x = r * x - D
    print(x)


### FIXED CODE ###

r, D, x = list(map(int, input().split()))
for i in range(10):
    x = r * x - D
    print(x)
a = []
while 1:
 s = input()
 if s == 'END_OF_TEXT':
  break
 else:
  s = list(s.split('.')
  s = list(s.split())
  a.append(s)

print(a.count(a[0]) - 1)

### FIXED CODE ###

word = input()
counter = 0
while 1:
 s = input()
 if s == 'END_OF_TEXT':
  break
 else:
  s = list(s.lower().split())
  counter += s.count(word)
  counter += s.count(word + '.')

print(counter)
print a*b, 
print a+a+b+b

### FIXED CODE ###

a, b = map(int, raw_input().split())
print a*b, 2*a + 2*b
N = int(input())
inputted = list(map(int, input().split()))
S = inputted[0]
T = inputted[1]

answer = ''
for s, t in zip(S, T):
    answer += s + t

answer = ''.join([s + t for s, t in zip(S, T)])

print(answer)

### FIXED CODE ###

N = int(input())
inputted = input().split()
S = inputted[0]
T = inputted[1]

answer = ''
for s, t in zip(S, T):
    answer += s + t

answer = ''.join([s + t for s, t in zip(S, T)])

print(answer)
A, B, C = map(int, input().split())
K = int(input())
flag = False

l=[]
for i in range(K):
  for j in range(K):
    for k in range(K):
      if i+j+k == K:
        m=[i, j, k]
        l.append(m)

for i in range(len(l)):
  m = l[i]
  a=A*(2**m[0])
  b=B*(2**m[1])
  c=C*(2**m[k])

  if a<b and b<c:
    flag = False
    print("Yes")
    break
  else:
    flag = True
if flag:
  print("No")

### FIXED CODE ###

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

l=[]
for i in range(K+1):
  for j in range(K+1):
    for k in range(K+1):
      if i+j+k == K:
        m=[i, j, k]
        l.append(m)

for i in range(len(l)):
  m = l[i]
  a=A*(2**m[0])
  b=B*(2**m[1])
  c=C*(2**m[2])

  if a<b and b<c:
    flag = False
    print("Yes")
    break
  else:
    flag = True
if flag:
  print("No")
from itertools import permutations

N, M = map(int, input().split())
G = [[] for _ in range(N)]
for _ in range(N):
    a, b = map(int, input().split())
    a, b = a - 1, b - 1
    G[a].append(b)
    G[b].append(a)

res = 0
for P in permutations(range(N), N):
    if P[0] != 0:
        continue
    for i in range(N - 1):
        if P[i + 1] not in G[P[i]]:
            break
    else:
        res += 1

print(res)


### FIXED CODE ###

import itertools as it

N, M = map(int, input().split())
ab = tuple(set(map(int, input().split())) for _ in range(M))

P = it.permutations(range(1, N + 1), N)

res = 0
for p in P:
    if p[0] == 1:
        for i in range(N - 1):
            if not(set({p[i], p[i + 1]}) in ab):
                break
        else:
            res += 1

print(res)
from collections import*
z,v,a,c=input,range,print,split
h,w,k=map(int,z().c());r,s,t,u=map(lambda x:int(x)-1,z().c())
b=[z()for _ in v(h)];l=[[-1]*w for _ in v(h)];l[r][s]=0
d=deque([(r,s)])
while d:
  x,y=d.popleft();j=l[x][y]
  if(x==t)&(y==u):exit(a(j))
  for e,f in[[1,0],[-1,0],[0,-1],[0,1]]:
    for i in v(1,k+1):
      p,q=x+e*i,y+f*i
      if not((0<=p<h)&(0<=q<w))or b[p][q]=="@" or 0<=l[p][q]<=j:break
      if l[p][q]<0:d+=[(p,q)];l[p][q]=j+1
a(-1)

### FIXED CODE ###

import sys
inf=1000002
sys.setrecursionlimit(inf)
from collections import deque
h,w,k=map(int,input().split())
x1,y1,x2,y2=map(int,input().split())
c=[input() for i in range(h)]
dp=[[inf if c[i][j]=="." else -1 for j in range(w)] for i in range(h)]
now=deque()
now.append([x1-1,y1-1])
dp[x1-1][y1-1]=0
#kの更新が遅い
def bfs(d):
    global h,w,k,dp,now,x2,y2
    l=len(now)
    if l==0:
        return
    dp_sub=deque()
    cand=set()
    for i in range(l):
        x,y=now.popleft()
        for j in range(1,min(k+1,w-y)):
            if dp[x][y+j]==inf:
                dp_sub.append([x,y+j,d])
                #dp[x][y+j]=d
                cand.add((x,y+j))
                #now.append([x,y+j])
            else:
                break
        for j in range(1,min(k+1,y+1)):
            if dp[x][y-j]==inf:
                dp_sub.append([x,y-j,d])
                #dp[x][y-j]=d
                cand.add((x,y-j))
                #now.append([x,y-j])
            else:
                break
        for j in range(1,min(k+1,h-x)):
            if dp[x+j][y]==inf:
                dp_sub.append([x+j,y,d])
                #dp[x+j][y]=d
                cand.add((x+j,y))
                #now.append([x+j,y])
            else:
                break
        for j in range(1,min(k+1,x+1)):
            if dp[x-j][y]==inf:
                dp_sub.append([x-j,y,d])
                #dp[x-j][y]=d
                cand.add((x-j,y))
                #now.append([x-j,y])
            else:
                break
    while dp_sub!=deque([]):
        e=dp_sub.popleft()
        dp[e[0]][e[1]]=e[2]
    for i in cand:
        now.append(i)
    bfs(d+1)
bfs(1)
print(dp[x2-1][y2-1] if dp[x2-1][y2-1]!=inf else -1)
T = list(input())
if len(T) == 1:
  if T[0] == "?":
    print("D")
  else:
    print("".join(T))
else:
  for i in range(len(T)):
    if i > 0 and T[i] == "?" and T[i-1] == "P":
      T[i] = "D"
    elif i <= len(T) -1 and T[i] == "?" and (T[i+1] == "D" or T[i+1] == "?"):
      T[i] = "P"
    elif T[i] == "?":
      T[i] = "D"
  print("".join(T))

### FIXED CODE ###

T = list(input())
if len(T) == 1:
  if T[0] == "?":
    print("D")
  else:
    print("".join(T))
else:
  for i in range(len(T)):
    if i > 0 and T[i] == "?" and T[i-1] == "P":
      T[i] = "D"
    elif i < len(T) -1 and T[i] == "?" and (T[i+1] == "D" or T[i+1] == "?"):
      T[i] = "P"
    elif T[i] == "?":
      T[i] = "D"
  print("".join(T))
from collections import deque

h,w = map(int,input().split())
maze = []

cnt_wall = 0
for _ in range(h):
    s = input()
    cnt_wall += s.count('#')
    maze.append(s)

def  bfs(d):
    inf = 10**5
    visited = [[inf]*w for _ in range(h)]
    sx,sy = 0,0
    gx,gy = w-1, h-1
    que = deque([(sx,sy)])
    visited[sx][sy] = 1
    
    while que:
        x,y = que.popleft()
        if x==gx and y==gy:
            return visited[gx][gy]
        for i,j in ((1,0),(0,1),(-1,0),(0,-1)):
            nx,ny = x+i, y+j
            if 0<=nx<=gx and 0<=ny<=gy:
                if d[nx][ny]=='.' and visited[nx][ny] == inf:
                    visited[nx][ny] = visited[x][y]+1
                    que.append((nx,ny))



min_step = bfs(maze)
if min_step == 10**5:
    print(-1)
else:
    print(h*w - min_step - cnt_wall)

### FIXED CODE ###

from collections import deque

def bfs(maze,visited,sy,sx,gy,gx):
    Step = ([1,0],[0,1],[-1,0],[0,-1])
    
    que = deque([[sx,sy]])
    visited[sx][sy] = 1
    
    while que:
        y,x = que.popleft()
        if [y,x] == [gy,gx]:
            return visited[y][x]
        for j,k in Step:
            ny,nx = y+j , x+k
            if 0 <= ny <= gy and 0 <= nx <= gx:
                if maze[ny][nx] == '.' and visited[ny][nx] == INF:
                    visited[ny][nx] = visited[y][x] + 1
                    que.append([ny,nx])


h,w = map(int,input().split())
maze = [input().strip() for _ in range(h)]

cntSharp = 0
for i in range(h):
    cntSharp += maze[i].count('.')

INF = 10**5
visited = [[INF]*w for _ in range(h)]

sx,sy = 0,0
gy,gx = h-1,w-1

minStep = bfs(maze,visited,sy,sx,gy,gx)
print(cntSharp - minStep if visited[gy][gx] != INF else -1)
# -*- coding utf-8 -*-
n = str(input())
S = n.replace(1,8)
T = S.replace(9,1)
U = T.replace(8,9)
print(U)

### FIXED CODE ###

# -*- coding utf-8 -*-
n = str(input())
S = n.replace("1","8")
T = S.replace("9","1")
U = T.replace("8","9")
print(U)
def C(x, y):
    z = 1
    for i in range(x, x-y, -1):
        z *= i
    for i in range(y, 1, -1):
        z //= i
    return z
def H(x, y):
    return C(x+y-1, y) % 1000000007
n, m = list(map(int, input().split()))
p = 2
prime_factorization = []
while p * p <= m:
    count = 0
    while m % p == 0:
        m //= p
        count += 1
    if count > 0:
        prime_factorization.append(count)
    p += 1
if m > 1:
    prime_factorization.append(1)
ans = 1
for r in prime_factorization:
    ans *= H(n, r)
print(ans % 1000000007)

### FIXED CODE ###

l = list(map(int, input().split()))
print(9*max(l)+sum(l))
h, w = map(int, input())
a, b = map(int, input())

print(h*w - (h*b + w*a - a*b))


### FIXED CODE ###

h, w = map(int, input().split())
a, b = map(int, input().split())

print(h*w - (h*b + w*a - a*b))
S = input()

if (S[0]==S[1] and S[2]==S[3] and S[1]!=S[2])or (S[1]==S[2] and S[0]==S[3] and S[0]!=S[1])or (S[0]==S[2] and S[1]==S[3] and S[1]!=S[2]):
  print(Yes)
else:
  print(No)

### FIXED CODE ###

S = input()

if (S[0]==S[1] and S[2]==S[3] and S[1]!=S[2])or (S[1]==S[2] and S[0]==S[3] and S[0]!=S[1])or (S[0]==S[2] and S[1]==S[3] and S[1]!=S[2]):
  print("Yes")
else:
  print("No")
s,t = input().split()

t = t[:-1]

if s == t:
    print('Yes')
else:
    print('No1')





### FIXED CODE ###

s = input()
t = input()

t = t[:-1]
if s == t:
    print('Yes')
else:
    print('No')
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)]
 
#差分だけで良い，これを*1 or -1していく
diff = [[0]*W for _ in range(H)]
for i in range(H):
    for j in range(W):
        diff[i][j] = abs(A[i][j] - B[i][j])
        
 # i,jマスにおいて，偏りがkになれるかどうかでDP
K = 6401 #適当
kk = int((K-1)/2)
dp = [[[False]*K for _ in range(W)] for _ in range(H)]
 
dp[0][0][kk+diff[0][0]] = True
dp[0][0][kk-diff[0][0]] = True
 

for i in range(H):
    for j in range(W):
        a= min((i+j)*80,K)
        for k in range(kk-a,kk+a):
            if i-1>=0:
                if k+diff[i][j]<K:
                    if dp[i-1][j][k+diff[i][j]]:
                        dp[i][j][k] =True
                if k-diff[i][j]>=0:
                    if dp[i-1][j][k-diff[i][j]]:
                        dp[i][j][k] =True
            if j-1>=0:
                if k+diff[i][j]<K:
                    if dp[i][j-1][k+diff[i][j]]:
                        dp[i][j][k] =True
                if k-diff[i][j]>=0:
                    if dp[i][j-1][k-diff[i][j]]:
                        dp[i][j][k] =True
ans = K


for k in range(K):
    if dp[H-1][W-1][k]:
        ans = min(ans,abs(k-kk))
print(ans)

### FIXED CODE ###

import sys
input = sys.stdin.readline

H,W = map(int,input().split())
#差分だけで良い，これを*1 or -1していく
diff = [list(map(int, input().split())) for _ in range(H)]

for i in range(H):
    B = list(map(int,input().split()))
    for j in range(W):
        diff[i][j] = abs(diff[i][j] - B[j])
        
 # i,jマスにおいて，偏りがkになれるかどうかでDP
#dp[i][j]にはkという数字にたどり着けるかどうかを示す2進数を入れる

dp = [[False]*W for _ in range(H)]
ofs = 80*(H+W)


dp[0][0]=(1<<(ofs+diff[0][0]) | 1>>(ofs-diff[0][0]))
 
for i in range(H):
    for j in range(W):
        if i>0:
            dp[i][j]|=(dp[i-1][j]<<diff[i][j] | dp[i-1][j]>>diff[i][j])
        if j>0:
            dp[i][j]|=(dp[i][j-1]<<diff[i][j] | dp[i][j-1]>>diff[i][j])


#0のところから見て，最初に1が出てきたところが答え
for k in range(ofs):
    if (dp[-1][-1]>>(k+ofs)&1):
        print(k)
        break
n = int(input())
a = [int(i) for in input().split()]
t = 0
for i in range(n):
 for j in range(i+1,n):
  t += a[i] > a[j]
print("YES" if t < 2 else "NO")

### FIXED CODE ###

n = int(input())
a = [int(i) for i in input().split()]
q = 0
for i in range(n):
 for j in range(i, n):
  t = a[i]
  a[i] = a[j]
  a[j] = t
  f = 1  
  lst = - 1100
  for k in a:
   f &= k > lst
   lst = k
  q |= f
  t = a[i]
  a[i] = a[j]
  a[j] = t
print("YES" if q else "NO")
import sys
s = str(input())
Q = int(input())
q = sys.stdin.readlines()
for i in q:
  if i[0] == 1:
    s = alpha[::-1]
  elif i[1] == 1:
    s.appendleft(i[2])
  else:
    s.append(i[2])
print(s)

### FIXED CODE ###

from collections import deque
import sys
s = deque(list(input()))
Q = int(input())
cnt = 0

for i in range(Q):
  q = list(input().split())
  if q[0] == '1':
    cnt = (cnt+1) % 2
  elif q[1] == '1':
    if cnt == 0:
      s.appendleft(q[2])
    else:
      s.append(q[2])
  else:
    if cnt == 0:
      s.append(q[2])
    else:
      s.appendleft(q[2])

if cnt == 1:
  s.reverse()
print("".join(s))
n,t= map(int, input().split())
m = min([c for c,ti in [map(int,input().split()) for i in range(n)] if ti <=t])
print(m if m else 'TLE')

### FIXED CODE ###

n,t= map(int, input().split())
rs = [list(map(int, input().split())) for i in range(n)]
rs.sort()
for i in rs:
    ci, ti = i
    if ti<= t:
        print(ci)
        exit()
print('TLE')
n, k, m = map(int, input().split())
li = list(map(int, input().split()))
genzai = sum(li)
mokuhyou = n*m
theta = mokuhyou-genzai
if theta > k:
    print(-1)
elif k >= theta:
    print(theta)
elif theta < 0:
    print(0)

### FIXED CODE ###

x = str(input())
alph = 'abcdefghijklmnopqrstuvwxyz'
a = alph.find(x) + 1
b = alph[a]
print(b)
n = input()

l = list(map(int, input().split()))

l.sort(reverse=True)

total = l.sum()

if (total - 2 * l[0] > 0 ) :
  print("yes")
else:
  print("no")
  

### FIXED CODE ###

n = input()
 
l = list(map(int, input().split()))
 
l.sort(reverse=True)
 
total = sum(l)
 
if (total - 2 * l[0] > 0 ) :
  print("Yes")
else:
  print("No")
def lcm(a):
    from fractions import gcd
    x = a[0]
    for i in range(1, len(a)):
        x = (x * a[i]) // gcd(x, a[i])
    return x
  

N = int(input())
lst = list(map(int, input().split()))
lcm = lcm(lst)

a = 0
for i in range(N):
  a += int(lcm/lst[i])
print(a)


### FIXED CODE ###

def lcm(a):
    from fractions import gcd
    x = a[0]
    for i in range(1, len(a)):
        x = (x * a[i]) // gcd(x, a[i])
    return x
  
N = int(input())
lst = list(map(int, input().split()))
const = 10**9 + 7

def solve(arr):
    ab = lcm(arr)
    sum = 0
    for a in arr:
        sum += ab // a
    return sum % const

answer = solve(lst)

print(int(answer))
def main():
  H,N = map(int,input().split())
  AB = [list(map(int,input().split())) for _ in range(N)]
  ab = min(AB,key = lambda x:x[1])
  INF = float('inf')
  dp = [INF]*(H+1)
  mi_a = ab[0]
  mi_b = ab[1]
  dp[0] = 0
  for i in range(1,H+1):
    if i<=mi_a:
      dp[i]=mi_b
    else:
      mi = float('inf')
      for a,b in AB:
        mi = min(mi,dp[max(0,i-a)]+b)
      if dp[i]>mi:
        dp[i] = mi

  print(dp[H])
  
main()

### FIXED CODE ###

H,A = map(int,input().split())
if H%A==0:
  print(H//A)
else:
  print((H//A)+1)
N = int(input())
 
t = [int(input().split()) for i in range(N)]
 
M = int(input())
 
cal = sum(t)
 
for j in range(M):
    p, x = list(map(int, input().split()))
    print(cal - t[[p] - 1] + x)

### FIXED CODE ###

N = int(input())
 
t = list(map(int, input().split()))
 
M = int(input())
 
cal = sum(t)
 
for j in range(M):
    p, x = map(int, input().split())
    print(cal - t[p - 1] + x)
N, W = map(int, input().split())
w = []
v = []
for _ in range(N):
  wi, vi = map(int, input().split())
  w.append(wi)
  v.append(vi)
dp = [[0]*(W+1) for _ in range(N+1)]

for i in range(N):
  for sum_w in range(W+1):
    if sum_w-w[i] >= 0:
      dp[i+1][sum_w] = max(dp[i][sum_w], dp[i][sum_w-w[i]]+v[i])
    else:
      dp[i+1][sum_w] = dp[i][sum_w]

print(dp[N][W])

### FIXED CODE ###

N, W = map(int, input().split())
w = []
v = []
for _ in range(N):
  wi, vi = map(int, input().split())
  w.append(wi)
  v.append(vi)
dp = [[float('inf')]*(max(v)*N+1) for _ in range(N+1)]
dp[0][0] = 0

for i in range(N):
  for sum_v in range(max(v)*N+1):
    if v[i] - sum_v > 0:
      dp[i+1][sum_v] = dp[i][sum_v]
    else:
      dp[i+1][sum_v] = min(dp[i][sum_v], dp[i][sum_v - v[i]] + w[i])

ans = 0
for sum_v in range(max(v)*N+1):
  if dp[N][sum_v] <= W:
    ans = sum_v
print(ans)
def LCS():
    seq1 = raw_input()
    seq2 = raw_input()
 
    a, b = len(seq1), len(seq2)
    for i in range(b + 1):
      c1[i] = 0 
    for i in range(a):
        e1 = seq1[i]
        c2 = c1+[]
        for j in range(b):
            if e1 == seq2[j]:
                c1[j + 1] = c2[j] + 1
            elif c1[j + 1] < c1[j]:
                c1[j + 1] = c1[j]
    return c1[-1]
 
n = input()
for i2 in range(n):
    print LCS()

### FIXED CODE ###

def LCS():
    X = raw_input()
    Y = raw_input()
 
    a, b = len(X), len(Y)
    c1 = [0 for i in range(b+1)]
    for i in range(a):
        e1 = X[i]
        c2 = c1+[]
        for j in range(b):
            if e1 == Y[j]:
                c1[j+1] = c2[j] + 1
            elif c1[j+1] < c1[j]:
                c1[j+1] = c1[j]
    return c1[-1]
 
n = input()
for i in range(n):
    print LCS()
# coding: utf-8
# Your code here!
def dfs(loc,num):
    root[loc]=num
    for item in plan[loc]:
        if root[item]==-1:
            dfs(item,num)
    return 0

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

P=list(map(int,input().split()))

plan=[[]for i in range(N)]
root=[-1]*N

for _ in range(M):
    a,b=map(int,input().split())
    plan[a-1].append(b-1)
    plan[b-1].append(a-1)

for i in range(N):
    if root[i]==-1:
        dfs(i,i)

ans=0
for i in range(N):
    if root[i]==root[P[i]-1]:
        ans+=1
#print(root)
print(ans)

### FIXED CODE ###

# coding: utf-8
# Your code here!
import sys
sys.setrecursionlimit(10**9)

def dfs(loc,num):
    root[loc]=num
    for item in plan[loc]:
        if root[item]==-1:
            dfs(item,num)
    return 0

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

P=list(map(int,input().split()))

plan=[[]for i in range(N)]
root=[-1]*N

for _ in range(M):
    a,b=map(int,input().split())
    plan[a-1].append(b-1)
    plan[b-1].append(a-1)

for i in range(N):
    if root[i]==-1:
        dfs(i,i)

ans=0
for i in range(N):
    if root[i]==root[P[i]-1]:
        ans+=1
#print(root)
print(ans)
import numpy as np
n = int(input())
arr = np.full((n,n),9)
for i in range(n):
  nn = int(input())
  for j in range(nn):
    a,b = map(int,input().split())
    arr[i][a-1] = b

arr2 = arr.T
cnt = 0
for i in range(n):
  for j in range(n):
    if arr[i][j]==0 and arr2[i][j]==0:
      cnt += 1
    elif arr[i][j]==1 and arr2[i][j]==1:
      cnt+=1

print(cnt)

### FIXED CODE ###

a,b,c = map(int, input().split())
print("win" if a+b+c <= 21 else "bust")
import sys
input = sys.stdin.readline
sys.setrecursionlimit(10**6)
n,m=map(int,input().split())

a=[int(input()) for i in range(m)]

def fib(n):
    if n==1:
        return 1
    if n==2:
        return 2
    return fib(n-1)+fib(n-2)

ans=0
check=0
for i in a:
    if i-check==1:
        print(0)
        exit()
    ans+= fib(i-check-1)
    check=i
ans+=fib(n-check-1)
print(ans%(10**9+7))

### FIXED CODE ###

n,m=map(int,input().split())
mod=10**9+7

    
dp=[0]*(n+1)
dp[0]=1

a=set(int(input()) for i in range(m))

for i in range(1,n+1):
    if i in a:
        continue
    x=dp[i-1]
    if i>1:
        x+=dp[i-2]
    dp[i]=x%mod
print(dp[-1])
from bisect import bisect_right
from bisect import bisect_left

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

#n=6
#k=727202214173249351
#a=[6, 5, 2, 5, 3, 2]

ai=1
aj=[]
for i in range(min(n,k)):
    aim=ai
    ai=a[ai-1]
#    print(ai,aj)
    if ai in aj:
#        print(ai,aj)
        ic2=aim
        break
    else:
        aj.append(ai)
        

ic1=bisect_left(a,a[ic2])
icyc=ic2-ic1
    
k2=(k-ic1)%icyc+ic1
ai=1
for i in range(k2):
    ai=a[ai-1]
        
print(ai)


### FIXED CODE ###

import sys

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

for i in range(n):
    a[i]-=1
#print(a)

if k<=n:
    b=0
    for i in range(k):
        b=a[b]
    print(b+1)
    sys.exit()
    
b=0
c=[-1]*n
c[0]=0
for i in range(n):
#   print(b,a[b])
   b=a[b]
   if c[b]>=0:
#       print("i:",i)
       break
   else:
       c[b]=i+1

ki=c[b]+1
kc=(i+1)-c[b]
k2=(k-ki)%kc+ki
#print("ki:",ki,"kc:",kc,"k2:",k2)
b=0
for i in range(k2):
    b=a[b]
print(b+1)
n, d = map(int, input().split())
xy = []
for i in range(n):
  a, b = map(int, input().split())
  x.append([a, b])
 
count = 0
for xi, yi in xy:
  count += xi**2 + yi**2 <= d**2
 
print(count)

### FIXED CODE ###

n, d = map(int, input().split())
x, y = [], []
for i in range(n):
  a, b = map(int, input().split())
  x.append(a)
  y.append(b)

count = 0
for xi, yi in zip(x, y):
  if xi**2 + yi**2 <= d**2:
    count += 1

print(count)
h,n=map(int,input().split())
dp=[10**10]*(h+1)
dp[0][0]=1
X=[]
for i in range(n):
    a,b=map(int,input().split())
    X.append([a,b])


for i in range(h):
    for j in range(n):
        k=min(i+X[j][0],h)
        dp[k]=min(dp[k],dp[i]+X[j][1])
print(dp[h])

### FIXED CODE ###

h,n=map(int,input().split())
H=[]
A=[]
for i in range(n):
    a,b=map(int,input().split())
    H.append([a,b])
    A.append(a)
a_max=max(A)
dp=[10**10]*(h+a_max+1)
dp[0]=0
for i in range(1,h+a_max+1):
    for j in range(n):
        if i-H[j][0]<0:
            dp[i]=min(dp[i],H[j][1])
        else:
            dp[i]=min(dp[i],dp[i-H[j][0]]+H[j][1])
print(min(dp[h:h+a_max+1]))
s=input()
count=0
for i in s:
    if i='+':
        count+=1
    else:
        count-=1
print(count)

### FIXED CODE ###

s=input()
count=0
for i in s:
    if i=='+':
        count+=1
    else:
        count-=1
print(count)
a,b,m=map(int,input().split())
A=list(map(int,input().split()))
B=list(map(int,input().split()))
ans=min(A)+min(B)
for i in range(m):
  x,y,c=map(int,input().split())
  k=A[x]+B[y]-c
  if k<ans:
    ans=k
print(ans)

### FIXED CODE ###

a,b,m=map(int,input().split())
A=list(map(int,input().split()))
B=list(map(int,input().split()))
ans=min(A)+min(B)
for i in range(m):
  x,y,c=map(int,input().split())
  k=A[x-1]+B[y-1]-c
  if k<ans:
    ans=k
print(ans)
n = input()
l = len(n)-1

for i in range(2**l):
    op = ["-"]*l
    for j in range(l):
        if (i>>j) &1:
            op[i-j-1]="+"
    formula = ""
    for op_num,op_l in zip(n,op):
        formula = op_num+op_l
        if eval(formula)==7:
            print(formula+"=7")
            break

### FIXED CODE ###

def dfs(i, Str, res):
    if i==3:
        if res==7:
            print(Str+"=7")
            exit()
        return
    
    dfs(i+1,Str+"+"+s[i+1],res+int(s[i+1]))
    dfs(i+1,Str+"-"+s[i+1],res-int(s[i+1]))

s=input()
dfs(0,s[0],int(s[0]))
abhm=tuple(map(float, input().split()))
a=abhm[0]
b=abhm[1]
h=abhm[2]
m=abhm[3]

import math as mt

pi=mt.pi
print(pi)

c=pi*(h+m/60)/6
d=pi*m/30

print(mt.sqrt((a*mt.cos(c)-b*mt.cos(d))**2+(a*mt.sin(c)-b*mt.sin(d))**2))


### FIXED CODE ###

n=int(input())
m=n%10
if m in [2, 4,5,7,9]:
    print('hon')
elif m in [0,1,6,8]:
    print('pon')
else:
    print('bon')
N = int(input())
ans = [0] (N + 1)
for i in range (1, 101):
  for j in range(1, 101):
    for k in range(1, 101):
      n = i*i+j*j+k*k+i*j+j*k+k*i
      if n <= N:
        ans[n] += 1

print(*ans[1:], sep='\n')



### FIXED CODE ###

N = int(input())
ans = [0] * (N + 1)
for i in range (1, 101):
  for j in range(1, 101):
    for k in range(1, 101):
      n = i*i+j*j+k*k+i*j+j*k+k*i
      if n <= N:
        ans[n] += 1

print(*ans[1:], sep='\n')