Harryxun/stf_run huggingface dataset:
import numpy as np
n, m, k = map(int, input().split())
ab = [list(map(int, input().split())) for _ in range(m)]
cd = [list(map(int, input().split())) for _ in range(k)]
con = [1 for _ in range(n+1)]
uni = np.array([-1 for i in range(n+1)])

def root(num, pea, index=True):
    get_index = []
    while pea[num] > 0:
        get_index.append(num)
        num = pea[num]
    if index:
        return num, get_index
    else:
        return num

for i in range(m):
    a, b = ab[i]
    con[a] += 1
    con[b] += 1
    if uni[a] != uni[b] or uni[a] < 0 or uni[b] < 0:
        root_a, get_a_index = root(a, uni)
        root_b, get_b_index = root(b, uni)
        root_a, root_b = sorted([root_a, root_b])
        uni[root_a] += uni[root_b]
        uni[get_a_index+get_b_index+[root_b]] = root_a

for i in range(k):
    c, d = cd[i]
    if root(c, uni, index=False) == root(d, uni, index=False):
        con[c] += 1
        con[d] += 1

result = []
for i in range(1, n+1):
    root_i = root(i, uni, index=False)
    result.append(-uni[root_i]-con[i])
print(*result)

### FIXED CODE ###

class UnionFind():
    # 作りたい要素数nで初期化
    # 使用するインスタンス変数の初期化
    def __init__(self, n):
        self.n = n
        # root[x]<0ならそのノードが根かつその値が木の要素数
        # rootノードでその木の要素数を記録する
        self.root = [-1]*(n+1)
        # 木をくっつける時にアンバランスにならないように調整する
        self.rnk = [0]*(n+1)

    # ノードxのrootノードを見つける
    def Find_Root(self, x):
        if(self.root[x] < 0):
            return x
        else:
            # ここで代入しておくことで、後の繰り返しを避ける
            self.root[x] = self.Find_Root(self.root[x])
            return self.root[x]
    # 木の併合、入力は併合したい各ノード
    def Unite(self, x, y):
        # 入力ノードのrootノードを見つける
        x = self.Find_Root(x)
        y = self.Find_Root(y)
        # すでに同じ木に属していた場合
        if(x == y):
            return 
        # 違う木に属していた場合rnkを見てくっつける方を決める
        elif(self.rnk[x] > self.rnk[y]):
            self.root[x] += self.root[y]
            self.root[y] = x

        else:
            self.root[y] += self.root[x]
            self.root[x] = y
            # rnkが同じ（深さに差がない場合）は1増やす
            if(self.rnk[x] == self.rnk[y]):
                self.rnk[y] += 1
    # xとyが同じグループに属するか判断
    def isSameGroup(self, x, y):
        return self.Find_Root(x) == self.Find_Root(y)

    # ノードxが属する木のサイズを返す
    def Count(self, x):
        return -self.root[self.Find_Root(x)]


n, m, k = map(int, input().split())
ab = [list(map(int, input().split())) for _ in range(m)]
cd = [list(map(int, input().split())) for _ in range(k)]
con = [1 for _ in range(n+1)]
uni = UnionFind(n+1)


for i in range(m):
    a, b = ab[i]
    con[a] += 1
    con[b] += 1
    uni.Unite(a, b)

for i in range(k):
    c, d = cd[i]
    if uni.isSameGroup(c,d):
        con[c] += 1
        con[d] += 1

result = []
for i in range(1, n+1):
    result.append(uni.Count(i)-con[i])
print(*result)
W,H,x,y,r,=map(int,input().split())
if (x-r<0 or x+r>W) and() (y-r<0 or y+r>H):
    print ("No")
elif (x-r>=0 and x+r<=W) and() (y-r>=0 and y+r<=H):
    print ("Yes")


### FIXED CODE ###

W,H,x,y,r,=map(int,input().split())
if (x-r<0 or x+r>W) or (y-r<0 or y+r>H):
    print ("No")
elif (x-r>=0 and x+r<=W) or (y-r>=0 and y+r<=H):
    print ("Yes")
s,t=input().split()
print=(t+S)

### FIXED CODE ###

s,t=input().split()
print(t+s)
n = int(input())
nums = [int(input()) for _ in range(n)]
cnt = {}
ans = 0
for x in nums:
    if x not in cnt:
        cnt[x] = 1
    else:
        cnt[x] += 1
for y in cnt.values():
    if cnt[y] % 2 != 0:
        ans += 1

print(ans)

### FIXED CODE ###

n = int(input())
nums = [int(input()) for _ in range(n)]
cnt = {}
ans = 0
for x in nums:
    if x not in cnt:
        cnt[x] = 1
    else:
        cnt[x] += 1
for y in cnt.values():
    if y % 2 != 0:
        ans += 1

print(ans)
A,V = (int(x) for x in input().split())
B,W = (int(x) for x in input().split())
T = int(input())
if V>W and (A-B)%(V-W)==0 and abs(A-B)//(V-M)<=T:
    Flag = True
else:
    Flag = False
    
if Flag:
    print('YES')
else:
    print('NO')

### FIXED CODE ###

A,V = (int(x) for x in input().split())
B,W = (int(x) for x in input().split())
T = int(input())

if V>W and abs(A-B)/(V-W)<=T:
    Flag = True
else:
    Flag = False
    
if Flag:
    print('YES')
else:
    print('NO')
# -*- coding: utf-8 -*-

#############
# Libraries #
#############

import sys
input = sys.stdin.readline

import math
from collections import deque
from fractions import gcd
from functools import lru_cache


#############
# Constants #
#############

MOD = 10**9+7
INF = float('inf')

#############
# Functions #
#############

######INPUT######
def inputI(): return int(input().strip())
def inputS(): return input().strip()
def inputIL(): return list(map(int,input().split()))
def inputSL(): return list(map(str,input().split()))
def inputILs(n): return list(int(input()) for _ in range(n))
def inputSLs(n): return list(input().strip() for _ in range(n))
def inputILL(n): return [list(map(int, input().split())) for _ in range(n)]
def inputSLL(n): return [list(map(str, input().split())) for _ in range(n)]

#####Inverse#####
def inv(n): return pow(n, MOD-2, MOD)

######Combination######
kaijo_memo = []
def kaijo(n):
  if(len(kaijo_memo) > n):
    return kaijo_memo[n]
  if(len(kaijo_memo) == 0):
    kaijo_memo.append(1)
  while(len(kaijo_memo) <= n):
    kaijo_memo.append(kaijo_memo[-1] * len(kaijo_memo) % MOD)
  return kaijo_memo[n]

gyaku_kaijo_memo = []
def gyaku_kaijo(n):
  if(len(gyaku_kaijo_memo) > n):
    return gyaku_kaijo_memo[n]
  if(len(gyaku_kaijo_memo) == 0):
    gyaku_kaijo_memo.append(1)
  while(len(gyaku_kaijo_memo) <= n):
    gyaku_kaijo_memo.append(gyaku_kaijo_memo[-1] * pow(len(gyaku_kaijo_memo),MOD-2,MOD) % MOD)
  return gyaku_kaijo_memo[n]

def nCr(n,r):
  if(n == r):
    return 1
  if(n < r or r < 0):
    return 0
  ret = 1
  ret = ret * kaijo(n) % MOD
  ret = ret * gyaku_kaijo(r) % MOD
  ret = ret * gyaku_kaijo(n-r) % MOD
  return ret

######Factorization######
def factorization(n):
    arr = []
    temp = n
    for i in range(2, int(-(-n**0.5//1))+1):
        if temp%i==0:
            cnt=0
            while temp%i==0:
                cnt+=1
                temp //= i
            arr.append([i, cnt])
    if temp!=1:
        arr.append([temp, 1])

    if arr==[]:
        arr.append([n, 1])
    return arr

#####LCM#####
def lcm(a, b):
    return a * b // gcd (a, b)

#############
# Main Code #
#############

N,M = inputIL()
S = inputS()

if "1"*M in S:
  print(-1)
  exit()  

if M>=N:
  print(N)
  exit()
  
  
max_n = [0 for i in range(N+1)]

for i in range(1,N+1):
  s = S[max(0,i-M):i]
  l = len(s)
  mask = (1<<l) -1
  b = (~int(s, 2)) & mask
  max_n[i] = math.floor(math.log(b)/math.log(2))+1
  
now = N
deme = []
while now != 0:
  x = max_n[now]
  now = now-x
  deme.append(x)

print(*deme[::-1])

### FIXED CODE ###

import sys
input = sys.stdin.readline

import math
import bisect

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

if "1"*M in S:
  print(-1)
  exit()  

S = [int(S[i]) for i in range(N+1)]

L = [(1<<i) -1 for i in range(1,M+1)]

max_n = [0]
mask = (1<<M) -1
b = 0
for i in range(N):
  b = ((b<<1) + (1- S[i])) & mask
  max_n.append(bisect.bisect_left(L,b)+1)

now = N
deme = []
while now != 0:
  x = max_n[now]
  now -= x
  deme.append(x)
print(*deme[::-1])
n1,n2,n3 = map(int,input().split(" "))

list1 = [list(map(int,input().split(" "))) for _ in range(n1)]
list2 = [list(map(int,input().split(" "))) for _ in range(n2)]

mat = [[0 for _ in range(n1)] for _ in range(n3)]

for i in range(n1):
	for j in range(n2):
		for k in range(n3):
			mat[i][k] += list1[i][j] * list2[j][k]

for m in mat:
	print(*m)



### FIXED CODE ###

n1,n2,n3 = map(int,input().split(" "))

list1 = [list(map(int,input().split(" "))) for _ in range(n1)]
list2 = [list(map(int,input().split(" "))) for _ in range(n2)]

mat = [[0 for _ in range(n3)] for _ in range(n1)]

for i in range(n1):
	for j in range(n3):
		mat[i][j]= str(sum(list1[i][k] * list2[k][j] for k in range(n2)))

for m in mat:
	print(*m)
def lcs_size():
  X = input()
  Y = input()
  
  a = len(X)
  b = len(Y)
  
  c = [[0 for i in range(a+1)] for j in range(b+1)]
  maxl = 0
  for i in range(a):
    for j in range(b):
      if X[i] == Y[j]:
        c[i+1][j+1] = c[i][j] + 1
      else:
        c[i+1][j+1] = max(c[i][j+1], c[i+1][j])
      maxl = max(maxl, c[i+1][j+1])
  
  return maxl

q = input()

for i in range(q):
  print lcs_siz()

### FIXED CODE ###

def lcs_size():
  X = raw_input()
  Y = raw_input()
  a = len(X)
  b = len(Y)
  z2 = [0 for i in range(b+1)]

  for i in range(a):
    ch = X[i]
    z1 = z2 + []
    for j in range(b):
      if ch == Y[j]:
        z2[j+1] = z1[j] + 1
      elif z2[j+1] < z2[j]:
        z2[j+1] = z2[j]

  return z2[-1]

q = input()
for k in range(q):
  print lcs_size()
a = int(input())
b = int(input())
if a*b%2 ==0:
    print('Even')
else:
    print('Odd')

### FIXED CODE ###

a,b = map(int, input().split())
c = a*b
if c % 2 == 0 :
    print('Even')
else:
    print('Odd')
from scipy.special import comb

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

divided = []
for i in range(N):
    divided.append(A_list.count(i + 1))

ans = 0
for j in divided:
    ans += comb(j, 2)

# print(divided)

for k in range(1, N + 1):
    n = divided[A_list[k - 1] - 1]
    # print(n)
    ans_k = ans
    if n > 1:
        ans_k -= n - 1

    print(int(ans_k))

### FIXED CODE ###

import collections
import math

def combinations_count(n, r):
    return math.factorial(n) // (math.factorial(n - r) * math.factorial(r))

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

counts = collections.Counter(A_list)
ans = 0
for _, v in counts.items():
    # ans += len(list(itertools.combinations(range(v), 2)))
    if v > 1:
        ans += combinations_count(v, 2)

for k in range(1, N + 1):
    n = counts[A_list[k - 1]]
    ans_k = ans
    if n > 1:
        ans_k -= n - 1

    print(int(ans_k))
a = map(int,raw_input().split())
a.reverse()
for i in range(len(a)):
  if i == 0:
    res = 0
  else :
    res += a[i-1]-a[i]
print(res)

### FIXED CODE ###

a = list(map(int, input().split())) 
a.sort()
for i in range(len(a)):
  if i == 0:
    res = 0
  else :
    res += a[i]-a[i-1]
print(res)
from collections import Counter
import fractions

N = int(input())
s=[0]*N
S = []
mydict = {}
flag=0
for i in range(N):
    s_sorted =''.join(map(str, sorted(str(input()))))
    S.append(s_sorted)
c = Counter(S)
ans =0
for i in range(len(list(c.values()))):
    ans = ans+math.factorial(list(c.values())[i])/math.factorial(2)/math.factorial(list(c.values())[i]-2)
print(int(ans))

### FIXED CODE ###

n = int(input())
strings_list = [list(input()) for i in range(n)]
counter = 0
dict = {}
 
for strings in strings_list:
    strings = "".join(sorted(strings))
    if strings in dict.keys():
        counter += dict[strings]
        dict[strings] += 1
    else:
        dict[strings] = 1
print(counter)
import sys,queue,math,copy,itertools,bisect,collections,heapq

def main():
    sys.setrecursionlimit(10**7)
    INF = 10**18
    MOD = 10**9 + 7
    LI = lambda : [int(x) for x in sys.stdin.readline().split()]
    NI = lambda : int(sys.stdin.readline())
    SI = lambda : sys.stdin.readline().rstrip()

    N,M = LI()

    d = {}
    m = M
    for i in range(2,int(math.sqrt(M))+1):
        while m % i == 0:
            if i in d:
                d[i] += 1
            else:
                d[i] = 1
            m //= i
    if m > 1:
        d[m] = 1

    a = [0]
    b = [0]
    c = 1
    for i in range(1,N+(int(math.log(N,2))+1)**2 +1):
        c = (c * i) % MOD
        a.append(c)
        b.append(pow(c,MOD-2,MOD))

    ans = 1
    for v in d.values():
        ans = (ans * a[N+v-1] * b[v]* b[N-1]) % MOD
    print(ans)

if __name__ == '__main__':
    main()

### FIXED CODE ###

import sys,queue,math,copy,itertools,bisect,collections,heapq

def main():
    MOD = 10**9 + 7
    LI = lambda : [int(x) for x in sys.stdin.readline().split()]

    N,M = LI()

    d = {}
    m = M
    for i in range(2,int(math.sqrt(M))+1):
        while m % i == 0:
            if i in d:
                d[i] += 1
            else:
                d[i] = 1
            m //= i
    if m > 1:
        d[m] = 1

    a = [1]
    b = [1]
    c = 1
    for i in range(1,N+int(math.log(M,2)) +1):
        c = (c * i) % MOD
        a.append(c)
        b.append(pow(c,MOD-2,MOD))

    ans = 1
    for v in d.values():
        ans = (ans * a[N+v-1] * b[v]* b[N-1]) % MOD
    print(ans)

if __name__ == '__main__':
    main()
import sys
N = int(input().strip())
grid = []
for i in range(N):
    array = list(map(int, input().strip().split(' ')))
    grid.append(array)
x = 0
y = 0
while y <= 100:
  x = 0
  while x <= 100:
    lis = []
    for arrays in grid:
      if arrays[2]>=1:
        lis.append(arrays[2]+abs(x-arrays[0])+abs(y-arrays[1]))
    if min(lis)==max(lis):
      if print(x,y,max(0,arrays[2]+abs(x-arrays[0])+abs(y-arrays[1])))
      sys.exit()
    x += 1
  y += 1
        


### FIXED CODE ###

import sys
N = int(input().strip())
grid = []
ref = 0
for i in range(N):
    array = list(map(int, input().strip().split(' ')))
    grid.append(array)
    if array[2]>0:
      ref = i
x = 0
y = 0
while y <= 100:
  x = 0
  while x <= 100:
    flag = 0
    h0 = grid[ref][2]+abs(x-grid[ref][0])+abs(y-grid[ref][1])
    for arrays in grid:
      h = max(0,h0-abs(x-arrays[0])-abs(y-arrays[1]))
      if h != arrays[2]:
        flag = 1
    if flag == 0:
      print(x,y,h0)
      sys.exit()
    x += 1
  y += 1
def solve():
    rec = list(range(1000000))
    odd_rec = rec.copy()
    
    for i in range(2, 181):
        t = i * (i + 1) * (i + 2) // 6
        if t % 2 == 0:
            for i, tpl in enumerate(zip(rec[t:], rec), start=t):
                a, b = tpl
                b += 1
                if b < a:
                    rec[i] = b
        else:
            z_rec = zip(rec[t:], rec, odd_rec[t:], odd_rec)
            for i, tpl in enumerate(z_rec, start=t):
                a, b, c, d = tpl
                b += 1
                if b < a:
                    rec[i] = b
                d += 1
                if d < c:
                    odd_rec[i] = d
    
    n = int(input())
    while n:
        print(rec[n], odd_rec[n])
        n = int(input())

solve()


### FIXED CODE ###

def solve():
    rec = [1000000] * 1000000
    rec[0] = 0
    odd_rec = rec.copy()
    
    for i in range(1, 181):
        t = i * (i + 1) * (i + 2) // 6
        for i, tpl in enumerate(zip(rec[t:t*3+1], rec), start=t):
            a, b = tpl
            b += 1
            if b < a:
                rec[i] = b
        if t % 2:
            for i, tpl in enumerate(zip(odd_rec[t:t*34+1], odd_rec), start=t):
                a, b = tpl
                b += 1
                if b < a:
                    odd_rec[i] = b
    
    import sys
    file_input = sys.stdin
    n = int(file_input.readline())
    while n:
        print(rec[n], odd_rec[n])
        n = int(file_input.readline())

solve()
INF = 10 ** 9


def calc(point_list, t):
    x_min, y_min, x_max, y_max = INF, INF, -INF, -INF
    for point in point_list:
        x, y, d = point
        dx = t if d == 'R' else (-t if d == 'L' else 0)
        dy = t if d == 'U' else (-t if d == 'D' else 0)
        x_min = min(x_min, x + dx)
        x_max = max(x_max, x + dx)
        y_min = min(y_min, y + dy)
        y_max = max(y_max, y + dy)
    return (x_max - x_min) * (y_max - y_min)


def main():
    N = int(input())
    point_list = list()
    x_min, y_min, x_max, y_max = INF, INF, -INF, -INF
    for _ in range(N):
        X, Y, D = input().split()
        X = int(X)
        x_min = min(x_min, X)
        x_max = max(x_max, X)
        Y = int(Y)
        y_min = min(y_min, Y)
        y_max = max(y_max, Y)
        point_list.append((X, Y, D))
    t_left, t_right = 0, max(x_max - x_min, y_max - y_max)
    while t_right - t_left > 10 ** (-8):
        t_in_left, t_in_right = (2 * t_left + t_right) / 3, (t_left + 2 * t_right) / 3
        if calc(point_list, t_in_left) < calc(point_list, t_in_right):
            t_right = t_in_right
        else:
            t_left = t_in_left
    print(calc(point_list, (t_in_left + t_in_right) / 2))


if __name__ == '__main__':
    main()

### FIXED CODE ###

INF = 10**18


def calc(point_list, t):
    x_min, y_min, x_max, y_max = INF, INF, -INF, -INF
    for point in point_list:
        x, y, d = point
        dx = t if d == 'R' else (-t if d == 'L' else 0)
        dy = t if d == 'U' else (-t if d == 'D' else 0)
        x_min = min(x_min, x + dx)
        x_max = max(x_max, x + dx)
        y_min = min(y_min, y + dy)
        y_max = max(y_max, y + dy)
    return (x_max - x_min) * (y_max - y_min)


def main():
    N = int(input())
    point_list = list()
    x_min, y_min, x_max, y_max = INF, INF, -INF, -INF
    for _ in range(N):
        X, Y, D = input().split()
        X = int(X)
        x_min = min(x_min, X)
        x_max = max(x_max, X)
        Y = int(Y)
        y_min = min(y_min, Y)
        y_max = max(y_max, Y)
        point_list.append((X, Y, D))
    if N == 1:
        print(0)
        return
    t_left, t_right = 0, 2 * max(x_max - x_min, y_max - y_min)
    v_left, v_right = calc(point_list, t_left), calc(point_list, t_right)
    while True:
        dt = t_right - t_left
        if dt < 10 ** (-8):
            break
        t_in_left, t_in_right = t_left + dt / 3, t_right - dt / 3
        v_in_left, v_in_right = calc(point_list, t_in_left), calc(point_list, t_in_right)
        if v_in_left < v_in_right:
            t_right = t_in_right
            v_right = v_in_right
        else:
            t_left = t_in_left
            v_left = v_in_left
    print(v_left)


if __name__ == '__main__':
    main()
import numpy as np
import math

def main():
    N, X = map(int, input().split())
    x = np.asarray(list(map(int, input().split())))
    x = np.absolute(x - X)
    if N > 1:
        d = x[:N-1] - x[1:N]
        l = None
        for i, n in enumerate(d):
            if i == 0:
                l = n
            else:
                l = math.gcd(l, n)
        print(l)
    else:
        print(x[0])


if __name__ == '__main__':
    main()

### FIXED CODE ###


import numpy as np
import fractions

def main():
    N, X = map(int, input().split())
    x = np.asarray(list(map(int, input().split())))
    x = np.absolute(x - X)
    if N > 1:
        l = None
        for i, n in enumerate(x):
            if i == 0:
                l = n
            else:
                l = fractions.gcd(l, n)
        print(l)
    else:
        print(x[0])


if __name__ == '__main__':
    main()
s = input()
t = input()

len_s = len(s)
len_t = len(t)

dp = [[0] * len_t for _ in range(len_s)]

for i in range(len_s):
    for j in range(len_t):
        if s[i] == t[j]:
            dp[i + 1][j + 1] = max(dp[i + 1][j + 1], dp[i][j] + 1)
        dp[i+1][j+1] = max(dp[i+1][j+1], dp[i+1][j])
        dp[i+1][j+1] = max(dp[i+1][j+1], dp[i][j+1])

i = len_s
j = len_t
res = ""
while i > 0 and j > 0:
    if dp[i][j] == dp[i][j-1]:
        j -= 1
    elif dp[i][j] == dp[i-1][j]:
        i -= 1
    else:
        res += s[i-1]
        i -= 1
        j -= 1

print(res[::-1])


### FIXED CODE ###

s = input()
t = input()

dp = [[0] * 3010 for _ in range(3010)]

for i in range(len(s)):
    for j in range(len(t)):
        if s[i] == t[j]:
            dp[i + 1][j + 1] = max(dp[i + 1][j + 1], dp[i][j] + 1)
        dp[i+1][j+1] = max(dp[i+1][j+1], dp[i+1][j])
        dp[i+1][j+1] = max(dp[i+1][j+1], dp[i][j+1])

i = len(s)
j = len(t)
res = ""
while i > 0 and j > 0:
    if dp[i][j] == dp[i][j-1]:
        j -= 1
    elif dp[i][j] == dp[i-1][j]:
        i -= 1
    else:
        res += s[i-1]
        i -= 1
        j -= 1

ans = ""
for i in reversed(range(len(res))):
    ans += res[i]

print(ans)
li=list(input())
a=li[2]
b=li[3]
c=li[4]
d=li[5]
if a=b:
    if c=d:
        print('Yes')
    else:
        print('No')
else:
    print('No')

### FIXED CODE ###

li=list(input())
a=li[2]
b=li[3]
c=li[4]
d=li[5]
if a==b:
    if c==d:
        print('Yes')
    else:
        print('No')
else:
    print('No')
X = int(input())
List =[]
for i in range(33):
    if i >= X:
        break
    for j in range(2,11):
        if i**j < X :
            pass
        elif i**j == X:
            List.append(i**j)
            break
        else:
            List.append(i**(j-1))
            break
print(max(List))

### FIXED CODE ###

X = int(input())
a = 1
for i in range(1,X):
    for j in range(2,X):
        if i**j <= X:
            a = max(a,i**j)
        else:
            break

print(a)
N, K = map(int, input().split())
al = list(map(int, input().split()))

visited_towns = []
for i in range(N):
    next_town  = al[visited_towns[i] - 1]
    if next_town in visited_towns:
        loop_sta = visited_towns.index((next_town)) #　visited_townsにおけるループ開始のインデックス
        loop_end = len(visited_towns) #visited_townsにおけるループの終わりのインデックス
        loop_length = loop_end - loop_sta #繰り返すループの長さ
        amari = (K - loop_sta) % loop_length
        ans = visited_towns[loop_sta + amari]
        print(ans)
        exit()
    else:
        visited_towns.append(next_town)

print(visited_towns[-1])



### FIXED CODE ###

from collections import defaultdict


def inpl():
    return list(map(int, input().split()))


N, K = inpl()
aa = inpl()

s = 1

route = [s]
ed = set([s])

for i in range(1, K + 1):
    s = aa[s - 1]
    if s in ed:
        Li = route.index(s)
        Ri = len(route)
        idx = Li + (K - Li) % (Ri - Li)
        print(route[idx])
        break
    else:
        route.append(s)
        ed.add(s)
        continue
else:
    print(s)
n = int(input()
arr = [[int(i) for i in list(input().split())] for j in range(n)]
for i in range(1,n):
	arr[i][0] += max(arr[i-1][1], arr[i-1][2])
	arr[i][2] += max(arr[i-1][1], arr[i-1][0])
	arr[i][1] += max(arr[i-1][0], arr[i-1][2])
print(max(arr[n-1]))

### FIXED CODE ###

n = int(input())
arr = [[int(i) for i in list(input().split())] for j in range(n)]
for i in range(1,n):
	arr[i][0] += max(arr[i-1][1], arr[i-1][2])
	arr[i][2] += max(arr[i-1][1], arr[i-1][0])
	arr[i][1] += max(arr[i-1][0], arr[i-1][2])
print(max(arr[n-1]))
n=int(input())
L=[list(map(int, input().split())) for i in range(D)]
print(sum(L)-n)

### FIXED CODE ###

n=int(input())
L=list(map(int, input().split()))
print(sum(L)-n)
from math import factorial
import sys

X, Y = map(int, input().split())
MOD = 10 ** 9 + 7

n1 = (2 * X - Y)
n2 = (2 * Y - X)

if n1 % 3 != 0 or n2 % 3 != 0:
    print(0)
    sys.exit()
else:
    n1 = n1 // 3
    n2 = n2 // 3

if n1 == 0 and n2 == 0:
    print(0)
    sys.exit()


P = 10**9 + 7
N = 333334
inv_t = [0]+[1]
for i in range(2,N):
    inv_t += [inv_t[P % i] * (P - int(P / i)) % P]

m = 10**9+7
res = 1
for i in range(n1 + 1, n1 + n2 + 1):
    res = res * i % m
for i in range(1, n1 + 1):
    res = res * inv_t[i] % m
print(res)

### FIXED CODE ###

import sys

X, Y = map(int, input().split())
MOD = 10 ** 9 + 7

if (X + Y) % 3 != 0:
    print(0)
    sys.exit()

n1 = (2 * X - Y) // 3
n2 = (2 * Y - X) // 3

if n1 < 0 or n2 < 0:
    print(0)
    sys.exit()

P = 10 ** 9 + 7
N = 10 ** 6 + 5
inv_t = [0]+[1]
for i in range(2, N):
    inv_t += [inv_t[P % i] * (P - int(P / i)) % P]

m = 10 ** 9 + 7
res = 1
for i in range(2, n1 + n2 + 1):
    res = res * i % m
for i in range(1, n2 + 1):
    res = res * inv_t[i] % m
for i in range(1, n1 + 1):
    res = res * inv_t[i] % m
print(res)
N=int(input())
T=[int(input()) for _ in range(N)]
T=list(set(T))
#print(T)

def gcd(a,b):
  if b==0:
    return a
  else:
    return gcd(b,a%b)

ans=T[0]
for i in range(N):
  #print(ans)
  ans=ans*T[i]//gcd(ans,T[i])
print(ans)

### FIXED CODE ###

N=int(input())
T=[int(input()) for _ in range(N)]
T=list(set(T))
N=len(T)
#print(T)

def gcd(a,b):
  if b==0:
    return a
  else:
    return gcd(b,a%b)

ans=T[0]
for i in range(N):
  #print(ans)
  ans=ans*T[i]//gcd(ans,T[i])
print(ans)
A, B = map(int, input().split())
0<=A<=100
2<=B<=100

if 0 <= A <= 5 :
    B = 0
elif 6 <= A <= 13 :
    B = B//2
else :
    B = B
    if B & 1:
        print(B)
    else :
        break


### FIXED CODE ###

A, B = map(int, input().split())
0<=A<=100
2<=B<=100
if 0<=A<=5 :
    B=0
elif 6<=A<=12 :
    B=B//2
else :
    B=B
print(B)