Harryxun/stf_run huggingface dataset:
def face(x,y,dice):
    if (x==dice[5] and y==dice[4])or(x==dice[4] and y==dice[0])or(x==dice[0] and y==dice[1])or(x==dice[1] and y==dice[5]):
        return dice[2]
    elif (x==dice[0] and y==dice[2])or(x==dice[2] and y==dice[5])or(x==dice[5] and y==dice[3])or(x==dice[3] and y==dice[0]):
        return dice[4]
    elif (y==dice[5] and x==dice[4])or(y==dice[4] and x==dice[0])or(y==dice[0] and x==dice[1])or(y==dice[1] and x==dice[5]):
        return dice[3]
    elif (y==dice[0] and x==dice[2])or(y==dice[2] and x==dice[5])or(y==dice[5] and x==dice[3])or(y==dice[3] and x==dice[0]):
        return dice[1]
    elif (x==dice[2] and y==dice[1])or(x==dice[1] and y==dice[3])or(x==dice[3] and y==dice[4])or(x==dice[4] and y==dice[2]):
        return dice[5]
    else:
        return dice[0]
         
 
for i in range(n):
    a,b=map(int,raw_input().split())
    print face(a,b,l)


### FIXED CODE ###

class dice:

    def __init__(self, numlist):
        self._men = {"T": numlist[0],
                     "B": numlist[5],
                     "N": numlist[4],
                     "S": numlist[1],
                     "W": numlist[3],
                     "E": numlist[2]}

    def roll(self, direction):
        t = dict(self._men)

        if direction == "N":
            self._men["T"] = t["S"]
            self._men["B"] = t["N"]
            self._men["N"] = t["T"]
            self._men["S"] = t["B"]
        elif direction == "S":
            self._men["T"] = t["N"]
            self._men["B"] = t["S"]
            self._men["S"] = t["T"]
            self._men["N"] = t["B"]
        elif direction == "W":
            self._men["T"] = t["E"]
            self._men["B"] = t["W"]
            self._men["W"] = t["T"]
            self._men["E"] = t["B"]
        elif direction == "E":
            self._men["T"] = t["W"]
            self._men["B"] = t["E"]
            self._men["W"] = t["B"]
            self._men["E"] = t["T"]


    def settopsouth(self, top, south):
        if self._men["T"] == top:
            pass
        elif self._men["S"] == top:
            self.roll("N")
        elif self._men["N"] == top:
            self.roll("S")
        elif self._men["W"] == top:
            self.roll("E")
        elif self._men["E"] == top:
            self.roll("W")
        elif self._men["B"] == top:
            self.roll("N")
            self.roll("N")

        if self._men["S"] == south:
            return self._men["E"]
        elif self._men["E"] == south:
            return self._men["N"]
        elif self._men["N"] == south:
            return self._men["W"]
        elif self._men["W"] == south:
            return self._men["S"]


    def gettop(self):
        return self._men["T"]

def decode():
    numlist = [int(x) for x in input().split()]
    n = int(input())
    qs = []
    for _ in range(n):
        al = [int(x) for x in input().split()]
        qs.append(al)

    return numlist, n, qs


if __name__ == '__main__':

    numlist, n, qs = decode()
    d1 = dice(numlist)
    for q in qs:
        print(d1.settopsouth(*q))
def main():
    N = int(input())
    A = list(map(int, input().split()))
    A = sorted(A)
    A_M = sorted(A)
    A_M[0] *= -1
    start = 0
    if N == 2:
        print(max(A) - min(A))
        print('{} {}'.format(max(A), min(A)))
        return
    for i in range(1, N-1):
        if A_M[i] < 0:
            A_M[i] *= -1
            start = i
    M = sum(A_M)
    print(M)
    if start == 0:
        for i in range(1, N):
            if i < N-1:
                if i == 1:
                    x = A[0]
                    y = A[1]
                else:
                    x = tmp
                    y = A[i]
            else:
                x = A[-1]
                y = tmp
            tmp = x - y
            print('{} {}'.format(x, y))
    elif start == N - 2:
        for i in range(1, N):
            if i == 1:
                x = A[-1]
                y = A[start]
            else:
                x = tmp
                y = A[start-i+1]
            tmp = x - y
            print('{} {}'.format(x, y))
    else:
        for i in range(1, N):
            if i == 1:
                x = A[start]
                y = A[start+1]
            elif 1 < i < N - 1 - start:
                x = tmp
                y = A[start+i]
            elif i == N - 1 - start:
                x = A[-1]
                y = tmp
            else:
                x = tmp
                y = A[start-(i-N-1-start)]
            tmp = x - y
            print('{} {}'.format(x, y))
    return


if __name__ == '__main__':
    main()


### FIXED CODE ###

def main():
    N = int(input())
    A = list(map(int, input().split()))
    A = sorted(A)
    A_M = sorted(A)
    A_M[0] *= -1
    start = 0
    if N == 2:
        print(max(A) - min(A))
        print('{} {}'.format(max(A), min(A)))
        return
    for i in range(1, N-1):
        if A_M[i] < 0:
            A_M[i] *= -1
            start = i
    M = sum(A_M)
    print(M)
    if start == 0:
        for i in range(1, N):
            if i < N-1:
                if i == 1:
                    x = A[0]
                    y = A[1]
                else:
                    x = tmp
                    y = A[i]
            else:
                x = A[-1]
                y = tmp
            tmp = x - y
            print('{} {}'.format(x, y))
    elif start == N - 2:
        for i in range(1, N):
            if i == 1:
                x = A[-1]
                y = A[start]
            else:
                x = tmp
                y = A[start-i+1]
            tmp = x - y
            print('{} {}'.format(x, y))
    else:
        for i in range(1, N):
            if i == 1:
                x = A[start]
                y = A[start+1]
            elif 1 < i < N - 1 - start:
                x = tmp
                y = A[start+i]
            elif i == N - 1 - start:
                x = A[-1]
                y = tmp
            else:
                x = tmp
                y = A[start-(i-(N-1-start))]
            tmp = x - y
            print('{} {}'.format(x, y))
    return


if __name__ == '__main__':
    main()
import sys
N = 8
ptn = [18,48,6,30,20,34,16]
def f(D):
    i = 0
    s = 0
    D = D[D.index("1"):]
    for c in D:
        if c=="1": s += i
        i += 1
    p = "ABCDEF"[ptn.index(s)]
    return p
 
i=0
D=""
for s in sys.stdin:
    if i<8:
        D+=s[1:]
        i+=1
    else:
        print f(D)
        D=""
        i=0
print f(D)

### FIXED CODE ###

import sys
ptn = [18,48,6,30,20,34,16]

def f(D):
    i = 0
    s = 0
    D = D[D.index("1"):]
    for c in D:
        if c=="1": s += i
        i += 1
    p = "ABCDEFG"[ptn.index(s)]
    return p

i=0
D=""
for s in sys.stdin:
    if i<8:
        i+=1
        D+=s[:-1]
    else:
        print f(D)
        i=0
        D=""
print f(D)
N = int(input())
flag = 'False'
for i in range(0,N):
  c = input()
  if c == 'Y':
    flag = 'True'
if flag:
  print('Four')
else:
  print('Three')

### FIXED CODE ###

flag = 0
N = int(input())
c = input().split()
for i in range(0,N):
  if c[i] == 'Y':
    flag = 1
if flag:
  print('Four')
else:
  print('Three')
inp = list(map(int,input().split()))
if (inp[0]*inp[1])%2==1:
  print((inp[0]*inp[1])//2+1)
else:
  print((inp[0]*inp[1])//2)

### FIXED CODE ###

a=[1, 1, 1, 2, 1, 2, 1, 5, 2, 2, 1, 5, 1, 2, 1, 14, 1, 5, 1, 5, 2, 2, 1, 15, 2, 2, 5, 4, 1, 4, 1, 51]
print(a[int(input())-1])
a,b,c,x = [int(input()) for _ in range(4)]
print(sum(500*i+100*j+50*k==x for i in range(a+1)for j in range(b+1)for k in range(c+1)))

### FIXED CODE ###

num = int(input())
if num in [i*j for i in range(1,10) for j in range(1,10)]:
    print("Yes")
else:
    print("No")
n,k = map(int,input().split())
v = map(int,input().split())

ans = 0

for l in range(n):
    for r in range(n-l+1):
        if l+r >k:
            break
        nv = v[:l] + v[n-r:]
        nv.sort()
        for i in range(k-l-r):
            if not nv or nv[0] >= 0:
                break
            nv.pop(0)
        ans = max(ans,sum(nv))
print(ans)


### FIXED CODE ###

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

ans = 0

for l in range(n):
    for r in range(n-l+1):
        if l+r >k:
            break
        nv = v[:l] + v[n-r:]
        nv.sort()
        for i in range(k-l-r):
            if not nv or nv[0] >= 0:
                break
            nv.pop(0)
        ans = max(ans,sum(nv))
print(ans)
N,Y = map(int,input().split())
ans = '-1 -1 -1'
for i in range(2001):
    for j in range(2001):
        for k in range(2001):
            if 10000*i + 5000*j + 1000*k == Y and i+j+k == N:
                ans = str(i) + ' '+str(j) + ' '+ str(k)
                print(ans)
                sys.exit()
print(ans)

### FIXED CODE ###

import sys
N,Y = map(int,input().split())
ans = '-1 -1 -1'

for i in range(2001):
    for j in range(2001):
        if 10000*i + 5000*j + 1000*(N-i-j) == Y :
            if N-i-j >= 0:
                print(str(i) + ' '+str(j) + ' '+ str(N-i-j))
                sys.exit()
print(ans)
s = input()

flag = True
for i in range(len(s)-1):
  if s[i] == s[i+1]:
    print("Bad")
	flag = False

if flag:
  	print("Good")


### FIXED CODE ###

s = input()

flag = True
for i in range(len(s)-1):
  if s[i] == s[i+1]:
    print("Bad")
    flag = False
    break
if flag:
  print("Good")
import sys
input = lambda: sys.stdin.readline().rstrip()
from itertools import accumulate


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

S = input()

if len(S) == 1:
    print(1)
    exit()

cum_sum = [0]

tmp_S = S

if S[-1] == '0':
    tmp_S += '1'
else:
    tmp_S += '0'

cnt = 1
for i in range(len(tmp_S)-1):
    if tmp_S[i] == tmp_S[i+1]:
        cnt += 1
    else:
        cum_sum.append(cnt)
        cnt = 1

cum_sum = list(accumulate(cum_sum))

ans = 0
ran = K+K
if S[0] == '0':
    for i in range(0, len(cum_sum), 2):
        if i+ran < len(cum_sum):
            ans = max(ans, cum_sum[i+ran] - cum_sum[i])
else:
    for i in range(0, len(cum_sum), 2):
        if i+ran < len(cum_sum):
            ans = max(ans, cum_sum[i+ran+1] - cum_sum[i])

print(ans)

### FIXED CODE ###

import sys
input = lambda: sys.stdin.readline().rstrip()
from itertools import accumulate

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

S = input()


num = []

if S[0] == '0':
    num.append(0)

if S[-1] == '1':
    S += '0'
else:
    S += '1'    

cnt = 1
for i in range(len(S)-1):
    if S[i] == S[i+1]:
        cnt += 1
    else:
        num.append(cnt)
        cnt = 1 
if S[-2] == '0':
    num.append(0)

num = [0] + num
cum_sum = list(accumulate(num))

ans = 0

for i in range(0, len(cum_sum), 2):
    right = i + K * 2 + 1
    if i + K * 2 >= len(cum_sum): 
        right = len(cum_sum) - 1

    ans = max(ans, cum_sum[right] - cum_sum[i])
print(ans)
n=int(input())
a=list(map(int,input().split()))
a.sort()
minus=sum(a[0:n//2])
plus=sum(a)-minus
print(plus-minus)
if n%2==0:
 s=a[0]
 for i in range(1,n//2):
  print(a[n-i],s)
  s=a[n-i]-s
  print(a[i],s)
  s=a[i]-s
 print(a[n//2],s)
else:
 s=a[n-1]
 for i in range(n//2):
  print(a[i],s)
  s=a[i]-s
  print(a[n-(i+2)],s)
  s=a[n-(i+2)]-s

### FIXED CODE ###

n,k=map(int,input().split())
if k==1:
 print(0)
else:
 print(n-k)
解答例
R = int(input())

if R < 1200:
	print("ABC")
elif R < 2800:
	print("ARC")
else:
	print("AGC")


### FIXED CODE ###

R = int(input())

if R < 1200:
	print("ABC")
elif R < 2800:
	print("ARC")
else:
	print("AGC")
n=int(input())
ans=0
for i in range(n):
    x,u=map(int,input().split())
    if u == 'BTC':
        x=x*380000.
    ans+=x
print(ans)

### FIXED CODE ###

n=int(input())
ans=0
for i in range(n):
    x,u=input().split()
    x=float(x)
    
    if u == 'BTC':
        x=x*380000.
    ans+=x
print(ans)
import sys
input = sys.stdin.readline
 
h,w,m = list(map(int,input().split()))

R = [0]*h
C = [0]*w
G = [[0]*w for _ in range(h)]

for _ in range(m):
  a,b = list(map(int,input().split()))
  a,b = a-1, b-1
  R[a] += 1
  C[b] += 1
  G[a][b] = 1
  
best = 0
for i in range(h):
  for j in range(w):
    best = max(best,R[i]+C[j] - G[i][j])
    
print(best)

### FIXED CODE ###

import sys
input = sys.stdin.readline
 
h,w,m = list(map(int,input().split()))

R = [0]*h
C = [0]*w
G = {}

for _ in range(m):
  a,b = list(map(int,input().split()))
  a,b = a-1, b-1
  R[a] += 1
  C[b] += 1
  G[(a,b)] = 1
  
hhh = max(R)
ccc = max(C)
hei,wei = [],[]

for i in range(h):
  if R[i]==hhh:
    hei.append(i)
    
for i in range(w):
  if C[i]==ccc:
    wei.append(i)
  
  
best = 0
for i in hei:
  for j in wei:
    cor = 0
    if (i,j) in G:
      cor = 1
    best = max(best,R[i]+C[j] - cor)
    if cor==0:
      break
  if cor==0:
      break
      
print(best)
N=int(input())
if N < 1000 :
  print(f"ABC{N}")
else :
  n = N - 999
  print(f"ABD{n})

### FIXED CODE ###

N=int(input())
if N <= 999 :
  print("ABC")
else :
  print("ABD")
import math

r = input()

s = math.pi * (r ** 2)

p = 2 * math.pi * r

print(s,p)


### FIXED CODE ###

from math import pi

r = float(input())

s = pi * (r ** 2)

p = 2 * pi * r

print(s,p)
N, M = map(int, input().split()) 
ans = []
if M % 2 != 0:
    for i in range((M+1)//2):
        ans.append((1 + i,M - i))
        
    for j in range((M - 1)//2):
        ans.append((M + 1 + j, 2*M + 1 - j))
else:
    for i in range(M//2):
        ans.append((1 + i, M + 1 - i))
        ans.append((M + 2 + j, 2*M + 1 - j))
              
for i in range(M):
    print(*ans[i])

### FIXED CODE ###

K = int(input()) 
A, B = map(int, input().split())
import math
n = math.floor(B / K) 
if n >= A / K:
    print('OK')
else:
    print('NG')
n, p = map(int, raw_input().split())
fac = {}
primes = [1]*(10**6 + 200)
i = 2
prim = []
while i <= 10**6 + 100:
    if primes[i]:
        prim.append(i)
        j = i*2
        while j <= 10**6 + 100:
            primes[j] = 0
            j += i 
    i += 1 
for i in prim:
    while p%i == 0:
        p /= i 
        fac[i] = fac[i] + 1 if i in fac else 1
if p > 1:
    fac[p] = 1
ans = 1
for i in fac:
    if fac[i] >= n:
        ans *= i**(fac[i]/n)
print ans

### FIXED CODE ###

print raw_input().count('2')
#encoding:utf-8

d=int(input())

n=int(input())

r=(100**d)*n

print(r)


### FIXED CODE ###

# encoding:utf-8

import copy
import numpy as np
import random

#n==100の時のコーナーケースに手間取った

d,n = map(int, input().split())
if n == 100:
    print(100**d*101)
    exit()
else:
    print(100**d*n)
def transport(n,a,b,c,d,e):
    s = [a,b,c,d,e]
    x = min(s)
    return 5+int(1/x*(n-1))
n = int(input())
a = int(input())
b = int(input())
c = int(input())
d = int(input())
e = int(input())
print(transport(n,a,b,c,d,e))  

### FIXED CODE ###

import sys
input = sys.stdin.readline
 
x, y, z, k = map(int, input().split())
a = sorted(int(i) for i in input().split())
b = sorted(int(i) for i in input().split())
c = sorted(int(i) for i in input().split())
 
#a.sort(reverse=True)
#b.sort(reverse=True)
#c.sort(reverse=True)
 
ab = sorted(i+j for i in a for j in b)[:-k-1:-1]
abc = sorted(i+j for i in ab for j in c)[:-k-1:-1]
 
print(*abc[:k], sep="\n")
import sys
input = sys.stdin.readline
N,M = map(int,input().split())
lst=[int(input()) for i in range(M)]
t=0
ans=[0]*(N+1)
ans[0]=1
for j in range(N):
 if lst[t]==j+1:
  ans[j+1]=0
  t+=1
  t=min(M-1,t)
 else:
  ans[j+1]+=ans[j]
  if j!=0:
   ans[j+1]+=ans[j-1]
  ans[j+1]%=(10**9+7)
print(ans[N])

### FIXED CODE ###

import sys
input = sys.stdin.readline
N,M = map(int,input().split())
lst=[int(input()) for i in range(M)]
t=0
ans=[0]*(N+1)
ans[0]=1
for j in range(N):
 if M!=0:
  if lst[t]==j+1:
   ans[j+1]=0
   t+=1
   t=min(M-1,t)
  else:
   ans[j+1]+=ans[j]
   if j!=0:
    ans[j+1]+=ans[j-1]
   ans[j+1]%=(10**9+7)
 else:
  ans[j+1]+=ans[j]
  if j!=0:
   ans[j+1]+=ans[j-1]
  ans[j+1]%=(10**9+7)
print(ans[N])
def binexp(b):
  res = 1
  while b>0:
    if b&1:
      res *= a
      res%=mod
    a *= a
    a%=mod
    b>>=1
  return res
mod = 1000000007
n = int(input())
if n==1:
  print(0)
elif n==2:
  print(1)
else:
  count = 1
  n -= 2
  ans = binexp(n)
  print(ans)

### FIXED CODE ###

def binexp(a,b):
  res = 1
  while b>0:
    if b&1:
      res *= a
      res%=mod
    a *= a
    a%=mod
    b>>=1
  return res
mod = 1000000007
n = int(input())
if n==1:
  print(0)
elif n==2:
  print(2)
else:
  ans = binexp(10,n)
  ans1 = binexp(9,n)
  ans2 = binexp(8,n)
  print((ans-2*ans1+ans2)%mod)
from sys import stdin
N = int(stdin.readline().rstrip())
data = [int(x) for x in stdin.readline().rstrip().split()]
flag = True
if len(set(data)) != 3:
    flag = False
syugo = list(set(data))
if syugo[0]^syugo[1] != syugo[2]:
    flag = False

if flag:
    print("Yes")
else:
    print("No")

### FIXED CODE ###

from sys import stdin
N = int(stdin.readline().rstrip())
data = [int(x) for x in stdin.readline().rstrip().split()]
flag = True
syugo = set(sorted(data))
if len(syugo) == 1:
    syugo = list(syugo)
    if syugo[0] != 0:
        flag = False

elif len(syugo) == 2:
    syugo = list(syugo)
    if syugo[0] != 0:
        flag = False
    if data.count(syugo[1]) != data.count(0)*2:
        flag = False
        
elif len(set(data)) == 3:
    syugo = list(syugo)
    if syugo[0]^syugo[1] != syugo[2]:
        flag = False
    if len(set([data.count(i) for i in syugo])) != 1:
        flag = False
else:
    flag = False

if flag:
    print("Yes")
else:
    print("No")
from scipy.special import comb
import math
N=int(import())

a = comb(N, 3, exact=True)
if N%2==0:
  ans=a/2-1
else:
  ans=a/2
  ans = math.floor(ans)
print(ans)

### FIXED CODE ###

N=int(input())
if N==1 or N==2:
  ans=0
elif N%2==0:
  ans=(N/2)-1
else:
  ans=N//2  
print(int(ans))
n,m,k = map(int,input().split())
nlist = list(map(int,input().split()))
mlist = list(map(int,input().split()))
result = 0

# mlistが読める残り時間。ncount(nが読める冊数)が増えるたびに減少していく
mrest = k

# mlistが読める冊数。最初はの最大冊数だが、ncount(nが読める冊数)が増えるたびに減少していく
mcount = m

# mcount分読むのにかかる時間。最初は最大冊数分持っているか、mcountが減るたびに減少していく
mtime = sum(mlist)

# ncount(nが読める冊数)を1ずつ増やしていく
for ncount in range(0, len(nlist) + 1):
  # mlistが読める残り時間も冊数もあれば、mlistから本を取っていく
  # もしmlistが読める残り時間が最大時間を超えていたら後ろから諦めていく
  while mrest > 0 and mcount > 0 and mtime > mrest:
    mcount -= 1
    mtime -= mlist[mcount]
  # このループで読める冊数はncount+mcount。ループごとの最大値が応え
  result = max(result, ncount + mcount)
  # ncountから1冊読んだので、mrestをその時間分減らす
  mrest -= nlist[ncount]
  # これでmlistを読む時間が無くなってしまったら処理を終了する
  if mrest <= 0:
    break
print(result)


### FIXED CODE ###

n,m,k = map(int,input().split())
nlist = list(map(int,input().split()))
mlist = list(map(int,input().split()))
result = 0

# mlistが読める残り時間。ncount(nが読める冊数)が増えるたびに減少していく
mrest = k

# mlistが読める冊数。最初はの最大冊数だが、ncount(nが読める冊数)が増えるたびに減少していく
mcount = m

# mcount分読むのにかかる時間。最初は最大冊数分持っているか、mcountが減るたびに減少していく
mtime = sum(mlist)

# ncount分読むのにかかる時間。ncountが増えるたびに増加していく
ntime = 0

# ncount(nが読める冊数)を1ずつ増やしていく
for ncount in range(len(nlist) + 1):
  # ncountが1以上の場合は、1冊読んだので、mrestをその時間分減らす
  if ncount > 0:
    mrest -= nlist[ncount - 1]
    ntime += nlist[ncount - 1]
  # もしntimeが最大時間を超えてしまったら終了する
  if ntime > k:
    break;
  # mlistが読める残り時間も冊数もあれば、mlistから本を取っていく
  # もしmlistが読める残り時間が最大時間を超えていたら後ろから諦めていく
  while mcount > 0 and mtime > mrest:
    mcount -= 1
    mtime -= mlist[mcount]
  # このループで読める冊数はncount+mcount。ループごとの最大値が答え
  result = max(result, ncount + mcount)
  # nlistの本を全部読み終わっていたら処理を終了する
  if ncount == n:
    break;
print(result)
keys = input.split()
values = tuple(map(int, input().split()))

ball = dict(zip(keys, values))
u = input()

ball[u] -= 1
print(ball[keys[0]], ball[keys[1]])


### FIXED CODE ###

keys = input().split()
values = tuple(map(int, input().split()))

ball = dict(zip(keys, values))
u = input()

ball[u] -= 1
print(ball[keys[0]], ball[keys[1]])
P = int(input())
Q = int(input())
R = int(input())

if P < Q < R:
	t1 = P
    t2 = Q
elif P < R < Q:
    t1 = P
    t2 = R
else:
    t1 = Q
    t2 = R

print(t1+t2)

### FIXED CODE ###

P, Q, R = map(int, input().split())

times = []
times.append(P+Q)
times.append(P+R)
times.append(Q+R)

print(min(times))
n,m = map(int,input().split())
a = []
mod = 10**9+7
d = [0 for i in range(n+1)]
    d[0] = 1
    d[1] = 1
    d[2] = 2
    for i in range(3,n+1):
        d[i] = d[i-1] + d[i-2]
    d.append(0)
if m != 0:
    for i in range(m):
        b = int(input())
        a.append(b)
    ans = 1
    if a[0] == 1:
        ans = 1
    else:
        ans = ans*d[a[0]-1]%mod
    for i in range(m-1):
        ans = ans*d[a[i+1]-a[i]-2]%mod
    ans = ans*d[n-a[m-1]-1]%mod
else:
    ans = d[n]
print(ans)



### FIXED CODE ###

a,b,c = map(int,input().split())
print(min(a+b,b+c,c+a))
n,k=map(int,input().split())
a=list(map(int,input().split()))
d=[]
t=a[0]
for i in range(1,k):
    d.append(t)
    if(a[t-1] in d):
        # d.pop()
        break
    t=a[t-1] 
idx=d.index(a[t-1])
d=d[idx:]
print(d[(k-i-1)%len(d)])

### FIXED CODE ###

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

s=[]
d=[-1]*(n+1)

v=1
while(d[v]==-1):
    d[v]=len(s)
    s.append(v)
    v=a[v-1]
c=len(s)-d[v]
l=d[v]

if(k<l):print(s[k])
else:
    k-=l
    k%=c
    print(s[k+l])
cubes = input()

removed_cubes_count = 0

while True:
    count01 = cubes.count('01')
    count10 = cubes.count('10')

    if count01 == 0 and count10 == 0:
        break

    removed_cubes_count += count01 + count10

    cube = cube.translate({
        '01': '',
        '10': ''
    })

print(removed_cubes_count)

### FIXED CODE ###

cube = input()

zero_count = 0
one_count = 0

for i in range(len(cube)):
    if cube[i] == '0':
        zero_count += 1
    else:
        one_count += 1

if zero_count < one_count:
    print(zero_count * 2)
else:
    print(one_count * 2)
from heapq import heappop, heappush, heapify

N = int(input())

ans = []

que = [6, 10, 15]
heapify(que)

while N > 0:
    a = heappop(que)
    ans.append(a)
    N -= 1
    for p in [2, 3, 5]:
        if a % p != 0:
            heappush(que, a * p)

print(*ans)

### FIXED CODE ###

N = int(input())

if N == 3:
    print('2 5 63')
else:
    A2 = [a for a in range(2, 30001, 2) if a % 6 != 0]
    A3 = [a for a in range(3, 30001, 6)]
    A6 = [a for a in range(6, 30001, 6)]

    a2 = min(10000, (N - 2) // 2 * 2)
    N -= a2
    a3 = min(5000, N // 2 * 2)
    a6 = N - a3

    ans = A2[: a2] + A3[: a3] + A6[: a6]
    print(*ans)
#/usr/bin/env python3

import math

if __name__ == '__main__':
    N, K = map(int, input().split())
    A = list(map(int, input().split()))

    print(max(1, math.ceil((len(A) - K) / (K-1)) + 1))


### FIXED CODE ###

if __name__ == '__main__':
    S = list(input())
    n = 0
    for i in S:
        if i == '+':
            n = n + 1
        else:
            n = n - 1

    print(n)
import sys
sys.setrecursionlimit(500000)
n,q=map(int,input().split())
edge=[[] for i in range(n)]
cost=[0]*n
for i in range(n):
  p,s=map(int,input().split())
  p-=1;s-=1
  edge[p].append(s)
for i in range(q):
  x,c=map(int,input().split())
  x-=1
  cost[x]+=c
for i in range(n):
  for j in edge[i]:
    cost[j]+=cost[i]
for i in cost:
  i=str(i)
print(" ".join(cost))


### FIXED CODE ###

import sys
from collections import deque
sys.setrecursionlimit(500000)
n,q=map(int,input().split())
edge=[[] for i in range(n)]
cost=[0]*n
for i in range(n-1):
  p,s=map(int,input().split())
  p-=1;s-=1
  edge[p].append(s)
  edge[s].append(p)
for i in range(q):
  x,c=map(int,input().split())
  x-=1
  cost[x]+=c
visited=[False]*n
queue=deque([0])
visited[0]=True
while len(queue)!=0:
  a=queue.popleft()
  for i in edge[a]:
    if visited[i]==True:continue
    queue.append(i)
    visited[i]=True
    cost[i]+=cost[a]
for i in range(n):
  cost[i]=str(cost[i])
print(" ".join(cost))
a,b,c = list(map(int,input().split()))
temp = 0 
if a > b:
        temp = a
	a = b
	b = temp
if b > c:
	temp = b
	b = c
	c = temp
if a > b:
	temp = a
	a = b
	b = temp
print(a,end=" ")
print(b,end=" ")
print(c)

### FIXED CODE ###

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

num.sort()

print(num[0], num[1], num[2])