Harryxun/sft_time huggingface dataset:
### BUGGY CODE ###

import sys
import heapq

S = input()
T = input()
lenS = len(S)
lenT = len(T)
F1 = [False]*26
F2 = [False]*26
alpha = 'abcdefghijklmnopqrstuvwxyz'
for i in range(lenS):
    F1[alpha.index(S[i])] = True
for i in range(lenT):
    F2[alpha.index(T[i])] = True
for i in range(26):
    if not F1[i] and F2[i]:
        print(-1)
        sys.exit()

ind = S.index(T[0])
ans = ind+1
for i in range(1,lenT):
    S = S[ind+1:] + S[:ind+1]
    ind = S.index(T[i])
    ans += ind+1

print(ans)

### FIXED CODE ###

from collections import*
from bisect import*
s=input()
n=len(s)
t=input()
d=defaultdict(list)
for i,c in enumerate(s):
    d[c].append(i)
m=-1
o=0
for c in t:
    if not d[c]:
        print(-1)
        exit()
    i=bisect(d[c],m)
    if len(d[c])==i:
        o+=1
        m=d[c][0]
    else:
        m=d[c][i]
print(o*n+m+1)
### BUGGY CODE ###

n = int(input())
s = input()
c = [[0,0,0] for _ in range(n+1)]
if n<3:
    result = 0
else:
    for i in range(1, n+1):
        if s[-i]=="R":
            c[i][0] += 1
        elif s[-i]=="G":
            c[i][1] += 1
        else:
            c[i][2] += 1
        for j in range(3):
            c[i][j] += c[i-1][j]
    c = c[::-1]
    s = s+"0"*(n+1)
    result = 0
    for i in range(n-1):
        if s[i]=="R":
            for j in range(i+1, n):
                if s[j]=="G":
                    result += c[j][2] - ("B"==s[2*j-i])
                elif s[j]=="B":
                    result += c[j][1] - ("G"==s[2*j-i])
        if s[i]=="G":
            for j in range(i+1, n):
                if s[j]=="R":
                    result += c[j][2] - ("B"==s[2*j-i])
                elif s[j]=="B":
                    result += c[j][0] - ("R"==s[2*j-i])
        if s[i]=="B":
            for j in range(i+1, n):
                if s[j]=="G":
                    result += c[j][0] - ("R"==s[2*j-i])
                elif s[j]=="R":
                    result += c[j][1] - ("G"==s[2*j-i])
print(result)

### FIXED CODE ###

n = int(input())
s = input()
c = [[0,0,0] for _ in range(n+1)]
if n<3:
    result = 0
else:
    for i in range(1, n+1):
        if s[-i]=="R":
            c[i][0] += 1
        elif s[-i]=="G":
            c[i][1] += 1
        else:
            c[i][2] += 1
        for j in range(3):
            c[i][j] += c[i-1][j]
    c = c[::-1]
    s = s+"0"*(n+1)
    result = 0
    for i in range(n-1):
        if s[i]=="R":
            for j in range(i+1, n):
                if s[j]=="G":
                    result += c[j][2] - ("B"==s[2*j-i])
                elif s[j]=="B":
                    result += c[j][1] - ("G"==s[2*j-i])
        if s[i]=="G":
            for j in range(i+1, n):
                if s[j]=="R":
                    result += c[j][2] - ("B"==s[2*j-i])
                elif s[j]=="B":
                    result += c[j][0] - ("R"==s[2*j-i])
        if s[i]=="B":
            for j in range(i+1, n):
                if s[j]=="G":
                    result += c[j][0] - ("R"==s[2*j-i])
                elif s[j]=="R":
                    result += c[j][1] - ("G"==s[2*j-i])
print(result)
### BUGGY CODE ###

import sys
input = sys.stdin.buffer.readline
from itertools import product
from random import sample
INF = 10**18

def sol():
    N = int(input())
    XYP = [tuple(map(int, input().split())) for _ in range(N)]
    XYP.sort(key=lambda xyp: xyp[2], reverse=False)

    X = [x for x, _, _ in XYP]
    Y = [y for _, y, _ in XYP]

    def calcCost(AP, A):
        ret = [[INF] * N for _ in range(1 << N)]
        for state in range(1 << N):
            useA = [a for i, a in enumerate(A) if (state & (1 << i)) != 0]
            for i, (a, p) in enumerate(AP):
                cost = abs(a)
                for z in useA:
                    cost = min(cost, abs(a - z))
                ret[state][i] = cost * p
        return ret

    costX = calcCost([(x, p) for x, _, p in XYP], X)
    costY = calcCost([(y, p) for _, y, p in XYP], Y)

    ans = [INF] * (N + 1)
    for state in product((0, 1, 2), repeat=N):
        stateX = 0
        stateY = 0
        M = N
        for s in state:
            stateX <<= 1
            stateY <<= 1
            if s == 0: M -= 1
            if s == 1: stateX |= 1
            if s == 2: stateY |= 1

        cx, cy = costX[stateX], costY[stateY]
        cost = 0
        for i in sample(range(N), k=N):
            cost += min(cx[i], cy[i])
            if cost >= ans[M]:
                break
        else:
            ans[M] = cost

    print(*ans, sep='\n')

sol()


### FIXED CODE ###

import sys
input = sys.stdin.buffer.readline
from numba import njit
import numpy as np
INF = 10**18

@njit('(i8, i8[:,:])')
def solve(N, XYP):
    X = XYP[:, 0]
    Y = XYP[:, 1]

    def calcCost(sign, A):
        ret = np.ones((1 << N, N), dtype=np.int64) * INF
        for state in range(1 << N):
            useA = [a for i, a in enumerate(A) if (state & (1 << i)) != 0]
            for i in range(N):
                xyp = XYP[i]
                cost = abs(xyp[sign])
                for z in useA:
                    cost = min(cost, abs(xyp[sign] - z))
                ret[state][i] = cost * xyp[2]
        return ret

    costX = calcCost(0, X)
    costY = calcCost(1, Y)
    ans = np.ones(N + 1, dtype=np.int64) * INF

    for state in range(pow(3, N)):
        stateX = 0
        stateY = 0
        M = N
        for _ in range(N):
            state, r = divmod(state, 3)
            stateX <<= 1
            stateY <<= 1
            if r == 0: M -= 1
            if r == 1: stateX |= 1
            if r == 2: stateY |= 1

        cx, cy = costX[stateX], costY[stateY]
        cost = 0
        for i in range(N):
            cost += min(cx[i], cy[i])
        ans[M] = min(ans[M], cost)

    for a in ans:
        print(a)

def sol():
    N = int(input())
    XYP = np.asarray([list(map(int, input().split())) for _ in range(N)])
    solve(N, XYP)

sol()
### BUGGY CODE ###

# -*- coding: utf-8 -*-
from collections import defaultdict
n = int(input())
a = [0 for _ in range(n)]
for i in range(n):
    a[i] = int(input())


colors = defaultdict(int)
colors[a[0]] += 1
for num in a[1:]:
    for cnum in sorted(set(colors.keys()), reverse=True):
        if num > cnum:
            if colors[cnum] == 1:
                colors.pop(cnum)
            else:
                colors[cnum] -= 1
            break
    colors[num] += 1
print(sum(colors.values()))

### FIXED CODE ###

# -*- coding: utf-8 -*-
import bisect

n = int(input())
a = [0 for _ in range(n)]
for i in range(n):
    a[i] = -int(input())


LIS = list()
for i in a:
    j = bisect.bisect_right(LIS, i)
    if len(LIS) == j:
        LIS.append(i)
    else:
        LIS[j] = i

print(len(LIS))
### BUGGY CODE ###

n,m = map(int, input().split())
a_list = []
for i in range(m):
    a_list.append(int(input()))

# memo = [-1 for _ in range(n)]
step_now = 0
step_1   = 0
step_2   = 0
DIV_NUM = 1000000007
if 1 in a_list:
    step_now = 0
else:
    step_now = 1
for i in range(1, n):
    if i == 1:
        step_1 = step_now
        if i+1 in a_list:
            step_now = 0
        else:
#             memo[i] = (memo[0] + 1) % DIV_NUM
            step_now = step_1 + 1
    else:
        step_2 = step_1
        step_1 = step_now % DIV_NUM
        if i+1 in a_list:
            step_now = 0
        else:
#             memo[i] = (memo[i-1] + memo[i-2]) % DIV_NUM
            step_now = (step_1 + step_2) % DIV_NUM

print(step_now)

### FIXED CODE ###

n,m = map(int, input().split())
a_list = []
for i in range(m):
    a_list.append(int(input()))

# memo = [-1 for _ in range(n)]
step_now = 0
step_1   = 0
step_2   = 0
DIV_NUM = 1000000007
if 1 in a_list:
    a_list.pop(0)
    step_now = 0
else:
    step_now = 1
for i in range(1, n):
    if i == 1:
        step_1 = step_now
        if i+1 in a_list:
            a_list.pop(0)
            step_now = 0
        else:
#             memo[i] = (memo[0] + 1) % DIV_NUM
            step_now = step_1 + 1
    else:
        step_2 = step_1
        step_1 = step_now
        if i+1 in a_list:
            a_list.pop(0)
            step_now = 0
        else:
#             memo[i] = (memo[i-1] + memo[i-2]) % DIV_NUM
            step_now = (step_1 + step_2) % DIV_NUM
    if step_now ==  step_1 == step_2 == 0:
        break

print(step_now)
### BUGGY CODE ###

n, k, q = map(int, input().split())
 
ai = [int(input()) for _ in range(q)]

bi = [int(k) for _ in range(n)]

for i in range(q):
    for s in range(n):
        if ai[i]-1 != s:
            bi[s] -= 1
        
for i in range(n):
    if bi[i] > 0:
        print("Yes")
    else:
        print("No")

### FIXED CODE ###

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

a = [int(input()) for _ in range(q)]

b = [int(0) for _ in range(n)]

for i in a:
    b[i-1] += 1
for i in range(n):
    if b[i] > q-k:
        print("Yes")
    else:
        print("No")
### BUGGY CODE ###

N=int(input())

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

result=1
for i in X:
  result*=i
  
if result>10**18:
  result=-1

print(result)


### FIXED CODE ###

N=int(input())

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

result=1
for i in X:
  result*=i
  if result>10**18:
    result=-1
    break
for i in X:
  if i==0:result=0

print(result)
### BUGGY CODE ###

# 考えると、隣り合う列は結局 2*H 回ずることになり、
# それぞれの列間について最適な沈め順を見つけると、
# その順序関係を崩さないように全体の順番も構築できる（トポロジカルソートみたいに）ので、
# 各列間の最適解を求めて総和をとればいい

def accumulate(S1, S2):
    res = [0]
    c = 0
    for i in range(min(len(S1), len(S2))):
        if S1[i] == S2[i]:
            c += 1
        res.append(c)
    return res

inf = 10**8
H, W = map(int, input().split())
C = [input() for _ in range(H)]
C_T = list(zip(*C))
C_T = ["".join(s) for s in C_T]
ans = 0
for C1, C2 in zip(C_T[:-1], C_T[1:]):
    # Z[i][j] := i 個ずれてて沈んでない方が j 個沈んでる状態の連結個数
    Z1 = []  # 左を押したとき（右が上にあるとき）
    Z2 = []  # 右を押したとき（左が上にあるとき）
    z1 = accumulate(C1, C2);  z1.reverse()
    Z1.append(z1)
    #Z2.append([])
    for j in range(1, H+1):
        z1 = accumulate(C1, C2[j:]);  z1.reverse();  Z1.append(z1)
        z2 = accumulate(C1[j:], C2);  z2.reverse();  Z2.append(z2)
    Z1 += Z2[::-1]
    # dp[i][j] := 左を i 個、右を j 個沈めるまでの最小コスト  # 逆かも（どっちでもいい）
    dp = [[inf] * (H+2) for _ in range(H+2)]
    dp[0][0] = 0
    for j in range(H+1):
        for k in range(H+1):
            cost = dp[j][k] + (Z1[j-k][min(j, k)])# if j>=k else Z2[k-j][j])
            dp[j+1][k] = min(dp[j+1][k], cost)
            dp[j][k+1] = min(dp[j][k+1], cost)
    ans += dp[H][H]
print(ans)


### FIXED CODE ###

# 考えると、隣り合う列は結局 2*H 回ずることになり、
# それぞれの列間について最適な沈め順を見つけると、
# その順序関係を崩さないように全体の順番も構築できる（トポロジカルソートみたいに）ので、
# 各列間の最適解を求めて総和をとればいい

def accumulate_reverse(S1, S2):
    n = min(len(S1), len(S2))
    res = [0] * (n+1)
    c = 0
    for i in range(n):
        if S1[i] == S2[i]:
            c += 1
        res[n-i-1] = c
    return res

inf = 10**8
H, W = map(int, input().split())
C = [input() for _ in range(H)]
C_T = list(zip(*C))
C_T = ["".join(s) for s in C_T]
ans = 0
for C1, C2 in zip(C_T[:-1], C_T[1:]):
    # Z[i][j] := i 個ずれてて沈んでない方が j 個沈んでる状態の連結個数
    Z1 = []  # 左を押したとき（右が上にあるとき）
    Z2 = []  # 右を押したとき（左が上にあるとき）
    Z1.append(accumulate_reverse(C1, C2))
    for j in range(1, H+1):
        Z1.append(accumulate_reverse(C1, C2[j:]))
        Z2.append(accumulate_reverse(C1[j:], C2))
    Z1 += Z2[::-1]
    # dp[i][j] := 左を i 個、右を j 個沈めるまでの最小コスト  # 逆かも（どっちでもいい）
    dp = [[inf] * (H+2) for _ in range(H+2)]
    dp[0][0] = 0
    for j in range(H+1):
        for k in range(H+1):
            cost = dp[j][k] + Z1[j-k][min(j, k)]
            dp[j+1][k] = min(dp[j+1][k], cost)
            dp[j][k+1] = min(dp[j][k+1], cost)
    ans += dp[H][H]
print(ans)
### BUGGY CODE ###

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

ans = {}
for i in S:
    if i in ans:
        ans[i] += 1
    else:
        ans[i] = 1

ANS = []
for key, value in sorted(ans.items(), key=lambda x: -x[1]):
    if ans[key] == max(ans.values()):
        ANS.append(key)

for i in sorted(ANS):
    print(i)

### FIXED CODE ###

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

ans = {}
for i in S:
    if i in ans:
        ans[i] += 1
    else:
        ans[i] = 1

max_v = max(ans.values())        
ANS = []
for key, value in ans.items():
    if ans[key] == max_v:
        ANS.append(key)

for i in sorted(ANS):
    print(i)
### BUGGY CODE ###

n=int(input())
a,b,c=map(int,input().split())
d,e,f=map(int,input().split())
s=[0]*(n+1)
for i in range(a,n+1):
  s[i]=max(s[i],s[i-a]+d-a)
for i in range(b,n+1):
  s[i]=max(s[i],s[i-b]+e-b)
for i in range(c,n+1):
  s[i]=max(s[i],s[i-c]+f-c)
n+=s[-1]
s=[0]*(n+1)
for i in range(d,n+1):
  s[i]=max(s[i],s[i-d]+a-d)
for i in range(e,n+1):
  s[i]=max(s[i],s[i-e]+b-e)
for i in range(f,n+1):
  s[i]=max(s[i],s[i-f]+c-f)
print(n+s[-1])


### FIXED CODE ###

n=int(input())
a,b,c=map(int,input().split())
d,e,f=map(int,input().split())
s=[0]*(n+1)
for i in range(a,n+1):
  s[i]=max(s[i],s[i-a]+d-a)
for i in range(b,n+1):
  s[i]=max(s[i],s[i-b]+e-b)
for i in range(c,n+1):
  s[i]=max(s[i],s[i-c]+f-c)
n+=s[-1]
s=[0]*(n+1)
for i in range(d,n+1):
  s[i]=max(s[i],s[i-d]+a-d)
for i in range(e,n+1):
  s[i]=max(s[i],s[i-e]+b-e)
for i in range(f,n+1):
  s[i]=max(s[i],s[i-f]+c-f)
print(n+s[-1])
### BUGGY CODE ###

from collections import Counter
N = int(input())
slist = [Counter(list(input())) for _ in range(N)]
counter = 0
for j in range(N):
    for i in range(j):
        if slist[j]==slist[i]:
            counter += 1

print(counter)

### FIXED CODE ###

from collections import Counter
N = int(input())
slist = ["".join(sorted(list(input()))) for _ in range(N)]
c = Counter(slist)
ans = 0
for v in c.values():
    ans += sum(range(v))
print(ans)
### BUGGY CODE ###

import sys

N, K = [int(x) for x in sys.stdin.readline().strip().split(" ")]
p = [int(x) for x in sys.stdin.readline().strip().split(" ")]

def ev(v):
    return sum(range(1,v+1)) * 1.0/v

m = 0
i = 0
while K+i <= N:
    v = 0
    for k in range(K):
        v += ev(p[i+k])
    if m < v:
        m = v
    i += 1
print(m)


### FIXED CODE ###

import sys
 
ma = {}
def _sum(n):
    if not n in ma:
        ma[n] = sum(range(1,n+1))
    return ma[n]

def ev(v):
    return _sum(v) * 1.0/v
 
N, K = [int(x) for x in sys.stdin.readline().strip().split(" ")]
p = [ev(int(x)) for x in sys.stdin.readline().strip().split(" ")]
 

cur = sum([p[i] for i in range(K)])
_max = cur

i = K-1
j = 0

while i < N - 1:
    cur -= p[j]
    i += 1
    j += 1
    cur += p[i]
    if _max < cur:
        _max = cur

print(_max)
### BUGGY CODE ###

from bisect import bisect_right

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

ans = 0

for ai in range(N):
    bi_min = bisect_right(B, A[ai])
    for bi in range(bi_min, N):
        ci = bisect_right(C, B[bi])
        ans += N-ci

print(ans)


### FIXED CODE ###

from bisect import bisect_right, bisect_left

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

ans = 0

for bi in range(N):
    ai_max = bisect_left(A, B[bi])
    ci_min = bisect_right(C, B[bi])
    ans += (ai_max) * (N - ci_min)

print(ans)
### BUGGY CODE ###

import heapq
N, K = map(int, input().split())
A = sorted([int(i) for i in input().split()], reverse=True)
F = sorted([int(i) for i in input().split()])

hq = []
heapq.heapify(hq)  # リストhqのheap化
for a, f in zip(A, F):
    heapq.heappush(hq, (-a*f, a, f))  # heap化されたリストhqに要素xを追加

for _ in range(K):
    _, a, f = heapq.heappop(hq)  # heap化されたリストhqから最小値を削除＆その最小値を出力
    a -= 1
    heapq.heappush(hq, (-a*f, a, f))  # heap化されたリストhqに要素xを追加

print(max(0, -min(hq)[0]))


### FIXED CODE ###

N, K = map(int, input().split())
A = sorted([int(i) for i in input().split()])
F = sorted([int(i) for i in input().split()], reverse=True)

if sum(A) <= K:
    print(0)
    exit()
else:
    OK = 10**12
    NG = -1

    while OK-NG > 1:
        mid = (OK+NG)//2
        cnt = 0

        for i, a in enumerate(A):
            cnt += max(0, a-mid//F[i])
        if cnt <= K:
            OK = mid
        else:
            NG = mid

print(OK)
### BUGGY CODE ###

from collections import Counter
n = int(input())
s = input()
c = Counter(s)
rgb = set(['R', 'G', 'B'])
ans = c['R']*c['G']*c['B']
for i in range(n-2):
    for j in range(i+1, n-1):
        x, y = s[i], s[j]
        if x == y:
            continue
        if n <= 2*j-i:
            continue
        z = s[2*j-i]
        if {x, y, z} == rgb:
            ans -= 1

print(ans)


### FIXED CODE ###

from collections import Counter
from operator import mul
n = int(input())
s = input()
c = Counter(s)
if n < 3:
    print(0)
    exit()
elif len(c.keys()) < 3:
    print(0)
    exit()
ans = 0
for i in range(n):
    x = s[i]
    ans += mul(*[v for k, v in c.items()if k != x])
    c[x] -= 1
    for j in range(i+1, n):
        y = s[j]
        if x == y:
            continue
        idx_diff = j-i
        if n <= j+idx_diff:
            continue
        z = s[j+idx_diff]
        if x != z and y != z:
            ans -= 1
print(ans)
### BUGGY CODE ###

n = int(input())
s = input()

def z_algorithm(str):
    len_str = len(str)
    p = [0] * len_str
    j = 0
    for i in range(1, len_str):
        if i + p[i-j] < j + p[j]:
            p[i] = p[i-j]
        else:
            k = max(0, j+p[j]-i)
            while i + k < len_str and str[k] == str[i+k] and k < i:
                k += 1
            p[i] = k
            j = i
    p[0] = 0
    return max(p)

ans = 0
for i in range(n-1):
    ans = max(ans, z_algorithm(s[i:]))

print(ans)

### FIXED CODE ###

n = int(input())
s = input()

def z_algorithm(str):
    len_str = len(str)
    p = [0] * len_str
    j = 0
    for i in range(1, len_str):
        if i + p[i-j] < j + p[j]:
            p[i] = p[i-j]
        else:
            k = max(0, j+p[j]-i)
            while i + k < len_str and str[k] == str[i+k]:
                k += 1
            p[i] = k
            j = i
    p[0] = len_str
    return p

ans = 0
for x in range(n):
    temp = [] + z_algorithm(s[x:])
    for y in range(n - x):
        z = min(temp[y], y)
        ans = max(ans, z)

print(ans)
### BUGGY CODE ###

#
from collections import deque

import sys
input = sys.stdin.readline


def main():
    n, m = map(int, input().split())

    edges = [[] for _ in range(n + 1)]

    for _ in range(m):
        u, v = map(int, input().split())
        edges[u].append(v)
    # print(edges)

    s, t = map(int, input().split())

    def next_kenp(node, edges, dones):
        nodes = set()
        nodes2 = set()

        for n1 in edges[node]:
            for n2 in edges[n1]:
                if n2 not in nodes2:
                    nodes2.add(n2)

        for nn in nodes2:
            for n3 in edges[nn]:
                if n3 in dones or n3 in nodes:
                    continue
                nodes.add(n3)
        return nodes

    dones = set()
    que = deque()
    que.append((s, 0))
    while que:
        node, step = que.popleft()
        next_nodes = next_kenp(node, edges, dones)
        for n in next_nodes:
            if n == t:
                print(step + 1)
                exit()

            que.append((n, step + 1))
            dones.add(n)

    print(-1)


if __name__ == '__main__':
    main()


### FIXED CODE ###

#
import itertools
from collections import Counter
from collections import defaultdict
from collections import deque
import bisect
from heapq import heappush, heappop


def main():
    n, m = map(int, input().split())

    edges = defaultdict(list)

    for _ in range(m):
        u, v = map(int, input().split())
        edges[(u, 0)].append((v, 1))
        edges[(u, 1)].append((v, 2))
        edges[(u, 2)].append((v, 0))

    s, t = map(int, input().split())

    # print(new_edges)

    dones = set()
    que = deque()
    que.append(((s, 0), 0))
    while que:
        node, step = que.popleft()

        next_nodes = edges[node]
        # print(next_nodes)
        for n, l in next_nodes:
            if n == t and l == 0:
                print((step + 1) // 3)
                exit()

            if (n, l) not in dones:
                que.append(((n, l), step + 1))
                dones.add((n, l))
    print(-1)


if __name__ == '__main__':
    main()
### BUGGY CODE ###

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

tmp = input().split()
hoge = list(map(lambda a: int(a), tmp))
n=hoge[0]
y=hoge[1]

max10=y//10000
max5=y//5000
max1=y//1000

flg=0
for i in range(0,max10+1):
	for j in range(0,max5+1):
		for k in range(0,max1+1):
			if(i+j+k==n)and(i*10000+j*5000+k*1000==y):
				flg=1
				break
		else:
			continue
		break
	else:
		continue
	break
if flg:
	print("{} {} {}".format(i,j,k))
else:
	print("-1 -1 -1")




### FIXED CODE ###

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

tmp = input().split()
hoge = list(map(lambda a: int(a), tmp))
n=hoge[0]
y=hoge[1]

max10=y//10000
max5=y//5000
max1=y//1000

flg=0
for i in range(0,max10+1):
	for j in range(0,max5+1):
		k=n-i-j
		if(k>=0)and(i*10000+j*5000+k*1000==y):
			flg=1
			break
	else:
		continue
	break
if flg:
	print("{} {} {}".format(i,j,k))
else:
	print("-1 -1 -1")
### BUGGY CODE ###

def f():
    n,k=map(int,input().split())
    l=list(map(int,input().split()))
    now=1

    for i in range(k.bit_length()):
        if k and k%2:now=l[now-1]
        l=[l[l[i]-1]for i in range(n)]
        k//=2
    print(now)
if __name__ == "__main__":
    f()

### FIXED CODE ###

n,k=map(int,input().split())
a=list(map(int,input().split()))
ok=set()
now=0
l=[]
while now not in ok and k:
    l.append(now)
    ok.add(now)
    now=a[now]-1
    k-=1
if k==0:print(now+1);exit()
length=len(ok)-(h:=l.index(now))
l=l[h:]

k=(k)%length

print(l[k]+1)
### BUGGY CODE ###

n = int(input())
nums = [int(c) for c in str(n)]
nums.reverse()
a = [0]*2019
a[0] = 1
now = 0
for i, num in enumerate(nums):
    now = (now+num*(10**i)) % 2019
    a[now] += 1
sum = 0
for i in range(2019):
    sum += a[i]*(a[i]-1)//2
print(sum)

### FIXED CODE ###

n = int(input())
nums = [int(c) for c in str(n)]
nums.reverse()
a = [0]*2019
a[0] = 1
now = 0
pow10 = [1]*len(nums)
for i, num in enumerate(nums):
    if i < len(nums)-1:
        pow10[i+1] = pow10[i]*10 % 2019
for i, num in enumerate(nums):
    now = (now+num*pow10[i]) % 2019
    a[now] += 1
sum = 0
for i in range(2019):
    sum += a[i]*(a[i]-1)//2
print(sum)
### BUGGY CODE ###

import sys, re
from collections import deque, defaultdict, Counter
from math import ceil, sqrt, hypot, factorial, pi, sin, cos, radians
from itertools import permutations, combinations, product
from operator import itemgetter, mul
from copy import deepcopy
from string import ascii_lowercase, ascii_uppercase, digits

def input(): return sys.stdin.readline().strip()
def INT(): return int(input())
def MAP(): return map(int, input().split())
def LIST(): return list(map(int, input().split()))
sys.setrecursionlimit(10 ** 9)
INF = float('inf')
MOD = 10 ** 9 + 7

N = INT()
a = LIST()
count = 0
flag = 0
while flag == 0:	
	for i in range(len(a)):
		if a[i] % 2 == 0:
			a[i] /= 2
			count += 1
			break
	else:
		flag = 1
print(count)

### FIXED CODE ###

import sys, re
from collections import deque, defaultdict, Counter
from math import ceil, sqrt, hypot, factorial, pi, sin, cos, radians
from itertools import permutations, combinations, product
from operator import itemgetter, mul
from copy import deepcopy
from string import ascii_lowercase, ascii_uppercase, digits

def input(): return sys.stdin.readline().strip()
def INT(): return int(input())
def MAP(): return map(int, input().split())
def LIST(): return list(map(int, input().split()))
sys.setrecursionlimit(10 ** 9)
INF = float('inf')
MOD = 10 ** 9 + 7

N = INT()
a = LIST()
count = 0
flag = 0
"""
while flag == 0:
	print(a)
	for i in range(N):
		if a[i] % 2 == 0:
			a[i] = int(a[i]/2)
			count += 1
			break
	else:
		flag = 1
"""
for i in a:
    while i % 2 == 0:
        count += 1
        i /= 2
print(count)