Harryxun/stf_run huggingface dataset:
w, h, x, y = map(int, input().split())
m = 1 if x == w/2 and y == h/2 else m = 0
print(w*h/2, m)

### FIXED CODE ###

w, h, x, y = (int(i) for i in input().split())
s = (w * h) / 2
met = 1 if (x == w/2 and y == h/2) else 0
print(s, met)
N=input()
a
if N[0] =='S':
  a='Cloudy'
elif N[0] =='C':
  a='Rainy'
else:
  a='Sunny'

print(a)
  


### FIXED CODE ###

N=input()
a=''
if N[0] =='S':
  a='Cloudy'
elif N[0] =='C':
  a='Rainy'
else:
  a='Sunny'

print(a)
return "ACL" * int(input())

### FIXED CODE ###

print("ACL" * int(input()))
import sys
input = sys.stdin.readline

def Warshall_Floyd(d):
    #dist[i][j]:iからjへの最短距離
    for k in range(n):
        for i in range(n):
            for j in range(n):
                d[i][j] = min(d[i][j], d[i][k]+d[k][j])
    return d
n, m, l = map(int, input().split())

f_inf = float('inf')
dist = [[f_inf]*n for _ in range(n)]
for i in range(m): dist[i][i] = 0

for _ in range(m):
    a, b, c = map(int, input().split())
    dist[a-1][b-1] = min(dist[a-1][b-1], c)
    dist[b-1][a-1] = min(dist[b-1][a-1], c)

dist = Warshall_Floyd(dist)

dist2 = [[f_inf]*n for _ in range(n)]
for i in range(m): dist2[i][i] = 0
for i in range(n):
    for j in range(n):
        if dist[i][j] <= l:
            dist2[i][j] = 1

dist2 = Warshall_Floyd(dist2)

q = int(input())
for _ in range(q):
    s, t = map(int, input().split())
    ans = dist2[s-1][t-1]-1
    if dist2[s-1][t-1] == f_inf:
      ans = -1
    print(ans)

### FIXED CODE ###

import sys
input = sys.stdin.readline

def main():
    N, M, L = map(int, input().split())
    dist = [[float('inf')] * N for _ in range(N)]
    for _ in range(M):
        A, B, C = map(int, input().split())
        if C > L:
            continue
        A -= 1
        B -= 1
        dist[A][B] = C
        dist[B][A] = C

    for k in range(N):
        for i in range(N):
            for j in range(N):
                dist[i][j] = min(dist[i][j], dist[i][k] + dist[k][j])

    e = [[float('inf')] * N for _ in range(N)]
    for i in range(N):
        for j in range(N):
            if dist[i][j] <= L:
                e[i][j] = 1
    
    for k in range(N):
        for i in range(N):
            for j in range(N):
                e[i][j] = min(e[i][j], e[i][k] + e[k][j])


    Q = int(input())
    for _ in range(Q):
        s, t = map(int, input().split())
        s -= 1
        t -= 1
        if e[s][t] == float('inf'):
            print(-1)
            continue
        ans = e[s][t]
        print(ans-1)


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

opes = [0] * (K)
for i in range(2**N):
    blue_cnt = 0
    ope_count = 0
    operating = False
    for j in range(N+1):
        bin2str = str(bin(i))
        if blue_cnt > K:
            break
        if operating and str[j+2:j+4:] == 0:
            operating = False
            ope_count += 1
        elif !operating and str[j+2:j+4:] == 1:
            operating = True
            blue_cnt += 1
        elif str[j+2:j+4:] == 1:
            blue_cnt += 1
    if blue_cnt == K:
        opes[ope_count] += 1
for i in opes:
    print(i)

### FIXED CODE ###

import sys
sys.setrecursionlimit(10000)

nCr = {}
def combination(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)] = combination(n-1,r) + combination(n-1,r-1)
    return nCr[(n,r)]

N, K = map(int, input().split())
for i in range(1, K+1):
	if i <= N-K+1:
		A = combination(N-K+1, i)
		P = combination(K-1, i-1)
		B = A * P
		print(B % (10**9+7))
	else:
		print(0)
n=int(input())
a=[]
for _ in range(n):
    a.append(list(map(int,input().split()))) 
dp=[0]*n
for i in range(3):
  dp[i]=a[0][i]
for k in range(1,n):
    m=[0,0,0]
    for i in range(3):
        for j in range(3):
            if i!=j:
                m[i]=max(m[i],dp[j]+a[k][i])
    dp=m
print(max(m))


### FIXED CODE ###

n=int(input())
a=[]
for _ in range(n):
    a.append(list(map(int,input().split())))
for i in range(1,n):
    a[i][0]+=max(a[i-1][1],a[i-1][2])
    a[i][1]+=max(a[i-1][0],a[i-1][2])
    a[i][2]+=max(a[i-1][1],a[i-1][0])
print(max(a[n-1]))
def gcd(a, b):
	while b:
		a, b = b, a % b
	return a

def gcd_list(li):
	if len(li) > 2:
		x = gcd(li[-1], li[-2])
		li = li[:-2] + [x]
		return gcd_list(li)
	else:
		return gcd(li[0], li[1])

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

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

li = [abs(i - X) for i in x]

li = [i for i in li if i]

if len(li) == 1:
	print(li[0])
else:
	print(gcd_list(li))


### FIXED CODE ###

import sys
sys.setrecursionlimit(500000)

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

	if b:
		return gcd(b, a % b)
	else:
		return a

def gcd_list(li):
	if len(li) > 2:
		x = gcd(li[-1], li[-2])
		li = li[:-2] + [x]
		return gcd_list(li)
	else:
		return gcd(li[0], li[1])

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

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

li = [abs(i - X) for i in x]

# li = [i for i in li if i]
# li = sorted(li)
if len(li) == 1:
	print(li[0])
else:
	ans = li[0]
	for i in range(1,N):
		ans = gcd(ans, li[i])
	print(ans)
n,a,b,c,d=map(int,input().split())
s=input()
if s[:max(c,d)].count("##")>0:
    print("No")
elif c<d:
    print("Yes")
else:
    if s[b-1:d+1].count("...")=0:
        print("No")
    else:
        print("Yes")


### FIXED CODE ###

n,a,b,c,d=map(int,input().split())
s=input()
if s[a-1:max(c,d)].count("##")>0:
    print("No")
elif c<d:
    print("Yes")
else:
    if "..." in s[b-2:d+1]:
        print("Yes")
    else:
        print("No")
c=input()
print(chr(ord(c)+1))

### FIXED CODE ###

n,k=map(int,input().split())
h=list(map(int,input().split()))
dp=[0] + [float('inf')]*(n-1)
for i in range(n):
    for j in range(max(0,i-k),i):
        dp[i]=min(dp[i],dp[j]+abs(h[i]-h[j]))
print(dp[-1])
from collections import deque
n,m = map(int,input().split())

turo = [[] for i in range(n)]
q = deque()
his = []

def root(x):
    if par[x] == x:
        return x
    else:
        return root(par[x])

for i in range(m):
    a,b = map(int,input().split())
    turo[a-1].append(b-1)
    turo[b-1].append(a-1)

par = [i for i in range(n)]
q.append(0)
his.append(0)

while len(q) > 0:
    #print(q)
    room = q.popleft()
    #print(room+1)
    for room2 in turo[room]:
        if room2 not in his:
            his.append(room2)
            q.append(room2)
            par[room2] = room

#print(turo,par)
for i in range(1,n):
    if (root(i) != 0):
        print("No")
        exit()
 
print("Yes")
for i in range(1,n):
    print(par[i]+1)

### FIXED CODE ###

from collections import deque
import sys
n,m = map(int,input().split())
 
turo = [[] for i in range(n)]
q = deque()
his = [False]*n
for i in range(m):
    a,b = map(int,input().split())
    turo[a-1].append(b-1)
    turo[b-1].append(a-1)
 
par = [i for i in range(n)]
rank = [sys.maxsize for i in range(n)]
rank[0] = 0
q.append(0)
 
while len(q) > 0:
    #print(q)
    room = q.popleft()
    
    if not his[room] :
        his[room] = True
    else:
        continue
    for room2 in turo[room]:
        if rank[room] < rank[room2]:
            q.append(room2)
            par[room2] = room
            rank[room2] = rank[room]+1
 
if len(his) < n:
    print("No")
    exit()
 
print("Yes")
for i in range(1,n):
    print(par[i]+1)
N = int(input())
P = list(map(int(),input().split()))
cnt = 0
for i in range(N):
    if P[i]!=i+1:
        cnt+=1
if cnt<=2:
    print("YES")
else:
    print("NO")

### FIXED CODE ###

N = int(input())
P = list(map(int,input().split()))
cnt = 0
for i in range(N):
    if P[i]!=i+1:
        cnt+=1
if cnt<=2:
    print("YES")
else:
    print("NO")
print("Yes" if s[2]==s[3] and s[4] == s[5] else "No")

### FIXED CODE ###

s = input()
print("Yes" if s[2]==s[3] and s[4] == s[5] else "No")
A,B = int(input().split())
if A <= 5:
  price = B
elif A >=6 and A <= 12:
  price = B/2
else:
  price = B
print(price)


### FIXED CODE ###

A,B = map(int,input().split())
if A <= 5:
  price = 0
elif A >=6 and A <= 12:
  price = B/2
else:
  price = B
print(int(price))
x,y,_=map(int(input().split()))
print(x*y//2)

### FIXED CODE ###

x,y,_=map(int,input().split())
print(x*y//2)
n, k = map(int, input().split())

if n%k!=0:
	print(0)
else:
	pritn(1)

### FIXED CODE ###

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

if n%k!=0:
	print(1)
else:
	print(0)
INFTY = 10**3
def paint0(i,j):
    global cnt
    if j+1<W and C[i][j+1]<0 and A[i][j+1]==0:
        C[i][j+1]=cnt
        paint0(i,j+1)
    if i-1>=0 and C[i-1][j]<0 and A[i-1][j]==0:
        C[i-1][j]=cnt
        paint0(i-1,j)
    if j-1>=0 and C[i][j-1]<0 and A[i][j-1]==0:
        C[i][j-1]==cnt
        paint0(i,j-1)
    if i+1<H and C[i+1][j]<0 and A[i+1][j]==0:
        C[i+1][j]=cnt
        paint0(i+1,j)
def paint1(i,j):
    if j+1<W and A[i][j+1]==1:
        A[i][j+1]=0
        paint1(i,j+1)
    if i-1>=0 and A[i-1][j]==1:
        A[i-1][j]=0
        paint1(i-1,j)
    if j-1>=0 and A[i][j-1]==1:
        A[i][j-1]=0
        paint1(i,j-1)
    if i+1<H and A[i+1][j]==1:
        A[i+1][j]=0
        paint1(i+1,j)
def paint2(i,j):
    global ind
    if j+1<W and A[i][j+1]==1 and C[i][j+1]<0:
        C[i][j+1]=ind
        paint2(i,j+1)
    elif j+1<W and A[i][j+1]==0 and dist[C[i][j+1]]>=INFTY:
        dist[C[i][j+1]] = dist[ind]+1
    if i-1>=0 and A[i-1][j]==1 and C[i-1][j]<0:
        C[i-1][j]=ind
        paint2(i-1,j)
    elif i-1>=0 and A[i-1][j]==0 and dist[C[i-1][j]]>=INFTY:
        dist[C[i-1][j]]=dist[ind]+1
    if j-1>=0 and A[i][j-1]==1 and C[i][j-1]<0:
        C[i][j-1]=ind
        paint2(i,j-1)
    elif j-1>=0 and A[i][j-1]==0 and dist[C[i][j-1]]>=INFTY:
        dist[C[i][j-1]]=dist[ind]+1
    if i+1<H and A[i+1][j]==1 and C[i+1][j]<0:
        C[i+1][j]=ind
        paint2(i+1,j)
    elif i+1<H and A[i+1][j]==0 and dist[C[i+1][j]]>=INFTY:
        dist[C[i+1][j]]=dist[ind]+1
    
H,W = map(int,input().split())
S = [input() for _ in range(H)]
A = [[0 for _ in range(W)] for _ in range(H)]
for i in range(H):
    for j in range(W):
        if S[i][j]=="#":
            A[i][j] = 1
C = [[-1 for _ in range(W)] for _ in range(H)]
ans = 0
if A[0][0]==1:
    A[0][0]=0
    paint1(0,0)
    ans += 1
if A[H-1][W-1]==1:
    A[H-1][W-1]=0
    paint1(H-1,W-1)
    ans += 1
cnt = 0
for i in range(H):
    for j in range(W):
        if C[i][j]<0 and A[i][j]==0:
            C[i][j] = cnt
            paint0(i,j)
            cnt += 1
dist = [INFTY for _ in range(cnt)]
dist[0] = 0
for i in range(H):
    for j in range(W):
        if A[i][j]==0:
            ind = C[i][j]
            paint2(i,j)
x = C[H-1][W-1]
ans += dist[x]
print(ans)

### FIXED CODE ###

from collections import deque
H,W = map(int,input().split())
A = [input().strip() for _ in range(H)]
d = 0
if A[0][0]=="#":
    d += 1
que = deque([(0,0,d)])
hist = [[H*W for _ in range(W)] for _ in range(H)]
hist[0][0] = d
while que:
    i,j,d = que.popleft()
    if j+1<W and A[i][j+1]==A[i][j]:
        if hist[i][j+1]>d:
            hist[i][j+1] = d
            que.append((i,j+1,d))
    elif j+1<W and A[i][j+1]!=A[i][j]:
        if hist[i][j+1]>d+1:
            hist[i][j+1] = d+1
            que.append((i,j+1,d+1))
    if i+1<H and A[i+1][j]==A[i][j]:
        if hist[i+1][j]>d:
            hist[i+1][j] = d
            que.append((i+1,j,d))
    elif i+1<H and A[i+1][j]!=A[i][j]:
        if hist[i+1][j]>d+1:
            hist[i+1][j] = d+1
            que.append((i+1,j,d+1))
m = hist[H-1][W-1]
print((m+1)//2)
a=(int,input())
b=(int,input())
if a>b:
   print(a-1)
else:
   print(a)

### FIXED CODE ###

a,b=map(int,input().split())
if a>b:
   print(a-1)
else:
   print(a)
N=int(input())
H=list(map(int,input().split()))

def dp(x):
    if x==0:
        return 0
    elif x==1:
        return abs(H[1]-H[0])
    else:
        a=dp(x-1)+abs(H[x]-H[x-1])
        b=dp(x-2)+abs(H[x]-H[x-2])
        return min(a,b)

print(dp(N-1))

### FIXED CODE ###

import numpy as np

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

dp=np.empty(N,dtype=int)
dp[0]=0
dp[1]=abs(H[1]-H[0])

for i in range(2,N):
    a=dp[i-1]+abs(H[i]-H[i-1])
    b=dp[i-2]+abs(H[i]-H[i-2])
    dp[i]=min(a,b)

print(dp[N-1])
a=input()
b=int(input())
if a[:b]=='1'*b:print(1)
else:
  k=0
  while a[k]=='1':k+=1
  print(a[k])

### FIXED CODE ###

a=input()
b=int(input())
if b<101:
  if a[:b]=='1'*b:print(1)
  else:
    k=0
    while a[k]=='1':k+=1
    print(a[k])
else:
  k=0
  while a[k]=='1':k+=1
  print(a[k])
# -*- coding: utf-8 -*-

def conbination(n, r):
    return f[n] // f[r]*f[n-r]

f = [1]
for i in (1, 2001):
    f.append(int(f[i-1]*i))

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

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


### FIXED CODE ###

# -*- coding: utf-8 -*-

def conbination(n, r):
    return f[n] // (f[r] * f[n-r])

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

f = [1]
for i in range(1, N+1):
    f.append(int(f[i-1]*i))

for i in range(1, K+1):
    if i > N-K+1:
        print(0)
        continue
    c_blue = conbination(K-1, i-1)
    c_red = conbination(N-K+1, i)
    print((c_blue * c_red) % (10**9 + 7))
import math

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

if A==B:
    print(A)
else:
    ans = 0
    if A*2 <= B-1 and B > 4:
        n = int(math.log2(A))
        m = int(math.log2(B))

        if n <= 1:
            for i in range(A,4):
                ans = ans ^ i
            A=4
            n=2
            
        if 2**n != A:
            n += 1
            ans = A
            for i in range(A+1,2**n):
                ans = ans ^ i

        for i in range(2**m,B+1):
            ans = ans ^ i

    else:
        for i in range(A+1,B+1):
            ans = ans ^ i

    print(ans)


### FIXED CODE ###

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

if A == B:
    print(A)
elif B - A == 1:
    print(A^B)
else:
    ans = 0
    if A % 2 != 0:
        ans ^= A
        A += 1
    if B % 2 == 0:
        ans ^= B
        B -= 1
    ans ^= ((B-A+1)//2)%2

    print(ans)
N=int(input()) 
A=int(input()) 
B=int(input()) 
C=int(input()) 
D=int(input()) 
E=int(input())

x = [A,B,C,D,E] 
pace = min(x) 
y = int(N/pace)
if pace = 1:
    print(y+4)
else:
    print(y+5)

### FIXED CODE ###

N=int(input()) 
A=int(input()) 
B=int(input()) 
C=int(input()) 
D=int(input()) 
E=int(input())

x = [A,B,C,D,E] 
pace = min(x) 
y = int(N/pace)
if pace == 1:
    print(y+4)
else:
    print(y+5)
S = input()
if S == "Sunny":
  print("Cloudy")
else if S == "Rainy":
  print("Sunny")
else:
  print("Rainy")

### FIXED CODE ###

S = input()
if S == "Sunny":
    print("Cloudy")
elif S == "Cloudy":
    print("Rainy")
else:
    print("Sunny")
import math
x = int(input())
b = 0

while True:
    a = math.pow(x+pow(b, 5), 0.2)
    if a.is_integer():
        print(int(a), b)
        break
    a = math.pow(x+pow(-b, 5), 0.2)
    if a.is_integer():
        print(int(a), b)
        break
    b += 1


### FIXED CODE ###

import math
x = int(input())
b = 0

"""
def calc(b, b5):
    a = (x+b5)**0.2

    if a.real.is_integer():
        print(int(a), b)
        exit()

while True:
    b5 = b ** 5
    calc(b, b5)
    if x-b5 >= 0:
        calc(-b, -b5)
    b += 1
    """

for i in range(-120,120):
    for j in range(-120,120):
        if i**5 - j**5 == x:
            print(i, j)
            exit()
x,n=map(int,input().split())
a=set(map,int(input().split()))
print(min([i for i in range(102) if i not in a],key=lambda y:abs(x-y)))

### FIXED CODE ###

x, n = map(int, input().split())
a = set(map(int, input().split()))
print(min([i for i in range(102) if i not in a], key=lambda y:abs(x-y)))
from functools import lru_cache

def main():
    @lru_cache(maxsize=1000)
    def dfs(d,R,sx,sy):
        if d == R:
            return 0
        x = 0
        y = 0
        for i in range(H):
            for j in range(W):
                if A[i][j] == d + D:
                    x = i
                    y = j
                    break
            else:
                continue
            break
        
        res = abs(x - sx) + abs(y - sy) + dfs(d+D,R,x,y)

        return res
    
    H, W, D = map(int, input().split())
    A = [list(map(int, input().split())) for _ in range(H)]
    Q = int(input())

    for _ in range(Q):
        L, R = map(int, input().split())
        sx = 0
        sy = 0
        for i in range(H):
            for j in range(W):
                if A[i][j] == L:
                    sx = i
                    sy = j
                    break
            else:
                continue
            break
        print(dfs(L,R,sx,sy))

        
        
        

main()

### FIXED CODE ###

def main():
    H, W, D = map(int, input().split())
    field = [list(map(int, input().split())) for _ in range(H)]

    c = [0] * (H * W)
    for i in range(H):
        for j in range(W):
            c[field[i][j] - 1] = (i, j)
    
    d = [0] * (H * W)
    for l in range(H * W - D):
        i, j = c[l]
        x, y = c[l + D]
        d[l+D] = d[l] + abs(x - i) + abs(y - j)
    
    Q = int(input())
    for _ in range(Q):
        L, R = map(int, input().split())
        print(d[R-1]-d[L-1])


main()
N, X = map(int, input().split())
 
arr = [int(_) for _ in input().split(' ')]
arr.sort()
 
a = 1000000000000
 
 
for i in range(N-1):
    if abs(arr[i+1]-arr[i]) < a:
        a = abs(arr[i+1]-arr[i])
 
for j in range(N):
    if abs(arr[j] - X) < a:
        a = abs(arr[j] - X)

if X > arr[N] or X < arr[0]:
    a = 1
 
print(a)

### FIXED CODE ###

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

N, X = map(int, input().split())
x = [int(_) for _ in input().split(' ')]

dist = [abs(i - X) for i in x]

ans = dist[0]

for i in range(N-1):
    ans = gcd(ans, dist[i+1])

print(ans)
from collections import Counter

s=Counter(input())
b,s=max(s.values()),min(s.values())
kind = len(s.keys())
if kind==3:
    if b-s<=1: print("YES")
    else: print("NO")
elif kind==2:
    if b==2 and s==1: print("YES")
    else: print("NO")
else:
    if b==1: print("YES")
    else: print("NO")

### FIXED CODE ###

from collections import Counter

s=Counter(input())
b,m=max(s.values()),min(s.values())
kind = len(s.keys())
if kind==3:
    if b-m<=1: print("YES")
    else: print("NO")
elif kind==2:
    if b==1 and m==1: print("YES")
    else: print("NO")
else:
    if b==1: print("YES")
    else: print("NO")
n = int(input())
    if n >= 30:
      s = 'Yes'
    else:
      s = 'No'
    print(s)

### FIXED CODE ###

n = int(input())
if n >= 30:
  print('Yes')
else:
  print('No')
s1 = input()
l = input()
l1 = len(s1)
sa = set(s1)
la = set(l)
if la.issubset(sa):
    j,su = 0,0
    d,li = {},[]
    for i in range(27):
        d[i] = []
    for i in range(l1):
        d[ord(s1[i])-ord('a')].append(i+1)
    for i in range(l1):
        d[ord(s1[i])-ord('a')].append(0)
    #print(d)
    v1,v2 = 0,0
    for i in l:
        v1 = d[ord(i)-ord('a')][j]
        if v1==0:
            j=0
            v1 = d[ord(i)-ord('a')][j]
        if v1<v2:
            j=0
            su+=l1-v2+v1
        else:
            j+=1
            su+=v1-v2
        v2 = v1
    print(su)
else:
    print(-1)

### FIXED CODE ###

s = input()
l = input()
     
count = 0
ind = -1
if set(l).issubset(set(s)):
    for i in range(len(l)):
        ind = s.find(l[i], ind+1)
        if ind == -1:
            count += 1
            ind = s.find(l[i], ind+1)
    print(count*len(s) + ind+1)
 
else:
    print(-1)
class edge():
    def __init__(self,_to,_cost):
        self.to = _to;
        self.cost = _cost;

N = int(input())
tree = [[] for i in range(N)]

for i in range(N-1):
    a,b,c = list(map(int, input().split()))
    a = a - 1
    b = b - 1
    tree[a].append(edge(b,c))
    tree[b].append(edge(a,c))
Q, K = list(map(int, input().split()))
K = K - 1

depth = [0]*N
def DFS(v,p,d):
    depth[v] = d
    for e in tree[v]:
        if e.to==p :
            continue
        DFS(e.to, v, d + e.cost)
DFS(K,-1,0)

for q in range(Q):
    x,y = list(map(int, input().split()))
    x = x - 1
    y = y - 1
    print(depth[x] + depth[y])


### FIXED CODE ###

n = input()
s = []
for i in range(len(n)):
    s.append(n[len(n)-1-i])
if(n=="".join(s)):
    print("Yes")
else:
    print("No")
N=int(input())
x=N*800
if N>=15:
    y=200*(N%15)
ans=x-y
print(ans)


### FIXED CODE ###

N=int(input())
x=N*800
y=0
if N>=15:
    y=200*(N//15)
ans=x-y
print(ans)
import sys
import os
import math
import bisect
import collections
import itertools
import heapq

ii = lambda: int(sys.stdin.buffer.readline().rstrip())
il = lambda: list(map(int, sys.stdin.buffer.readline().split()))
fl = lambda: list(map(float, sys.stdin.buffer.readline().split()))
iln = lambda n: [int(sys.stdin.buffer.readline().rstrip()) for _ in range(n)]

iss = lambda: sys.stdin.buffer.readline().decode().rstrip()
sl = lambda: list(map(str, sys.stdin.buffer.readline().decode().split()))
isn = lambda n: [sys.stdin.buffer.readline().decode().rstrip() for _ in range(n)]

lcm = lambda x, y: x * y / math.gcd(x, y)

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


def main():
    if os.getenv("LOCAL"):
        sys.stdin = open("input.txt", "r")

    N, K = il()
    A = il()
    t = [0]*N
    tmp = 1
    cnt = 0
    for n in range(N):
        if tmp in t:
            break
        cnt += 1
        t[n] = tmp
        tmp = A[tmp - 1]
    else:
        print(t[cnt-1])
        exit()

    mod = (K - cnt) % (len(t)-cnt)
    print(t[len(t)-cnt+1:][mod])


if __name__ == '__main__':
    main()


### FIXED CODE ###

import sys
import os
import math
import bisect
import collections
import itertools
import heapq
import re
import queue
from decimal import Decimal

# import fractions

sys.setrecursionlimit(10000000)

ii = lambda: int(sys.stdin.buffer.readline().rstrip())
il = lambda: list(map(int, sys.stdin.buffer.readline().split()))
fl = lambda: list(map(float, sys.stdin.buffer.readline().split()))
iln = lambda n: [int(sys.stdin.buffer.readline().rstrip()) for _ in range(n)]

iss = lambda: sys.stdin.buffer.readline().decode().rstrip()
sl = lambda: list(map(str, sys.stdin.buffer.readline().decode().split()))
isn = lambda n: [sys.stdin.buffer.readline().decode().rstrip() for _ in range(n)]

lcm = lambda x, y: (x * y) // math.gcd(x, y)
# lcm = lambda x, y: (x * y) // fractions.gcd(x, y)

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


def main():
    if os.getenv("LOCAL"):
        sys.stdin = open("input.txt", "r")

    N, K = il()
    tel = [0] + il()

    # 初期位置
    position = 1

    # 移動回数がN回(町の数)以下の場合
    if K <= N:
        for k in range(K):
            position = tel[position]
        print(position)
        exit()

    # 移動回数がN回(町の数)以上の場合
    for n in range(N):
        position = tel[position]

    # 既にN回移動済みのため、
    # 必要な移動回数(K)から減算
    K -= N
    # ループまでに必要な移動回数を探索
    base = position
    cnt = 1
    while base != tel[position]:
        position = tel[position]
        cnt += 1

    # Kからループ数の余りを求め、
    # 余りの回数だけ移動を行う
    for k in range(K % cnt + 1):
        position = tel[position]
    print(position)


if __name__ == '__main__':
    main()
def counting_sort(target_list):
    counter = [0 for i in range(10000)]

    for n in target_list:
        counter[n] += 1

    for i in range(1,10000):
        counter[i] = counter[i] + counter[i-1]

    result = [0 for i in range(len(target_list))]
    for n in target_list[::-1]:
        result[counter[n] - 1] = n
        counter[n] -= 1
    
    return result
if __name__ == "__main__":
    n_list = int(input())
    target_list = [int(s) for s in input().split()]
    sorted_list = counting_sort(target_list)
    print(" ".join([int(s) for s in sorted_list]))

### FIXED CODE ###

#http://judge.u-aizu.ac.jp/onlinejudge/description.jsp?id=ALDS1_6_A&lang=jp
#?¨???°?????????

def counting_sort(target_list):
    counter = [0 for i in range(10000)]

    for n in target_list:
        counter[n] += 1

    for i in range(1,10000):
        counter[i] = counter[i] + counter[i-1]

    result = [0 for i in range(len(target_list))]
    for n in target_list[::-1]:
        result[counter[n] - 1] = n
        counter[n] -= 1
    
    return result
if __name__ == "__main__":
    n_list = int(input())
    target_list = [int(s) for s in input().split()]
    sorted_list = counting_sort(target_list)
    print(" ".join([str(s) for s in sorted_list]))
A=int(input("a"))
B=int(input("b"))

if A>=10 or B>=10:
    print(-1)
else:
    print(A*B)

### FIXED CODE ###

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

if A>=10 or B>=10:
    print(-1)
else:
    print(A*B)