Harryxun/stf_run huggingface dataset:
n = int(input())
XYH = list(map(int, input().split()) for _ in range(n))
  
XYH.sort(lambda x:x[2],reverse=True)
sx = XYH[0][0]
sy = XYH[0][1]
sh = XYH[0][2]
  
for i in range(0,101):
  for j in range(0,101):
    anss = sh + abs(sx-i) + abs(sy-j)
    for k in range(n):
      if H[k] == 0:
        continue
      if anss == XYH[k][2] + abs(XYH[k][0]-i) + abs(XYH[k][1]-j):
        continue
      else:
        break
    else:
      an = [sx, sy, sh]
      print(*an)
      exit()



### FIXED CODE ###

n = int(input())
XYH = [list(map(int, input().split())) for _ in range(n)]
  
XYH.sort(key=lambda x:x[2],reverse=True)
sx = XYH[0][0]
sy = XYH[0][1]
sh = XYH[0][2]
  
for i in range(0,101):
  for j in range(0,101):
    anss = sh + abs(sx-i) + abs(sy-j)
    for k in range(n):
      if XYH[k][2] == max(anss - abs(XYH[k][0]-i) - abs(XYH[k][1]-j),0):
        pass
      else:
        break
    else:
      an = [i, j, anss]
      print(*an)
      exit()
N = int(input())
A = list(map(int, input().split(" ")))

dp_dict = {}


def dp(i, j):
    if i >= N:
        return -1*10e+9
    if (i+1)//2 > (N//2)-j+1:
        return -1*10e+9
    if j == 1:
        return A[i]
    if (i, j) in dp_dict:
        return dp_dict[(i, j)]
    else:
        temp = max([dp(i+2, j-1)+A[i], dp(i+1, j)])
        dp_dict[(i, j)] = temp
        return temp


print(dp(0, (N//2)))

### FIXED CODE ###

N = int(input())
A = [0]+list(map(int, input().split(" ")))

dp_list = [{0, 0}, {0: 0, 1: A[1]}, {0: 0, 1: A[1] if A[1] > A[2] else A[2]}]

for i in range(3, N+1):
    b = (i-1)//2
    f = (i+1)//2
    dp_list.append({})
    for j in range(b, f+1):
        if j in dp_list[i-1]:
            dp_list[i][j] = dp_list[i-2][j-1]+A[i] if dp_list[i -
                                                              2][j-1]+A[i] > dp_list[i-1][j] else dp_list[i-1][j]
        else:
            dp_list[i][j] = dp_list[i-2][j-1]+A[i]

print(dp_list[-1][N//2])
#D問題
def find(A,x) -> int:
    p = A[x]
    if p == x:
        return x
    a = find(A,p)
    A[x] = a
    return a

def union(A, x, y):
    if find(A,x) > find(A,y):
        bx, by = find(A,y), find(A,x)
    else:
        bx, by = find(A,x), find(A,y)
    A[y] = bx
    A[by] = bx

import heapq

N = int(input())

XY0 = []
XY1 = []
for i in range(N):
    x,y = map(int,input().split())
    XY0.append([x,y,i])
    XY1.append([x,y,i])

XY0.sort()
XY1 = sorted(XY1, key=lambda x: x[1])

E = []
for i,x in enumerate(XY0):
    if i == 0:
        ox = x[0]
        oi = x[2]
    else:
        dx = x[0]-ox
        ox = x[0]
        heapq.heappush(E,[dx,oi,x[2]])
        oi = x[2]

for i,y in enumerate(XY1):
    if i == 0:
        oy = y[1]
        oi = y[2]
    else:
        dy = y[1]-oy
        oy = y[1]
        heapq.heappush(E,[dy,oi,y[2]])
        oi = y[2]


uf = UnionFind(N)
V = [i for i in range(N)]
ans = 0
while E:
    w,s,t = heapq.heappop(E)
    if find(V,s) != find(V,t):
        union(V,s,t)
        ans+=w
        
print(ans)



### FIXED CODE ###

#D問題
def find(A,x):
    p = A[x]
    if p == x:
        return x
    a = find(A,p)
    A[x] = a
    return a

def union(A, x, y):
    if find(A,x) > find(A,y):
        bx, by = find(A,y), find(A,x)
    else:
        bx, by = find(A,x), find(A,y)
    A[y] = bx
    A[by] = bx

import heapq

N = int(input())

XY0 = []
XY1 = []
for i in range(N):
    x,y = map(int,input().split())
    XY0.append([x,y,i])
    XY1.append([x,y,i])

XY0.sort()
XY1 = sorted(XY1, key=lambda x: x[1])

E = []
for i,x in enumerate(XY0):
    if i == 0:
        ox = x[0]
        oi = x[2]
    else:
        dx = x[0]-ox
        ox = x[0]
        heapq.heappush(E,[dx,oi,x[2]])
        oi = x[2]

for i,y in enumerate(XY1):
    if i == 0:
        oy = y[1]
        oi = y[2]
    else:
        dy = y[1]-oy
        oy = y[1]
        heapq.heappush(E,[dy,oi,y[2]])
        oi = y[2]



V = [i for i in range(N)]
ans = 0
while E:
    w,s,t = heapq.heappop(E)
    if find(V,s) != find(V,t):
        union(V,s,t)
        ans+=w
        
print(ans)
n,m,q  = map(int,input().split())
rails=[tuple(map(int,input().split())) for i in range(m)]
qs=[tuple(map(int,input().split())) for i in range(q)]
enuq = list(enumerate(qs))
 
enuq.sort(key = lambda x:x[1][0])
ansli = [0 for i in range(q)]


for (i,(p,q)) in enuq:
    removelist=[]
    for (j,(l,r)) in enumerate(rails):
        if p<=l and r<=q:
            ansli[i]=ansli[i]+1
        elif l<p:
            removelist.append(j)
    for jj in removelist:
        rails.pop(jj)



for a in ansli:
    print(a)


### FIXED CODE ###

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

print((a-1)*(b-1))
s=map(int,raw_input().split())
sa=0
sb=0
sc=0
for i in range(len(s)):
  if s[i]=="a":
    sa+=1
  if s[i]=="b":
    sb+=1
  if s[i]=="c":
    sc+=1
if sa=1 and sb=1 and sc=1:
    print "Yes"
else: 
  print "No"

### FIXED CODE ###

s=raw_input()
sa=0
sb=0
sc=0
for i in range(len(s)):
  if s[i]=="a":
    sa+=1
  if s[i]=="b":
    sb+=1
  if s[i]=="c":
    sc+=1
if sa==1 and sb==1 and sc==1:
    print "Yes"
else: 
    print "No"
h, w=map(int, input().split())
a=[]
visited=[[True for i in range(w)] for j in range(h)]
need_visited=[[0 for i in range(w)] for j in range(h)]
stack=[]
for i in range(h):
    a.append(list(input()))

for i in range(h):
    for j in range(w):
        if a[i][j]=="#":
            stack.append([i, j])
            visited[i][j]=False



dx=[1, -1, 0, 0]
dy=[0, 0, 1, -1]


while len(stack)!=0:
    now_point=stack.pop(0)
    now_y=now_point[0]
    now_x=now_point[1]
    for i in range(4):
        if 0<=now_x+dx[i]<=w-1 and 0<=now_y+dy[i]<=h-1:
            if a[now_x+dx[i]][now_y+dy[i]]==".":
                if visited[now_x+dx[i]][now_y+dy[i]]:
                    need_visited[now_x+dx[i]][now_y+dy[i]]=need_visited[now_x][now_y]+1
                    visited[now_x+dx[i]][now_y+dy[i]]=False

                    stack.append([now_y+dy[i], now_x+dx[i]])
max_list=[]
for i in range(h):
    max_list.append(max(need_visited[i]))
print(max(max_list))


### FIXED CODE ###

from collections import deque

H, W = [int(x) for x in input().split()]
cell = [list(input()) for i in range(H)]

painted = deque()
for h in range(H):
    for w in range(W):
        if cell[h][w] == '#':
            painted.append([h, w, 0])

ans = 0
while len(painted) > 0:
    blackcell = painted.popleft()
    for dy, dx in [[1, 0], [0, 1], [-1, 0], [0, -1]]:
        nh = blackcell[0] + dy
        nw = blackcell[1] + dx
        d = blackcell[2]
        if 0 <= nh < H and 0 <= nw < W and cell[nh][nw] == '.':
            cell[nh][nw] = '#'
            painted.append([nh, nw, d + 1])
        ans = d

print(ans)
n = input() % 500 # N:払いたい金額
A = input() # A:1円玉の保持数
print("No" if n > A else "Yes")

### FIXED CODE ###

n = int(input()) % 500 # N:払いたい金額
A = int(input()) # A:1円玉の保持数
print("No" if n > A else "Yes")
while 1:
 n,x=map(int,input().split())
 if n+x==0:break
 for i in range(3,n+1):
  for j in range(2,x-i):
   if x-i-j<j<i:
    c+=1
 print(c)

### FIXED CODE ###

from itertools import combinations
while 1:
 n,m=map(int,input().split())
 if n==m==0:break
 print(sum(1 for p in combinations(range(1,n+1),3)if sum(p)==m))
n,m=map(int,input().split())
val =[[]for _ in range(m+1)]
for _ in range(n):
	a,b=map(int,input().split())
	val[a].append(b)
mval = [0]*(m+1)
for i in range(1,m+1):
	val[i].sort(reverse=True)
	mval[i] = val[i][0] if val[i] else 0
ans = 0
for dayleft in range(1,m+1):
	cidx = mval.index(max(mval[1:dayleft+1]))
	if cidx == 0:
		continue
	ans += mval[cidx]
	del val[cidx][0]
	mval[cidx] = 0 if val[cidx]==[] else val[cidx][0]

print(ans)

### FIXED CODE ###

from heapq import heappush, heappop
n,m=map(int,input().split())
works = []
for _ in range(n):
	a,b=map(int,input().split())
	if a>m:
		continue
	works.append((a,b))
works.sort(reverse=True)
q=[]
ans=0

for dayleft in range(1,m+1):
	while works and works[-1][0]<=dayleft:
		a,b=works.pop()
		heappush(q,-b)
	if q:
		b = -heappop(q)
		ans+=b
print(ans)
import array
import bisect


def is_prime_number(num):
    limit = int(num ** 0.5)

    for lp in range(3, limit + 1, 2):
        if num % lp == 0:
            return False

    return True


def binary_search(num_list, num):
    left = 0
    right = len(num_list)

    while left <= right:
        mid = (left + right) // 2

        if num_list[mid] == num:
            return True
        elif num_list[mid] < num:
            left = mid + 1
        else:
            right = mid - 1

    return False


LENGTH = 1000000
prime_number_list = array.array("i", [True] * (LENGTH + 1))

prime_number_list[0] = False
prime_number_list[1] = False

for lp in range(4, LENGTH + 1, 2):
    prime_number_list[lp] = False

limit = int((LENGTH + 1) ** 0.5)

for lp in range(3, limit + 1, 2):
    if is_prime_number(lp):
        for lp2 in range(lp * 2, LENGTH + 1, lp):
            prime_number_list[lp2] = False

prime_number_list = array.array("i", [index for index, item in enumerate(prime_number_list) if item])

while True:

    input_num = int(input())

    if input_num == 0:
        break

    count = 0

    array_size = bisect.bisect_left(prime_number_list, input_num // 2)

    for lp in prime_number_list[:array_size + 1]:

        search_num = input_num - lp

        if binary_search(prime_number_list, search_num):
            count += 1

    print(count)



### FIXED CODE ###

import array


def is_prime_number(num):
    limit = int(num ** 0.5)

    for lp in range(3, limit + 1, 2):
        if num % lp == 0:
            return False

    return True


LENGTH = 1000000
prime_number_list = array.array("i", [True] * (LENGTH + 1))

prime_number_list[0] = False
prime_number_list[1] = False

for lp in range(4, LENGTH + 1, 2):
    prime_number_list[lp] = False

limit = int((LENGTH + 1) ** 0.5)

for lp in range(3, limit + 1, 2):
    if is_prime_number(lp):
        for lp2 in range(lp * 2, LENGTH + 1, lp):
            prime_number_list[lp2] = False

while True:
    input_num = int(input())

    if input_num == 0:
        break

    count = 0

    for lp in range(2, input_num // 2 + 1):

        if prime_number_list[lp] and prime_number_list[input_num - lp]:
            count += 1

    print(count)
n = int(input())
# divisors = []
move =[]
for i in range(1, int(n**0.5)+1):
    if n % i == 0:
#         divisors.append(i)
        move.append(i+n//i)
        if i != n // i:
            divisors.append(n//i)
        
# divisors.sort()
# print(divisors)
# print(move)
print(min(move)-2)

### FIXED CODE ###

n = int(input())
move =[]
for i in range(1, int(n**0.5)+1):
    if n % i == 0:
        move.append(i+n//i)
# print(move)
print(min(move)-2)
from bisect import bisect_right

n, x = map(int, input().split())
a = list(map(int, input().split()))
a.sort()
SUM = [a[0]]

for i in range(1, n):
    SUM.append(SUM[-1]+a[i])

if SUM[-1] < x:
    print(n-1)
else:
    print(bisect_right(x, SUM))

### FIXED CODE ###

from bisect import bisect_right

n, x = map(int, input().split())
a = list(map(int, input().split()))
a.sort()
SUM = [a[0]]

for i in range(1, n):
    SUM.append(SUM[-1]+a[i])

if SUM[-1] < x:
    print(n-1)
else:
    print(bisect_right(SUM, x))
N = input(int())

print((N + 1) // 2 / N)

### FIXED CODE ###

a = int(input())

if a % 2 == 1:
  b = a // 2 + 1
else:
  b = a / 2
  
print(b / a)
S = input()
Q = int(input())

for k in range(Q):
    q =  [ i for i in input().split(' ')]
    if q[0] == '1':
        if not len(S) == 1:
            head = S[0]
            tail = S[-1]
            S = tail + S[1:-1] + head
            print(S)
    else:
        if q[1] == '1':
            S = q[2] + S
            print(S)
        else:
            S = S + q[2]
            print(S)
print(S)

### FIXED CODE ###

S = input()
Q = int(input())
front = ""
flag = 1
for i in range(Q):
    q =  [ i for i in input().split(' ')]
    if q[0] == '1':
        flag = flag * -1
    else:
        if flag == 1: 
            if q[1] == '1':
                front+=q[2]
            else:
                S += q[2]
        else:
            if q[1] == '1':
                S +=q[2]
            else:
                front+= q[2]
            
if flag ==1:
    print(front[::-1] + S)
else:
    print(S[::-1] + front)
import math

x1, y1, x2, y2 = raw_input().split()

print sqrt((x2-x1)**2 + (y2-y1)**2)

### FIXED CODE ###

import math

x1, y1, x2, y2 = map(float, raw_input().split())
print math.sqrt((x2-x1)**2 + (y2-y1)**2)
N = int(input())
A = list(map(int, input().split()))
res = 1

if 0 in A :
    res = 0

for x in range(N) :
    res = res*A[x]
    if res > 10E+18
        res = -1
        break

print(res)

### FIXED CODE ###

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

limit = 10 ** 18
A.sort()
result = A[0]
for a in A[1:]:
    result *= a
    if result > limit:
        print(-1)
        exit()
print(result)
boundaries = [399, 799, 1199, 1599, 1999, 2399, 2799, 3199, 4800]
input()
rates = sorted([int(x) for x in input().split()])
counts = []
for boundary in boundaries:
    tmp = 0
    while rates[0] <= boundary:
        tmp += 1
        rates.pop(0)
    counts.append(tmp)
least = sum([x > 0 for x in counts[:-1]])
print("{} {}".format(1 if least == 0 else least, counts[-1]+least))


### FIXED CODE ###

# -* encode: utf-8 *-

N = int(input())
rates = [int(x) for x in input().split()]

rates.sort()
uppers = [399, 799, 1199, 1599, 1999, 2399, 2799, 3199, 4800]
accum = list()
counts = list()

for upper in uppers:
    accum.append(len([x for x in rates if x <= upper]))

counts.append(accum[0])
for i in range(1, 9):
    counts.append(accum[i] - accum[i-1])

_least = sum([1 for count in counts[:-1] if count > 0])
max_scorerer = counts[-1]

if _least == 0:
    least = 1
    most = max_scorerer
else:
    least = _least
    most = least + max_scorerer

print("{} {}".format(least, most))
n,q = input().split()
n = int(n)
q = int(q)
T = [0] * (n+1)
A = [0] * (n+1)
B = [0] * (n+1)
P = [0] * (q+1)
X = [0] * (q+1)
for i in range(1,n):
    A[i],B[i] = [int(j) for j in input().split()]
for i in range(1,q+1):
    P[i],X[i] = [int(j) for j in input().split()]

NIL = -1

class node:
    def __init__(self):
        self.value = 0
        self.child = []
        self.parent = NIL

def childadd(T,x):
    for i in range(len(T[x].child)):
        T[T[x].child[i]].value += T[x].value
        childadd(T,T[x].child[i])

for i in range(1,n+1):
    T[i] = node()

for i in range(1,n):
    T[A[i]].child.append(B[i])

for i in range(1,q+1):
    T[P[i]].value += X[i]

childadd(T,1)

for i in range(1,n+1):
    print(T[i].value,end = " ")


### FIXED CODE ###

from collections import deque

n,q = input().split()
n = int(n)
q = int(q)
T = [0] * (n+1)

to = [[] for i in range(n+1)]
cnt = [0] * (n)
for i in range(1,n):
    a,b = [int(j) for j in input().split()]
    to[a].append(b)
    to[b].append(a)
for i in range(1,q+1):
    P,X = [int(j) for j in input().split()]
    T[P] += X
NIL = -1

q =deque()
q.append((1,0,NIL))
while len(q)>0:
    p,x,prev = q.pop()
    x += T[p]
    cnt[p-1] = x
    for i in to[p]:
        if i != prev:
            q.append((i,x,p))
print(*cnt)
s = input()
print(s if len(s)==2 else s[::-1]

### FIXED CODE ###

s = input()
print(s if len(s)==2 else s[::-1])
def rec(c, a, x, n, m, start, states, best, price):

    for i in range(start, n):
        price += c[i]
        states[0] += a[i][0]
        states[1] += a[i][1]
        states[2] += a[i][2]

        if states[0] >= x and states[1] >= x and states[2] >= x and price < best:
            best = price

        if i != n - 1:
            best = rec(c, a, x, n, m, i + 1, states, best, price)

        states[0] -= a[i][0]
        states[1] -= a[i][1]
        states[2] -= a[i][2]
        price -= c[i]

    return best


def task(n, m, x, c, a):
    mx = [0] * n
    for i in range(0, n):
        for j in range(0, m):
            mx[j] += a[i][j]

    for j in range(0, m):
        if mx[j] < x:
            print(-1)
            return

    best = rec(c, a, x, n, m, 0, [0, 0, 0], 1000000, 0)

    print(best)


n, m, x = map(int, input().split())
c = []
a = []
for i in range(0, n):
    values = list(map(int, input().split()))
    c.append(values[0])
    a.append(values[1:])

task(n, m, x, c, a)


### FIXED CODE ###

def task(s, t):
    for i in range(0, len(s)):
        if s[i] != t[i]:
            print("No")
            return

    print("Yes")


s = input()
t = input()
task(s, t)
n = int(input())
if n % 4 == 3 or n % 4 == 0:
    print('Yes')
else:
  print('No')

### FIXED CODE ###

N, K = (int(i) for i in input().split())
if N % K == 0:
    print(int(0))
else :
  print(int(1))
a,b=int(input()),str(input())
b.replace(".","")
print(int(a*b/100))

### FIXED CODE ###

A, B = input().split()
A, B = int(A), int(B.replace('.', ''))
print(A * B // 100)
import itertools
n,m=map(int,input().split())
p=[[False]*n for i in range(n)]

for i in range(m):
    a,b=map(int,input().split())
    a-=1
    b-=1
    p[a][b]=True
    p[b][a]=True
ans=0
for i in itertools.permutations(range(1,n),n-1):
    list=[0]+[i]
    if all(p[list[j]][list[j+1]]==True for j in range(n)):
        ans+=1
print(ans)   

### FIXED CODE ###

import itertools
n,m=map(int,input().split())
p=[[False]*n for i in range(n)]

for i in range(m):
    a,b=map(int,input().split())
    a-=1
    b-=1
    p[a][b]=True
    p[b][a]=True
ans=0
for i in itertools.permutations(range(n),n):
    if i[0]==0:
        for j in range(n):
            if j==n-1:
                ans+=1
                break
            if not p[i[j]][i[j+1]]:
                break
print(ans)
from collections import deque

nCr = {}


def cmb(n, r):
    if r == 0 or r == n:
        return 1
    if r == 1:
        return n
    if (n, r) in nCr:
        return nCr[(n, r)]
    nCr[(n, r)] = cmb(n-1, r) + cmb(n-1, r-1)
    return nCr[(n, r)]


N, P = map(int, input().split())
A = np.array(list(map(int, input().split())))

li = list(np.mod(A, 2))
zero = li.count(0)
one = li.count(1)

if P == 0:
    combi = [0] + [2 * x for x in range(1, (one + 2) // 2)]
if P == 1:
    combi = [1] + [2 * x + 1 for x in range(1, (one + 1) // 2)]

q = deque(combi)

right = 0
while q:
    c = q.popleft()
    tmp = cmb(one, c)
    right += tmp

print(2**zero * right)

### FIXED CODE ###

from collections import deque
import numpy as np
from functools import lru_cache

nCr = {}


@lru_cache(maxsize=None)
def cmb(n, r):
    if r == 0 or r == n:
        return 1
    if r == 1:
        return n
    if (n, r) in nCr:
        return nCr[(n, r)]
    nCr[(n, r)] = cmb(n-1, r) + cmb(n-1, r-1)
    return nCr[(n, r)]


N, P = map(int, input().split())
A = np.array(list(map(int, input().split())))

li = list(np.mod(A, 2))
zero = li.count(0)
one = li.count(1)

if P == 0:
    combi = [0] + [2 * x for x in range(1, (one + 2) // 2)]
if P == 1:
    combi = [1] + [2 * x + 1 for x in range(1, (one + 1) // 2)]

q = deque(combi)

right = 0
while q:
    c = q.popleft()
    tmp = cmb(one, c)
    right += tmp

print(2**zero * right)
[N,M,K] = list(map(int,input().split()))

F = [[] for i in range(N)]
B = [[] for i in range(N)]

for i in range(M):
    [A0,B0] = list(map(int,input().split()))
    F[A0-1].append(B0)
    F[B0-1].append(A0)
for i in range(K):
    [C0,D0] = list(map(int,input().split()))
    B[C0-1].append(D0)
    B[D0-1].append(C0)


def check(X,L):
    for i in F[X]:
        if ch[i-1]==0:
            ch[i-1]=1
            L.append(i)
            check(i-1,L)
X = []
ch = [0]*N
t = 0
while True:
    if t==N:
        break
    L0 = []
    L0.append(t+1)
    ch[t]=1
    check(t,L0)
    X.append(L0)
    while (t<N)and(ch[t]==1):
        t+=1
output = [0]*N
for i in range(len(X)):
    for j in X[i]:
        output[j-1] = len(X[i]) - len(F[j-1]) - len(set(B[j-1])&set(X[i]))-1

st = ""
for i in range(N-1):
    st += str(output[i]) + " "
st += str(output[N-1])
print(st)

### FIXED CODE ###

class UnionFind():
    def __init__(self, n):
        self.n = n
        self.parents = [-1] * n

    def find(self, x):
        if self.parents[x] < 0:
            return x
        else:
            self.parents[x] = self.find(self.parents[x])
            return self.parents[x]

    def union(self, x, y):
        x = self.find(x)
        y = self.find(y)

        if x == y:
            return

        if self.parents[x] > self.parents[y]:
            x, y = y, x

        self.parents[x] += self.parents[y]
        self.parents[y] = x

    def size(self, x):
        return -self.parents[self.find(x)]

    def same(self, x, y):
        return self.find(x) == self.find(y)

    def members(self, x):
        root = self.find(x)
        return [i for i in range(self.n) if self.find(i) == root]

    def roots(self):
        return [i for i, x in enumerate(self.parents) if x < 0]

    def group_count(self):
        return len(self.roots())

    def all_group_members(self):
        return {r: self.members(r) for r in self.roots()}

    def __str__(self):
        return '\n'.join('{}: {}'.format(r, self.members(r)) for r in self.roots())


N, M, K = map(int, input().split())
Network = UnionFind(N)
Friend = [0] * N
BlockInNetwork = [0] * N

for _ in range(M):
    a, b = map(int, input().split())
    Network.union(a-1, b-1)
    Friend[a-1] += 1
    Friend[b-1] += 1

for _ in range(K):
    c, d = map(int, input().split())
    if Network.same(c-1, d-1):
        BlockInNetwork[c-1] += 1
        BlockInNetwork[d-1] += 1

out = [0]*N
for i in range(N):
    out[i]=Network.size(i)-Friend[i]-BlockInNetwork[i] - 1
print(*out)
pow(x,3)




### FIXED CODE ###

x = input('')
x = int(x)
ans = int(pow(x,3))
print(ans)
N = int(input())
sum=0
import math
from functools import reduce
def gcd(*numbers):
    return reduce(math.gcd, numbers)
from itertools import product
pools = product(N,N,N)
for i, j ,k in pools:
  sum =sum + gcd(i, j, k)

### FIXED CODE ###

N = int(input())
sum=0
import math
for i in range(N):
  for j in range(N):
       t=math.gcd(i+1,j+1)
       for k in range(N):
          sum =sum + math.gcd(t, k+1)
print(sum)
import sys
import numpy as np

def main():
    MOD = int(1e9 + 7)

    n, k = map(int, input().split())
    can = np.zeros((n,n))
    for i in range(n):
        for j, e in enumerate(int(c) for c in input().split()):
            can[i,j] = e

    answer = np.identity(n)
    while k:
        if k % 2:
            answer = np.dot(answer, can)
        can = np.dot(can, can)
        k //= 2

    total = 0
    for i in range(n):
        for j in range(n):
            total += int(answer[i,j])
            if total >= MOD:
                total -= MOD

    print(total)


if __name__ == "__main__":
    main()


### FIXED CODE ###

import sys
import numpy as np


def main():
    MOD = int(1e9 + 7)

    n, k = map(int, input().split())
    can = [[int(c) for c in input().split()] for _ in range(n)]
    can = np.matrix(can, 'O')
    
    # for i in range(n):
    #     for j, e in enumerate(int(c) for c in input().split()):
    #         can[i, j] = e

    b = np.eye(n, n, 0, 'O')
    while k:
        b = [b, b*can % MOD][k & 1]
        can = can*can % MOD
        k >>= 1

    print(b.sum() % MOD)

    # answer = np.eye(n, dtype=int)
    # while k:
    #     if k % 2:
    #         answer = np.dot(answer, can) % MOD
    #     can = np.dot(can, can) % MOD
    #     k //= 2

    # total = 0
    # for i in range(n):
    #     for j in range(n):
    #         total += answer[i,j]
    #         if total >= MOD:
    #             total -= MOD

    # print(total)


if __name__ == "__main__":
    main()
N , K = map(int,input().split())

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

reach = [-1 for i in range(N)]
reach[0] = 0 #最初の町は0回でいく
now = 0
#loop = 1
dic ={}
dic[0] = 0
for i in range(N+1):
  to = A[now]-1
  if reach[to] != -1:
    ini = i+1
    #print(i,to,reach[to])
    loop = i+1 - reach[to]
    break
  if i+1 not in dic:
    dic[i+1] = to
  reach[to] = i+1
  #loop += 1
  now = to


#print(dic,reach,loop,ini)
if K <= ini:
  print(dic[K]+1)
else:
  t = (ini-loop) + (K-ini)%loop
  print(dic[t]+1)

### FIXED CODE ###

N , K = map(int,input().split())
 
A = list(map(int,input().split()))
 
reach = [-1 for i in range(N)]
reach[0] = 0 #最初の町は0回でいく
now = 0
#loop = 1
dic ={}
dic[0] = 0
for i in range(N):
  to = A[now]-1
  if reach[to] != -1:
    ini = i+1
    #print(i,to,reach[to])
    loop = i+1 - reach[to]
    break
  if i+1 not in dic:
    dic[i+1] = to
  reach[to] = i+1
  #loop += 1
  now = to
 
 
#print(dic,reach,loop,ini)
if K < ini:
  print(dic[K]+1)
else:
  t = (ini-loop) + (K-ini)%loop
  print(dic[t]+1)