Harryxun/stf_run huggingface dataset:
#!/usr/bin/env python3
import sys
import statistics
import collections

def solve(n: int, v: "List[int]"):
    half_length = len(v) // 2
    O = [v[i] for i in range(1, n, 2)]
    E = [v[i] for i in range(0, n, 2)]

    co = list(collections.Counter(O).most_common())
    ce = list(collections.Counter(E).most_common())
    o1 = co[0][0]
    e1 = ce[0][0]

    O_ = list(filter(lambda o: o != o1, O))
    E_ = list(filter(lambda e: e != e1, E))
    num_o_1 = len(O_) 
    num_e_1 = len(E_)

    if e1 != o1:
        num = num_o_1 + num_e_1
    else:
        if True and len2(co) == 1 and len2(ce) == 1:
            num = half_length
        elif len(co) == 1:
            e2 = ce[1][0]
            num_e_2 = len(list(filter(lambda e: e != e2, E)))
            num = num_o_1 + num_e_2
        elif len(ce) == 1:
            o2 = co[1][0]
            num_o_2 = len(list(filter(lambda o: o != o2, O)))
            num = num_o_2 + num_e_1
        else:
            e2 = ce[1][0]
            o2 = co[1][0]
            num = min(num_o_1 + num_e_2, num_o_2 + num_e_1)
    print(num)
    return

def len2(l):
    n = 0
    for i in l:
        n += 1
    return n

def main():
    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word
    tokens = iterate_tokens()
    n = int(next(tokens))  # type: int
    v = [ int(next(tokens)) for _ in range(n) ]  # type: "List[int]"
    solve(n, v)

if __name__ == '__main__':
    main()


### FIXED CODE ###

#!/usr/bin/env python3
import sys
import statistics
import collections

def solve(n: int, v: "List[int]"):
    half_length = len(v) // 2
    O = [v[i] for i in range(1, n, 2)]
    E = [v[i] for i in range(0, n, 2)]

    co = list(collections.Counter(O).most_common())
    ce = list(collections.Counter(E).most_common())
    o1 = co[0][0]
    e1 = ce[0][0]

    O_ = list(filter(lambda o: o != o1, O))
    E_ = list(filter(lambda e: e != e1, E))
    num_o_1 = len(O_) 
    num_e_1 = len(E_)

    num = 0
    if e1 != o1:
        num = num_o_1 + num_e_1
    else:
        if len(co) == 1 and len(ce) == 1:
            num = half_length
        elif len(co) == 1:
            e2 = ce[1][0]
            num_e_2 = len(list(filter(lambda e: e != e2, E)))
            num = num_o_1 + num_e_2
        elif len(ce) == 1:
            o2 = co[1][0]
            num_o_2 = len(list(filter(lambda o: o != o2, O)))
            num = num_o_2 + num_e_1
        else:
            e2 = ce[1][0]
            o2 = co[1][0]
            num_e_2 = len(list(filter(lambda e: e != e2, E)))
            num_o_2 = len(list(filter(lambda o: o != o2, O)))
            num = min(num_o_1 + num_e_2, num_o_2 + num_e_1)
    print(num)
    return

def len2(l):
    n = 0
    for i in l:
        n += 1
    return n

def main():
    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word
    tokens = iterate_tokens()
    n = int(next(tokens))  # type: int
    v = [ int(next(tokens)) for _ in range(n) ]  # type: "List[int]"
    solve(n, v)

if __name__ == '__main__':
    main()
from heapq import heappop, heappush 
def dijkstra(xs, ys, xg, yg,h,w,k,field):
    # que->(cost, x, y)
    que = [(0, xs, ys)]
    inf = 10 ** 6
    dp = [[inf for _ in range(w+1)] for _ in range(h+1)]
    visited = [[False for _ in range(w+1)] for _ in range(h+1)]
    dp[xs][ys] = 0
    dx = [-1,0,1,0]
    dy = [0,1,0,-1]
    while que:
        cost, x, y= heappop(que)
        # 現在のコストより高いなら無視する
        # if cost > dp[x][y]:
        #     continue
        if x == xg and y == yg:
            print(cost)
            exit(0)
        if visited[x][y]
            for i in range(4):
                for j in range(1, k+1):
                    x_, y_ = x+j*dx[i], y+j*dy[i]
                    if not field[x_][y_]:
                        break
                    if dp[x_][y_] > dp[x][y] + 1:
                        dp[x_][y_] = dp[x][y] + 1
                        heappush(que, (dp[x_][y_], x_, y_))
        visited[x][y] = True
    print(-1)
        

def main():
    import sys
    def input(): return sys.stdin.readline().rstrip()
    h, w, k = map(int, input().split())
    xs, ys, xg, yg = map(int, input().split())
    field = [[False]*(w+2) for _ in range(h+2)]
    for i in range(h):
        # False で覆うことでx,yの制限をなくす。
        s = [True if _ == '.' else False for _ in input()]
        field[i+1] = [False]+s+[False]
    dijkstra(xs, ys, xg, yg, h, w, k, field)

if __name__ == '__main__':
    main()

### FIXED CODE ###

import sys
from collections import deque
def input(): return sys.stdin.readline().rstrip()

def main():
    
    h, w, k = map(int, input().split())
    xs, ys, xg, yg = map(lambda x: int(x)-1, input().split())
    field = [input() for _ in range(h)]

    inf = 1e7

    dist = [[inf]*w for _ in range(h)]
    dist[xs][ys] = 0
    que = deque([(xs, ys)])
    dx = [-1, 0, 1, 0]
    dy = [0, 1, 0, -1]
    while que:
        x, y = que.popleft()
        for i in range(4):
            nx, ny = x, y
            for _ in range(k):
                nx += dx[i]
                ny += dy[i]
                if nx < 0 or nx >= h or ny < 0 or ny >= w: break
                if field[nx][ny] == '@' or dist[nx][ny] <= dist[x][y]: break
                if dist[nx][ny] > dist[x][y] + 1:
                    dist[nx][ny] = dist[x][y] + 1
                    que.append((nx, ny))
        
    if dist[xg][yg] == inf:
        print(-1)
    else:
        print(dist[xg][yg])
    
if __name__ == '__main__':
    main()
#!/usr/bin/env python
# -*- coding: utf-8 -*-


instr = input()
nq = instr.split(" ")

N = int(nq[0])
Q = int(nq[1])
balls = [chr(i) for i in range(65, 65+N)]

for i in range(N -1 ):
    for j in range(N - i  - 1):
        print("? %s %s"%(balls[j], balls[j + 1]), flush=True)
        ans = input()
        if(ans == ">") :
            balls[j + 1], balls[j] = balls[j], balls[j + 1]

print ("! %s"%"".join(balls), flush=True)


### FIXED CODE ###

#!/usr/bin/env python
# -*- coding: utf-8 -*-

abinput = input()
ab = abinput.split(" ")

if (int(ab[0])) & (int(ab[1])) & 1:
    print ("Odd")
else:
    print("Even")
n=input()
for i in range(0,n):
 a=input()
 b=input()
 s=str(a+b)
 if(len(s)<=80): print a+b
 else print "overflow"
 

### FIXED CODE ###

n=input()
for i in range(0,n):
 a=input()
 b=input()
 s=str(a+b)
 if(len(s)<=80): print a+b
 else: print "overflow"
import math
import copy
from functools import reduce
n = int(input())
a = list(map(int,input().split()))
ans = reduce(math.gcd,a)
if n==2 or (min(a)==max(a)):
    print(max(a))
else:
    for i in range(n):
        _a = copy.copy(a)
        _a.pop(i)
        tmp = reduce(math.gcd,_a)
        if tmp > ans:
            print(tmp)
            break
        else:
            if i != n-1:
                pass
            else:
                print(ans)

### FIXED CODE ###

#EOFERROR
# import math
# import copy
# from functools import reduce
# n = int(input())
# a = list(map(int,input().split()))
# ans = reduce(math.gcd,a)
# if n<=2 or (min(a)==max(a)):
#     print(max(a))
# else:
#     for i in range(n):
#         _a = copy.copy(a)
#         _a.pop(i)
#         tmp = reduce(math.gcd,_a)
#         if tmp > ans:
#             print(tmp)
#             break
#         else:
#             pass

def gcd(a,b):
    if b>a :
        a,b = b,a
    while b:
        a,b = b,a%b
    return a

def cul(n,x):
    l = len(x)
    b = [x[i] for i in range(l)]
    b.pop(n)
    tmp = b[0]
    for i in range(1,l-1):
        tmp = gcd(tmp,b[i])
    return tmp

import sys
p = 50
N = int(input())
if p>N : p=N
a = list(map(int,input().split()))

ans = 0

for i in range(p):
    s = cul(i,a[:p])
    if s>ans : ans=s

print(ans)
from collections import defaultdict, deque, Counter
import sys
import bisect
import heapq
import math

# input = sys.stdin.readline

sys.setrecursionlimit(1000000000)

MIN = -10 ** 9
MOD = 10 ** 9 + 7

ALPHA = "ABCDEFGHIJKLMNOPQRSTUVWXYZ"


def keta(n):
    if n < 10:
        return 1
    return math.floor(math.log10(n - 1)) + 1


def check(A, B, X, n):
    return A * n + B * keta(n) <= X


def p(tt, parent):
    children = tt[parent]
    for i in range(len(children)):
        if children[i][0] == parent:
            children.remove(children[i])
            break

    res = {parent: children}
    for c, ii in children:
        tt[c].remove((parent, ii))
        res = {**res, **p(tt, c)}
    return res


def main():
    N = int(input())
    ab = [[int(a) - 1 for a in input().split()] for _ in range(N - 1)]

    tt = defaultdict(list)

    for i, (a, b) in enumerate(ab):
        aa = tt[a]
        aa.append((b, i))
        tt[a] = aa
        a, b = b, a
        aa = tt[a]
        aa.append((b, i))
        tt[a] = aa

    tree = p(tt, 0)
    # print(tree)

    colors = len(tree[0])
    for k, v in tree.items():
        if k == 0:
            continue
        colors = max(colors, len(v) + 1)

    print(colors)

    res = [None] * (N - 1)

    def solve(pos, parentcol):
        children = tt[pos]
        for iii, (c, i) in enumerate(children):
            res[i] = (parentcol + 1 + iii) % colors
            solve(c, res[i])

    solve(0, -1)

    for i in range(N - 1):
        print(res[i] + 1)


if __name__ == '__main__':
    main()


### FIXED CODE ###

from collections import defaultdict, deque, Counter
import sys
import bisect
import heapq
import math

# input = sys.stdin.readline

sys.setrecursionlimit(1000000000)

MIN = -10 ** 9
MOD = 10 ** 9 + 7

ALPHA = "ABCDEFGHIJKLMNOPQRSTUVWXYZ"


def keta(n):
    if n < 10:
        return 1
    return math.floor(math.log10(n - 1)) + 1


def check(A, B, X, n):
    return A * n + B * keta(n) <= X


def main():
    N = int(input())
    ab = [[int(a) - 1 for a in input().split()] for _ in range(N - 1)]

    tree = defaultdict(list)
    # res = {}

    for i, (a, b) in enumerate(ab):
        # aa = tt[a]
        # aa.append((b, i))
        # tt[a] = aa
        if a not in tree:
            tree[a] = []
        tree[a].append((b, i))

    # def p(tt, parent):
    #     children = tt[parent]
    #     res[parent]=children
    #     # res = {parent: children}
    #     for c, ii in children:
    #         p(tt, c)
    #     return res
    #
    #
    # tree = p(tt, 0)

    colors = len(tree[0])
    for k, v in tree.items():
        if k == 0:
            continue
        colors = max(colors, len(v) + 1)

    print(colors)

    res = [None] * (N - 1)

    def solve(pos, parentcol):
        children = tree[pos]
        for iii, (c, i) in enumerate(children):
            res[i] = (parentcol + 1 + iii) % colors
            solve(c, res[i])

    solve(0, -1)

    for i in range(N - 1):
        print(res[i] + 1)


if __name__ == '__main__':
    main()
import math
from functools import reduce

def gcd(numbers):
    return reduce(math.gcd, numbers)

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

ans = []
ans.append(gcd(a[1:]))
ans.append(gcd(a[:n]))

for i in range(1, n-1):
    aaaa = []
    aaaa.append(gcd(a[:i]))
    aaaa.append(gcd(a[i+1:]))
    ans.append(gcd(aaaa))

print(max(ans))


### FIXED CODE ###

from math import gcd

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

L = [0] * N
L[0] = A[0]

#配列の左から順番に最大公約数を求める
for i, a in enumerate(A):
    L[i] = gcd(L[max(0, i-1)], a)

# print("L", L)
R = [0] * N
R[0] = A[-1]

#配列の右から順番に最大公約数を求める
for i, a in enumerate(A[::-1]):
    R[i] = gcd(R[max(0, i-1)], a)

# print("R", R)
ans = 0

for i in range(N):
    #一番左の数字を削除
    if i == 0:
        ans = max(ans, R[N-2])
    #一番右の数字を削除
    elif i == N-1:
        ans = max(ans, L[N-2])
    #i+1番目の数字を削除
    else:
        ans = max(ans, gcd(L[i-1], R[N-i-2]))
    
print(ans)
N = int,input()
sum = 0

#文字になるときpass
for i in range(N):
    if i % 3 == 0:
        pass
    elif i % 5 == 0:
        pass
    elif i % 15 == 0 :
        pass
    else:
         sum +=  i

print(sum)


### FIXED CODE ###

n = int(input())
sum = 0
 
for i in range(n+1):
    if i % 3 == 0:
        pass
    elif i % 5 == 0:
        pass
    elif i % 15 == 0:
        pass
    else:
     sum += i
 
print (sum)
s = input()

mod = [1] + [0]*2018
t = 0
a = 0
n = len(s)
s = reversed(s)
for i in range(n):
    t += int(s[i]) * (10 ** a)
    a += 1
    mod[t%2019] += 1
    print(t,t%2019)
ans = 0
for i in range(2019):
    ans += mod[i]*(mod[i]-1)//2
print(ans)

### FIXED CODE ###

s = input()
#s = '9' * 200000

mod = [1] + [0]*2018
t = 0
a = 1
n = len(s)
s = s[::-1]
for i in range(n):
    t = (t + int(s[i])*a) % 2019
    a = a * 10 % 2019
    mod[t] += 1
ans = 0
for i in range(2019):
    ans += mod[i]*(mod[i]-1)//2
print(ans)
n, k = map(int, input().split())
ans = 0

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

nums.sort

for i in range(k):
  ans += pop.nums(0)
  
print(ans)

### FIXED CODE ###

n, k = map(int, input().split())
ans = 0

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

nums.sort(reverse=True)

for i in range(k):
  ans += nums.pop(0)
  
print(ans)
import numpy as np
n,l=int(input()),list(map(float,input().split()))
dp=np.full([n+1,n+1],0.0)
dp[0][0]=1.0
for i in range(1,n+1):
    for j in range(i+1):
        if j==0:
            dp[i][j]=dp[i-1][j]*(1.0-l[i-1])
        else:
            dp[i][j]=dp[i-1][j]*(1.0-l[i-1])+dp[i-1][j-1]*l[i-1]
print(sum(dp[n][(n+1)//2:]))


### FIXED CODE ###

n,l=int(input()),list(map(float,input().split()))
dp=[[0.0]*(n+1) for _ in range(n+1)]
dp[0][0]=1.0
for i in range(1,n+1):
    for j in range(i+1):
        if j==0:
            dp[i][j]=dp[i-1][j]*(1.0-l[i-1])
        else:
            dp[i][j]=dp[i-1][j]*(1.0-l[i-1])+dp[i-1][j-1]*l[i-1]
print(sum(dp[n][((n+1)//2):]))
n, m, x = map(int, input().split())
a=list(map(int,input().split()))

ans = 0

for i in x:
  if (i in a):
    ans = ans + 1

print(min(ans, m-ans))


### FIXED CODE ###

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

ans = 0

for i in a:
  if i < x:
    ans += 1

print(min(ans, m-ans))
from collections import deque

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

sum = 0
ans = 0
for i in range(n):
  deque.append(A[i])
  sum += A[i]
  if len(deque)==k:
    ans = max(ans, (sum+k)/2)
  sum -= deque.popleft()

print(ans)

### FIXED CODE ###

import sys
sys.setrecursionlimit(2147483647)
INF=float("inf")
MOD=10**9+7 # 998244353
input=lambda:sys.stdin.readline().rstrip()
from collections import deque
def resolve():
    n, k =map(int,input().split())
    Q = deque([])
    sum = 0
    ans = 0
    for a in map(int,input().split()):
        Q.append(a)
        sum += a
        if(len(Q)==k):
            ans = max(ans, (sum+k)/2)
            sum -= Q.popleft()

    print(ans)
resolve()
n = int(input())
*a, = map(int, input().split())
a.sort()

if n % 2:
    for k in range(n):
        if a[k] != (k+1)//2*2:
        print(0)
        break
    else:
         print(2**((n-1)//2) % (10**9+7))
else:
    for k in range(n):
        if a[k] != k//2*2+1:
        print(0)
        break
    else:
        print(2**(n//2) % (10**9+7))


### FIXED CODE ###

n = int(input())
*a, = map(int, input().split())
a.sort()

if n % 2:
    for k in range(n):
        if a[k] != (k+1)//2*2:
            print(0)
            break
    else:
         print(2**((n-1)//2) % (10**9+7))
else:
    for k in range(n):
        if a[k] != k//2*2+1:
            print(0)
            break
    else:
        print(2**(n//2) % (10**9+7))
a,b=map(int,input.split())
print(a-b+1)

### FIXED CODE ###

N,i=map(int,input().split())
print(N+1-i)
n, m = map(int, input().split())
adj = [[] for _ in range(m)]
for i in range(m):
    a, b = map(int, input().split())
    a, b = a-1, b-1
    adj[a].append(b)
    adj[b].append(a)
# print(adj)
from collections import deque
q = deque([0])
dist = [-1]*n
ans = [0]*n

while q:
    now = q.popleft()
    for to in adj[now]:
        if dist[to] != -1: continue
        ans[to] = now 
        dist[to] = dist[now] + 1
        q.append(to)
    # print(adj[now], dist, ans, q)
    
print('Yes')
for i in range(1,n):
    print(ans[i]+1)


### FIXED CODE ###

n, m = map(int ,input().split())
 
adj = [[] for _ in range(n)]
 
for i in range(m):
    a, b = map(int, input().split())
    a-=1
    b-=1
    adj[a].append(b)
    adj[b].append(a)
 
from collections import deque
q = deque()
 
dist = [-1] * n
ans = [0] * n
 
q.append(0)
while len(q) != 0:
    now = q.popleft()
    for to in adj[now]:
        if dist[to] != -1:continue
        dist[to] = dist[now] + 1
        q.append(to)
        ans[to] = now
 
print("Yes")
for i in range(1, n):
    print(ans[i] + 1)
x, y = map(int, input().split())

answer = "No"

for i in range(x + 1):
  y = x - i
  if a * 2 + b * 4 == y:
    answer = "Yes"

print(answer)

### FIXED CODE ###

animals_num, legs_num = map(int, input().split())

answer = "No"

for i in range(animals_num + 1):
  j = animals_num - i
  if j * 4 + i * 2 == legs_num:
    answer = "Yes"
print(answer)
def mod(x):
  if x % 10 == 0:
    return x
  else:
    while True:
      x += 1
      if x % 10 == 0:
        break
    return x
      
A = int(input())
B = int(input())
C = int(input())
D = int(input())
E = int(input())
M = min(A%10, B%10, C%10, D%10, E%10)

if M = A%10:
  ans = A + mod(B) + mod(C) + mod(D) + mod(E)
elif M = B%10:
  ans = mod(A) + B + mod(C) + mod(D) + mod(E)
elif M = C%10:
  ans = mod(A) + mod(B) + C + mod(D) + mod(E)
elif M = D%10:
  ans = mod(A) + mod(B) + mod(C) + D + mod(E)
else:
  ans = mod(A) + mod(B) + mod(C) + mode(D) + E

### FIXED CODE ###

L = []
x = []
for _ in range(5):
    l = int(input())
    L.append(l)
    x.append((10-(l%10))%10)

ans = 0
for i in range(len(L)):
    ans += L[i]+x[i]

ans = ans - max(x)
print(ans)
import sys
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines

N,M = map(int,input().split())
PS = (input().split() for _ in range(N))

ac = [False] * N
wa_cnt = [0] * N
penal = 0
for P,S in PS:
    p = int(P)-1
    if ac[p]:
        pass
    elif S == b'WA':
        wa_cnt[p] += 1
    else:
        ac[p] = True
        penal += wa_cnt[p]

ac = sum(ac)
print(ac, penal)

### FIXED CODE ###

import sys
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines

N,M = map(int,readline().split())
PS = (line.split() for line in readlines())

ac = [False] * N
wa_cnt = [0] * N
penal = 0
for P,S in PS:
    p = int(P)-1
    if ac[p]:
        pass
    elif S == b'WA':
        wa_cnt[p] += 1
    else:
        ac[p] = True
        penal += wa_cnt[p]

ac = sum(ac)
print(ac, penal)
import sys
def main():

    n=int(input())
    p=list(map(int,input().split()))
    s=1
    p=sorted(p)
    for i in p:
        s*=i
        if i==0:
            print(0)
            sys.exit()
        else s>=10**18+1:
            print(-1)
            sys.exit()
    print(s)

if __name__ == '__main__':
    main()


### FIXED CODE ###

import sys
def main():

    n=int(input())
    p=list(map(int,input().split()))
    s=1
    p=sorted(p)
    for i in p:
        s*=i
        if i==0:
            print(0)
            sys.exit()
        elif s>=10**18+1:
            print(-1)
            sys.exit()
    print(s)

if __name__ == '__main__':
    main()
def fct(n):
	v = 1
	for i in range(1, n+1):
		v = (v * i) % 1000000007
	return v
N, M = map(int, input().split())
ans = 0
if N == M:
	v = fct(N)
	ans = (v*v*2)%1000000007
elif abs(N-M) == 1:
	ans = (fct(N)*fct(M))%1000000007
print ans

### FIXED CODE ###

def fct(n):
	v = 1
	for i in range(1, n+1):
		v = (v * i) % 1000000007
	return v
N, M = map(int, input().split())
ans = 0
if N == M:
	v = fct(N)
	ans = (v*v*2)%1000000007
elif abs(N-M) == 1:
	ans = (fct(N)*fct(M))%1000000007
print(ans)
S = ipnut()
T = input()
 
if(S==T[:len(S)]):
  print("Yes")
else:
  print("No")

### FIXED CODE ###

S = input()
T = input()
 
if(S==T[:len(S)]):
  print("Yes")
else:
  print("No")
n = int(input())
a = sorted(list(map(int,input().split())))[::-1]
ans = 0
temp = a[0]
lim = 1
cnt = 1
nb = iter(set(a))
poy = next(nb)
nxt = next(nb)
for v in a[1:]:
  if lim==0:
    cnt = 2
    temp = nxt
    lim = cnt
    nxt = next(nb)
  ans += temp
  if temp==v:
    cnt += 1
    lim = cnt
  else:
    lim -= 1
print(ans)

### FIXED CODE ###

n = int(input())
a = sorted(list(map(int,input().split())))[::-1]
ans = 0
for i in range(1,n):
  ans += a[i//2]
print(ans)
N - int(input())
A = list(map(int,input().split()))
ans = 1
for i in A:
  ans*=i
if ans > 10**18:
  ans = -1
print(ans)

### FIXED CODE ###

def main():
  N = int(input())
  A = list(map(int,input().split()))
  if 0 in A:
    return 0
  ans = 1
  for i in A:
    ans*=i
    if ans > 10**18:
      return -1
  return ans
print(main())
import numpy as np
import functools
import math
import collections
import scipy
import fractions
import itertools
 
def solve():
    n, k = map(int, input().split())
    a = list(map(int, input().split()))
    now = 0
    hoge= []
    bit = 0
    piyo = 0
    huga = []
    while True:
        hoge.append(now)
        now = a[now]-1
        if now in hoge:
            huga = hoge[hoge.index(now):len(hoge)]
            piyo = hoge.index(now)
            bit = 1
            break
    ans = huga[(k-piyo)%len(huga)]
    print(ans+1)
    return 0
 
if __name__ == "__main__":
    solve()

### FIXED CODE ###

def main():
    N, K = map(int, input().split())
    A = [a-1 for a in map(int, input().split())]    # 0-indexed に変換
    B = [None]*N    # 何ステップ目に到達したかを記録。Noneなら未到達を表す
    now = 0         # 現在地
    step = 0        # ステップ数
    B[now] = 0      # 開始地点は、0ステップ目に到達済みとする
    while K:
        now = A[now]    # 現在地を更新 
        step += 1
        K -= 1
        if B[now] is not None:  # ループを検出したら...
            K %= (step - B[now])      # Kからループ長さを引けるだけ引く
        else:
            B[now] = step  # 到達したステップ数を記録
    print(now+1)    # 1-indexed に再変換
 
main()
import math
a = math.ceil(math.sqrt(s))
print(0, 0, a, 1, a**2-s, a)

### FIXED CODE ###

import math
from collections import Counter

s = int(input())

def primes(n) :
    ps = [2]
    for i in range(3, n+1) :
        for p in ps :
            if i%p == 0 :
                break
        else :
            ps.append(i)
    return ps

def factorint(n) :
    ps = primes(n)
    l = []
    while n != 1 :
        for p in ps :
            if n%p == 0 :
                n //= p
                l.append(p)
                break
    return Counter(l)

a = math.ceil(math.sqrt(s))
print(0, 0, a, 1, a**2-s, a)