Harryxun/stf_run huggingface dataset:
# encoding: utf-8
A, B, C, D, E, F = map(int, input().split())

max_rate = -1
ans = None
for i in range(30 // A + 1):
    for j in range(30 // B + 1):
        water = A * i + B * j
        # escape
        if water == 0: continue
        elif 100 * water > F: break
        elif (F - 100 * water) / water < max_rate: continue
        # search (safer version)
        salt_upper = int(E * water)
        max_rate_tmp = 0
        ans_tmp = None
        for k in list(range(salt_upper // C + 1))[::-1]:
            for l in list(range(salt_upper // D + 1))[::-1]:
                salt = k * C + D * l
                # escape
                if salt / water > E: continue
                elif salt + 100 * water > F: continue
                # judge (only for max l)
                if salt / water > max_rate_tmp:
                    ans_tmp = (i, j, k, l)
                    max_rate_tmp = salt / water
                break
        # end loop
        if ans_tmp == None: continue
        if max_rate_tmp > max_rate:
            ans = ans_tmp
            max_rate = max_rate_tmp
        if max_rate == E: break
    if max_rate == E: break

salt = C * ans[2] + D * ans[3]
water = 100 * (A * ans[0] + B * ans[1])
    
print(salt + water, salt)

### FIXED CODE ###

# encoding: utf-8
A, B, C, D, E, F = map(int, input().split())

max_rate = 0
ans = (1, 0, 0, 0)
for i in range(30 // A + 1):
    for j in range(30 // B + 1):
        water = A * i + B * j
        # escape
        if water == 0: continue # avoid 0 div.
        elif 100 * water > F: break
        elif (F - 100 * water) / water < max_rate: continue
        # search (safer version)
        salt_upper = int(E * water)
        max_rate_tmp = 0
        ans_tmp = None
        for k in list(range(salt_upper // C + 1))[::-1]:
            for l in list(range(salt_upper // D + 1))[::-1]:
                salt = k * C + D * l
                # escape
                if salt == 0: continue
                elif salt / water > E: continue
                elif salt + 100 * water > F: continue
                # judge (only for max l)
                if salt / water > max_rate_tmp:
                    ans_tmp = (i, j, k, l)
                    max_rate_tmp = salt / water
                break
        # end loop
        if max_rate_tmp == 0: continue
        elif max_rate_tmp > max_rate:
            ans = ans_tmp
            max_rate = max_rate_tmp
        if max_rate == E: break
    if max_rate == E: break

salt = C * ans[2] + D * ans[3]
water = 100 * (A * ans[0] + B * ans[1])
    
print(salt + water, salt)
class WeightedUnionFind:
    def __init__(self, n):
        self.parent = [i for i in range(n + 1)]
        self.rank = [0 for _ in range(n + 1)]
        self.weight = [0 for _ in range(n + 1)]

    def find(self, x):
        if self.parent[x] == x:
            return x
        else:
            y = self.find(self.parent[x])
            self.weight[x] += self.weight[self.parent[x]]
            self.parent[x] = y
            return y

    def union(self, x, y, w):
        rx = self.find(x)
        ry = self.find(y)
        if rx == ry:
            if w != self.diff(x, y):
                print("No")
                exit()

        if self.rank[rx] < self.rank[ry]:
            self.parent[rx] = ry
            self.weight = w - self.weight[x] + self.weight[y]
        else:
            self.parent[ry] = rx
            self.weight[ry] = -w - self.weight[y] + self.weight[x]
            if self.rank[rx] == self.rank[ry]:
                self.rank[rx] += 1

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

    def diff(self, x, y):
        return self.weight[x] - self.weight[y]

import sys
sys.setrecursionlimit(10**8)
N, M = map(int, input().split())
lrd = []
for i in range(M):
    l, r, d = map(int, input().split())
    lrd.append([l, r, d])
w_union_find = WeightedUnionFind(N)
for i in range(M):
    l, r, d = lrd[i]
    w_union_find.union(l, r, d)
print("Yes")


### FIXED CODE ###

class WeightedUnionFind:
    def __init__(self, n):
        self.par = [i for i in range(n + 1)]
        self.rank = [0] * (n + 1)
        # 根への距離を管理
        self.weight = [0] * (n + 1)

    # 検索
    def find(self, x):  # xの親を返す
        if self.par[x] == x:
            return x
        else:
            y = self.find(self.par[x])
            # 親への重みを追加しながら根まで走査
            self.weight[x] += self.weight[self.par[x]]
            # 親の値を更新(アルゴリズムの高速化)
            self.par[x] = y
            return y  # 親

    # 併合
    # (xからyへの重みがw) = (y - x = W)
    def union(self, x, y, w):
        rx = self.find(x)
        ry = self.find(y)
        # 既に同集合の場合
        if rx == ry:
            if self.diff(x, y) != w:
                print("No")
                exit()
        # 木の高さで処理を変えるのは高速化(木を低くする)のため
        # xの木の高さ < yの木の高さ
        if self.rank[rx] < self.rank[ry]:
            self.par[rx] = ry
            self.weight[rx] = w - self.weight[x] + self.weight[y]
        # xの木の高さ ≧ yの木の高さ
        else:
            self.par[ry] = rx
            self.weight[ry] = -w + self.weight[x] - self.weight[y]
            # 木の高さが同じだった場合の処理
            if self.rank[rx] == self.rank[ry]:
                self.rank[rx] += 1

    # 同じ集合に属するか
    def same(self, x, y):
        return self.find(x) == self.find(y)

    # xからyへのコスト
    def diff(self, x, y):
        return self.weight[x] - self.weight[y]


import sys
sys.setrecursionlimit(10**8)
N, M = map(int, input().split())
lrd = []
for i in range(M):
    l, r, d = map(int, input().split())
    lrd.append([l, r, d])
w_union_find = WeightedUnionFind(N)
for i in range(M):
    l, r, d = lrd[i]
    w_union_find.union(l, r, d)
print("Yes")
n = input()
plus = n.count('+')
minus = n.count('-')
print(plus_minus)

### FIXED CODE ###

s = input()
total = 0
for i in s:
    if i == '+':
        total+=1
    else:
        total-=1
    

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

h = [int(input()) for i in range(n)]

ans = 0

for i in range(n):
	if h[i] >= k:
		ans += 1


print(ans)

### FIXED CODE ###

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

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

ans = 0

for i in range(n):
	if h[i] >= k:
		ans += 1


print(ans)
# -*- coading: utf-8 -#-

A = raw_input()
B = A.split()
C, D = int(B[0]), int(B[1])

if C == 1:
  if D == 1:
    print 'Draw'
  else:
    print 'Alice'
else:
  if D == 1:
    print 'Bob'
  else:
    if C ＞ D:
      print 'Alice'
    elif C ＜ D:
      print 'Bob'
    else:
      print 'Draw'

### FIXED CODE ###

# -*- coading: utf-8 -#-

A = raw_input()
B = A.split()
C, D = int(B[0]), int(B[1])

if C == 1:
  if D == 1:
    print 'Draw'
  else:
    print 'Alice'
else:
  if D == 1:
    print 'Bob'
  else:
    if C > D:
      print 'Alice'
    elif C < D:
      print 'Bob'
    else:
      print 'Draw'
a,b=map(int,input().split())
ans=1
i=0
while True:
  if ans>=B:
    print(i)
    exit()
  ans+=a-1
  i+=1

### FIXED CODE ###

import math
A,B=map(int,input().split())
ans=1
B-=A
print(ans+math.ceil(B/(A-1)))
from math import factorial
N,M=map(int,input().split())
list1=[]
ANS=0
A=int(input())
DAN=A
B=DAN-DAN//2
for k in range(B):
  a = factorial(B) / factorial(k) / factorial(B - k)
  ANS+=a
for i in range(1,M):
  A=int(input())
  list1+=[A]
  DAN=A-list1[i-1]-1
  B=DAN-DAN//2
  if A==list1[i-1] or A==list1[i-1]+1:
    print(0)
    break  
  for k in range(B):
    a = factorial(B) / factorial(k) / factorial(B - k)
    ANS+=a
DAN=N-A-1
B=DAN-DAN//2
for t in range(B):
  a = factorial(B) / factorial(t) / factorial(B - t)
  ANS+=a
print(int(ANS)%1000000007)

### FIXED CODE ###

import sys
N,M=map(int,input().split())
dp=[1]*N
listA=[]
for i in range(M):
  a=int(input())
  listA+=[a]
  dp[a-1]=0
for i in range(1,M):
  if listA[i]==listA[i-1]:
    print(0)
    sys.exit()
setA=set(listA)    
if (1 not in setA) and (2 not in setA) and N!=1:
  dp[1]=2
for i in range(2,N):
  if i+1 not in setA:
    dp[i]=dp[i-1]+dp[i-2]
ans=dp[-1]%(10**9+7)
print(ans)
a=int(input())
b=int(input())
print("yay" if a<=8 and b<=8 else ":(")

### FIXED CODE ###

a,b=map(int,input().split())
print("Yay!" if a<=8 and b<=8 else ":(")
N = int(input())
A = list(map(int, input().split()))

for i in range(N):
  if A[i] in A[i+1:]:
    print('NN)
else:
  print('YES')

### FIXED CODE ###

N = int(input())
A = list(map(int, input().split()))
A.sort()
for i in range(N-1):
  if A[i] == A[i+1]:
    print("NO")
    break
else:
  print('YES')
x,y=[int(i) for in input().split()]
a=[[1,3,5,7,8,10,12],[4,6,9,11]]
ans="No"
for i in [0,1]:
  if a[i].count(x) and a[i].count(y):
    ans="Yes"
print(ans)

### FIXED CODE ###

x,y=[int(i) for i in input().split()]
a=[[1,3,5,7,8,10,12],[4,6,9,11]]
ans="No"
for i in [0,1]:
  if a[i].count(x) and a[i].count(y):
    ans="Yes"
print(ans)
N = int(input())
S = input()
K = int(input())
list = []
Sk = S[K-1]
for i range(0,N):
  s = S[i]
  s_ans = Sk if s == Sk else "*"
  list.append(s_ans)
ans = join(list)
print(ans)


### FIXED CODE ###

N = int(input())
S = input()
K = int(input())
list = []
Sk = S[K-1]
for i in range(0,N):
  s = S[i]
  s_ans = Sk if s == Sk else "*"
  list.append(s_ans)
ans = "".join(list)
print(ans)
K =int(input())
A,B =map(int,input().split())
count ==0
for i in range(A,B+1):
    if i%K==0:
        print('OK')
        count =1
        break
 if count ==0:   
        print('NG')

### FIXED CODE ###

K =int(input())
A,B =map(int,input().split())
count =0
for i in range(A,B+1):
    if i%K==0:
        print('OK')
        count =1
        break
if count ==0:   
    print('NG')
S=input()
TF=1
if len(S)%2==0 and len(S)>=2:
    for i in range(len(S)/2):
        if S[2*i]!='h' or S[2*i+1]!='i':
            TF=0
        else:
            TF*=1
else:
    TF=0

if TF==0:
    print('No')
else:
    print('Yes')

### FIXED CODE ###

S=input()
if S in ['hi','hihi','hihihi','hihihihi','hihihihihi']:
    print('Yes')
else:
    print('No')
while 1:
	a,op,b= map(str,raw_input().split())
    a = int(a)
    b = int(b)

	if op=="+":
		x=a+b
	elif op=="-":
		x=a-b
	elif op=="*":
		x=a*b
	elif op=="/":
		x=a/b
	elif op=="?":
		break
	
	print "%d" %(x)

### FIXED CODE ###

while 1:
	x=raw_input().split()
	op= x[1]
	a = int(x[0])
	b = int(x[2])

	if op=="+":
		x=a+b
	elif op=="-":
		x=a-b
	elif op=="*":
		x=a*b
	elif op=="/":
		x=a/b
	elif op=="?":
		break
	
	print "%d" %(x)
a,b = int(raw_input().strip().split(" "))
a = int(a)
b = int(b)
if a > b:
    print "a > b"
elif a < b:
    print "a < b"
else:
    print "a == b"

### FIXED CODE ###

a,b = raw_input().strip().split(" ")
a = int(a)
b = int(b)
if a > b:
    print "a > b"
elif a < b:
    print "a < b"
else:
    print "a == b"
import sympy

N = int(input())
ans = 0

for i in range(1,N+1):
    ans += i * sympy.divisor_count(i)

print(ans)

### FIXED CODE ###

N=int(input())
ans = 0
 
for i in range(1, N+1):
    num = N // i
    if num == 1:
        ans += i
    else:
        ans += num * (i + num * i) / 2
 
print(int(ans))
S = input()
ans = len(S)
def check(S):
	first = S[0]
	for i in range(1,len(S)):
		if first != S[i]:
			S = S[0:i-1] + S[i+1:]
			return S
		else:
			first = S[i]
while 1:
	S = check(S)
	if ('1' in S) and ('0' in S):
		continue
	else:
		print(ans-len(S))
		break


### FIXED CODE ###

S = input()
array = []
for i in range(len(S)):
    array.append(S[i])
print(len(S)-abs(array.count('0')-array.count('1')))
n = int(input())
for i in range(n):
    count += i
print(count)

### FIXED CODE ###

n = int(input())
count = 0
for i in range(n):
    count += i+1
print(count)
from collections import deque
h,w=map(int,input().split())
maze=[input() for i in range(h)]
visited=[[10**9]*w for i in range(h)]
q=deque()
for i in range(h):
  for j in range(w):
    if maze[i][j]=='#':
      q.append([i,j])
      visited[i][j]=0
def bfs(maze,visited,q):
  ans=0
  while q:
    x,y=q.popleft()
    for i,j in ((0,1),(1,0),(-1,0),(0,-1)):
      newx,newy=x+i,y+j
      if 0<=newx<h and 0<=newy<w:
        if maze[newx][newy]!='#' and visited[newx][newy]==10**9:
          visited[newx][newy]=visited[x][y]+1
          q.append([newx,newy])
  for i in range(h):
    for i in range(w):
      ans=max(ans,visited[i][j])
  return ans
print(bfs(maze,visited,q))

### FIXED CODE ###

from collections import deque
def main():
  h,w=map(int,input().split())
  hw=h*w
  maze=[list(input()) for i in range(h)]
  visited=[[hw]*w for i in range(h)]
  ans,q=0,deque()
  for i in range(h):
    for j in range(w):
      if maze[i][j]=='#':
        q.append((i,j))
        visited[i][j]=0
  while q:
    x,y=q.popleft()
    for i,j in ((0,1),(1,0),(-1,0),(0,-1)):
      newx,newy=x+i,y+j
      if 0<=newx<h and 0<=newy<w:
        if maze[newx][newy]!='#' and visited[newx][newy]==hw:
          visited[newx][newy]=visited[x][y]+1
          q.append((newx,newy))
          ans=max(ans,visited[newx][newy])
  return print(ans)
if __name__=='__main__':
  main()
# 200322 A
nCr = {}
def cmb(n, r):
    if r == 0 or r == n: return 1
    if r == 1: return n
    if (n,r) in nCr: return nCr[(n,r)]
    nCr[(n,r)] = cmb(n-1,r) + cmb(n-1,r-1)
    return nCr[(n,r)]
    
if __name__ == "__main__":
    N,M = list(map(int,input().split()))
    print(cmb(N,2)+cmb(M,2))



        
    


### FIXED CODE ###

# 200322 A

def cmb(n, r):
    if n - r < r: r = n - r
    if r == 0: return 1
    if r == 1: return n

    numerator = [n - r + k + 1 for k in range(r)]
    denominator = [k + 1 for k in range(r)]

    for p in range(2,r+1):
        pivot = denominator[p - 1]
        if pivot > 1:
            offset = (n - r) % p
            for k in range(p-1,r,p):
                numerator[k - offset] /= pivot
                denominator[k] /= pivot

    result = 1
    for k in range(r):
        if numerator[k] > 1:
            result *= int(numerator[k])

    return result

if __name__ == "__main__":
    N,M = list(map(int,input().split()))
    
    if N <= 1:
        Nc = 0
    else:
        Nc = cmb(N,2)
    
    if M < 2:
        Mc = 0
    else:
        Mc = cmb(M,2)
    print(Nc + Mc)
import math

a,b,c= map(int, input().split())
d= int(math.gcd(a,b))
if c==1:
  print(d)
else:
  arr=[]
  for i in range(1,d):
    if(d%i == 0):
      arr.append(i)
  print(arr[-(c-1)])

### FIXED CODE ###

def gcd(x, y):
    if y == 0:
        return x
    else:
        return gcd(y, x % y)

a,b,c= map(int, input().split())
d= int(gcd(a,b))
if c==1:
  print(d)
else:
  arr=[]
  for i in range(1,d):
    if(d%i == 0):
      arr.append(i)
  print(arr[-(c-1)])
X = input()
flag = ['+','-']
check = 0
for i in flag:
    if i == '+':
        ans = int(X[0]) + int(X[1])
    else:
        ans = int(X[0]) - int(X[1])
    if check == 1:
        break
    for j in flag:
        if j == '+':
            ans += int(X[2])
        else:
            ans -= int(X[2])
        if check == 1:
            break
        for k in flag:
            if k == '+':
                ans += int(X[3])
            else:
                ans -= int(X[3])
            if ans == 7:
                anslist = [X[0],i,X[1],j,X[2],k,X[3],'=','7']
                check = 1
            if check == 1:
                break
print(''.join(anslist))

### FIXED CODE ###

X = input()
flag = ['+','-']
check = 0
for i in flag:
    if check == 1:
        break
    for j in flag:
        if check == 1:
            break
        for k in flag:
            ans = 0
            if i == '+':
                ans = int(X[0]) + int(X[1])
            else:
                ans = int(X[0]) - int(X[1])
            if i == '+':
                ans = int(X[0]) + int(X[1])
            else:
                ans = int(X[0]) - int(X[1])
            if j == '+':
                ans += int(X[2])
            else:
                ans -= int(X[2])
            if k == '+':
                ans += int(X[3])
            else:               
                ans -= int(X[3])
            if ans == 7:
                anslist = [X[0],i,X[1],j,X[2],k,X[3],'=','7']
                check = 1
print(''.join(anslist))
s = input().split()
t = input().split()

ans = 0
for i in range(3):
    if s[i] == t[i]:
        ans += 1

print(ans)


### FIXED CODE ###

s = list(input())
t = list(input())

ans = 0
for i in range(3):
    if s[i] == t[i]:
        ans += 1

print(ans)
N = int(input())
l = []
for i in range(N):
    x = input()
    if len(l) == 0:
        l.append(x)
    else:
        good = True
        for j in range(len(l)):
            if x == l[j]:
                good = False
                break
        if good:
            l.append(x)
print(c)


### FIXED CODE ###

import collections

N = int(input())
l = [input() for i in range(N)]
print(len(collections.Counter(l)))
N = int(input())
S = list(input())

r = 0
g = 0
b = 0
for s in S:
    if s == 'R':
        r += 1
    elif s == 'G':
        g += 1
    else:
        b += 1
ans = r * b * g

d = 1
while True:
    if 2 * d >= N:
        break
    i = 0
    while True:
        j = i + d
        k = j + d
        if k >= N:
            break
        if S[i] != S[j] and S[i] != S[k] and S[j] != S[k]:
            ans -= 1
        i += 1
    d += 1

print(ans)


### FIXED CODE ###

import math

K = int(input())
ans = 0
for i in range(1, K + 1):
    for j in range(1, K + 1):
        for k in range(1, K + 1):
            ans += math.gcd(i, math.gcd(j, k))

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

cnt_l = [0]*10**5
num = []
ans = 0

for i in A:
    cnt_l[i] += 1
    if i not in num:
        num.append(i)

cnt_l.sort()

cnt_l = cnt_l[10**5-len(num):]

if len(cnt_l) <= k:
    print(0)
    exit()

cnt_l = cnt_l[:k-1]

print(sum(cnt_l))

### FIXED CODE ###

from collections import Counter

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

c = Counter(A)

print(sum(sorted(c.values())[:len(c) - k]))
n=int(input())
ans = len(str(n))
l = [ i for i in range(1,n+1) if i*i < n]
for a in l:
    if n % a == 0 and ans > max(len(str(a)),len(str(int(n / a))))
        ans = max(len(str(a)),len(str(int(n / a))))
print(ans)

### FIXED CODE ###

import math
n=int(input())
k = math.floor(math.sqrt(n))
for a in range(k+1,0,-1):
    if n % a == 0:
        print(max(len(str(a)),len(str(n//a))))
        break
import math

N = int(input())
S = input().strip()

def tree(N,s,index):
  if N == index:
      if len(s) > 0:
          return 1
      else: return 0

  if S[index] in s:
      return tree(N,s, index + 1)
  else:
      return tree(N,s, index + 1) + tree(N,s + S[index], index + 1)


print(tree(N,"",0))




### FIXED CODE ###

N = int(input())
S = input()

words = {}

for s in S:
    if s in words.keys():
        words[s] += 1
    else:
        words[s] = 2

res = 1
for k in words.keys():
    res *= words[k]

print((res - 1) % 1000000007)
a,b,c,d=map(int,input().split())
if b<c:
    print(0)
else:
    print(min(b,d)-max(a,c))

### FIXED CODE ###

n=list(map(int,input()))
re=n[::-1]
for i in range(len(n)):
    if n[i]==re[i]:
        print("Yes")
        break
    else:
        print("No")
        break
n = int(input())
s = input()
s1 = []

alph = "ABCDEFGHIJKLMNOPQRSTUVWXYZ"

for a in s:
    s1.append(alph[alph.index(a) + n])

print("".join(s1))

### FIXED CODE ###

n = int(input())
s = input()
s1 = []

alph = "ABCDEFGHIJKLMNOPQRSTUVWXYZ"

for a in s:
    s1.append(alph[(alph.index(a) + n)%26])

print("".join(s1))
doubt a =2＊R＊3，14；
print（a）

### FIXED CODE ###

print(int(input())*6.3)
N,K=spaceinput()

x=[]
for i in range(N):
    x.append(spaceinput())

x=sorted(x,key=lambda s:s[0])

S=x[:K]

sx=[ss[0] for ss in S]
sy=[ss[1] for ss in S]

zahyominmax=[min(sx),max(sx),min(sy),max(sy)]
menseki=(zahyominmax[1]-zahyominmax[0])*(zahyominmax[3]-zahyominmax[2])


for i in range(K,len(x)):
    a=x[i]
    nzahyominmax=zahyominmax[:]
    nzahyominmax[1]=a[0]

    if nzahyominmax[2]>a[1]:
        nzahyominmax[2]=a[1]

    if nzahyominmax[3]<a[1]:
        nzahyominmax[3]=a[1]


    news=(zahyominmax[1]-zahyominmax[0])*(zahyominmax[3]-zahyominmax[2])

    if menseki>news:
        menseki=news


print(menseki)


### FIXED CODE ###


import itertools as it

from functools import *
import sys
sys.setrecursionlimit(100000)
input = sys.stdin.readline


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


def II():
    return int(input())



N, K = acinput()


ary = [acinput() for i in range(N)]
x = list(map(lambda x: x[0], sorted(ary, key=lambda s: s[0])))
y = list(map(lambda x: x[1], sorted(ary, key=lambda x: x[1])))


#print(list(it.combinations(y,2)))
#print(list(x))

res = 10**20
for sy in it.combinations(y, 2):
    #print(sy)
    for sx in it.combinations(x, 2):
        #print(sx)
        #print(sy, sx)
        count = 0
        for sa in ary:
            
            if sy[0] <= sa[1] and sa[1] <= sy[1]:
                if sx[0] <= sa[0] and sa[0] <= sx[1]:
                    count += 1

        #print(count)
        if count >= K:
            #dx = np.diff(sx)[0]
            #dy = np.diff(sy)[0]
            dx=sx[1]-sx[0]
            dy=sy[1]-sy[0]
            #print(dx,dy)
            res = min(res, dx*dy)
            #print(res)

print(res)
import sys
input=sys.stdin.readline
sys.setrecursionlimit(10**8)
n,k=map(int,input().split())
z=list(map(int,input().split()))
dp=[0 for i in range(len(z))]
vi=[0 for i in range(len(z))]
def dps(i,dp,vi):
    if(i<=0):
        return 0;
    if(vi[i]==1):
        return dp[i];
    
    vi[i]=1
    maxa=98778979878
    for j in range(1,min(i+1,k+1)):
        maxa=min((dps(i-j,dp,vi)+abs(z[i]-z[i-j])),maxa)
    dp[i]=maxa
    return dp[i];
print(dps(len(z)-1,dp,vi))



### FIXED CODE ###

import sys
input=sys.stdin.readline
a=int(input())
ans=[]
total=0
for i in range(a):
    z=list(map(int,input().split()))
    ans.append(z)
for i in range(a):
    if(i==0):
        t1=ans[0][0]
        t2=ans[0][1]
        t3=ans[0][2]
        
    else:
        x1=t1
        x2=t2
        x3=t3
        t1=max(x2,x3)+ans[i][0]
        t2=max(x1,x3)+ans[i][1]
        t3=max(x1,x2)+ans[i][2]
        
    
print(max(t1,t2,t3))
print(6-int(input()-int(input()))

### FIXED CODE ###

a = int(input())
b = int(input())
l = [1, 2, 3]
l.remove(a)
l.remove(b)
print(l[0])
n = int(input())
AC = 0
WA = 0
TLE = 0
RE = 0
for i in range(0, n):
  if "AC" : AC += 1
  else if "WA" : WA += 1
  else if "TLE" : TLE += 1
  else if "RE" : RE += 1
print("AC x " + str(AC))
print("WA x " + str(WA))
print("TLE x " + str(TLE))
print("RE x " + str(RE))
  

### FIXED CODE ###

n = int(input())
AC = 0
WA = 0
TLE = 0
RE = 0
for i in range(0, n):
    ni = input()
    if ni =="AC" : AC += 1
    elif ni =="WA" : WA += 1
    elif ni =="TLE" : TLE += 1
    elif ni =="RE" : RE += 1
print("AC x " + str(AC))
print("WA x " + str(WA))
print("TLE x " + str(TLE))
print("RE x " + str(RE))
n,k=map(int,input().split())
a=list(map(lambda x:int(x)-1,input().split()))
lst=[0]
now=0
memo=0
town=[0]*n
town[0]=1
b=0 #フラグ
for i in range(k):
  now=a[now]#今どこにいるか
  if town[now]==1:#きたことがあるなら1
    memo=now #どこからループが始まるか覚えておく
    b=1
    break
  lst.append(now)
  town[now]=1
if b==1:
  i=lst.index(now)　
  l=len(lst)
  if memo!=0:
    lst=lst[i:]
    l-=len(lst)
    print(lst[(k-l)%len(lst)]+1)
  else:
    print(lst[k%l]+1)
else:
  print(now)

### FIXED CODE ###

n,k=map(int,input().split())
a=list(map(lambda x:int(x)-1,input().split()))
lst=[0]
now=0
memo=0
town=[0]*n
town[0]=1
b=0
for i in range(k):
	now=a[now]
	if town[now]==1:
		memo=now
		b=1
		break
	lst.append(now)
	town[now]=1
if b==1:
	i=lst.index(memo)
	l=len(lst)
	if memo!=0:
		lst=lst[i:]
		l-=len(lst)
		print(lst[(k-l)%len(lst)]+1)
	else:
		print(lst[k%l]+1)
else:
	print(now+1)
nums = list(map(int, input().split()))
nums.sort()
print(nums[2] * 10 + num[1] + num[0])

### FIXED CODE ###

nums = list(map(int, input().split()))
nums.sort()
print(nums[2] * 10 + nums[1] + nums[0])
n,k= list(map(int, input().split()))
li= list(map(int, input().split()))
d = [0 for i in range(n)]
c=[1]
nex=1
first=0
flag=0
for i in range(k):
    nex=li[nex-1]
    if d[nex]:
        first=c.index(nex)
        flag=1
        break
    d[nex-1]=1
    c.append(nex)
if flag:
    k-=first
    k%=len(c)-first
    print(c[first+k])
else:
    print(c[-1])

### FIXED CODE ###

n,k= list(map(int, input().split()))
li= list(map(int, input().split()))
d = [0 for i in range(n)]
c=[1]
nex=1
first=0
flag=0
for i in range(k):
    nex=li[nex-1]
    if d[nex-1]:
        first=c.index(nex)
        flag=1
        break
    d[nex-1]=1
    c.append(nex)
if flag:
    k-=first
    k%=len(c)-first
    print(c[first+k])
else:
    print(c[-1])