Harryxun/stf_run huggingface dataset:
N, M, X = map(int,input().split())

C = list()
A = list()
for i in range(N):
	temp = list(map(int,input().split()))
	C.append(temp[0])
	A.append(temp[1:])	


MAX = 100000000000	

def func(cost,a,i):
	if min(a) >= X:
		return cost
	elif i == N:
		return MAX
	total_A = [x+y for (x,y) in zip(a,A[i])]
    
	return min(func(cost + C[i],total_A,i+1),func(cost,a,i+1))
	
ans = func(0,[0]*M,0)

if ans == MAX:
	print(-1)
else:
	print(ans)


### FIXED CODE ###

prev = input()
prev_l = list(prev)

now = input()
now_l = list(now)
n = len(now_l)

if now_l[:n-1] == prev_l:
    print("Yes")
else:
    print("No")
from itertools import combinations_with_replacement

def main():
    N, M, Q = map(int, input().split())
    qs = [list(map(int,input().split())) for _ in range(Q)]
    seq = [i for i in range(1,M+1)]
    C = combinations_with_replacement(seq, N)
    max_score = 0

    for A in C:
        A = sorted(A)
        score = 0
        for q in qs:
            if A[q[1]-1] - A[q[0]-1] == q[2]:
                score += q[3]
        max_score = max(score, max_score)
    print(max_score)

if __name__ == '__main__':
    main()

### FIXED CODE ###

K = int(input())
A,B = map(int,input().split())
i = 0

while True:
    if A <= K*i <=B:
        print('OK')
        break
    elif B < K*i:
        print('NG')
        break
    else:
        i += 1
from math import gcd
from collections import Counter, deque, defaultdict
from heapq import heappush, heappop, heappushpop, heapify, heapreplace, merge
from bisect import bisect_left, bisect_right, bisect, insort_left, insort_right, insort
from itertools import accumulate, product, permutations, combinations, combinations_with_replacement

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

c = Counter(S)
print(max(0, c["#"] - 1))

### FIXED CODE ###

from collections import Counter, deque, defaultdict
from heapq import heappush, heappop, heappushpop, heapify, heapreplace, merge
from bisect import bisect_left, bisect_right, bisect, insort_left, insort_right, insort
from itertools import accumulate, product, permutations, combinations, combinations_with_replacement
from collections import Counter, deque, defaultdict

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

mi = 10000000

c = Counter(S)
A = N - c["#"]
B = N - c["."]

l = 0
r = c["."]

for i in range(0, N):

    if S[i] == "#":
        l += 1
    else:
        r -= 1
    a = l + r
    if mi > a:
        mi = a

print(min(mi, A, B))
MOD = int(1e9 + 7)

N, K = map(int, input().split())
A = list(map(int, input().split()))
AA = sorted(A, key=lambda x: abs(x))
AAr = sorted(A, key=lambda x: abs(x), reverse=True)


ans = 1
if N == K:
    for a in A:
        ans *= a
        ans %= MOD
elif all([a < 0 for a in A]) and K % 2 == 1:
    for k in range(K):
        ans *= AA[k]
    ans %= MOD
else:
    AArk = AAr[:K]
    AArem = AAr[K:]
    # print(AAr)
    # print(AArk)
    for k in range(K):
        ans *= AAr[k]
    if ans > 0:
        ans %= MOD
    else:
        # 負を1つとり除き，非負を1つ加える
        neg1 = float("inf")
        for a in AArk:
            if a < 0 and abs(a) < abs(neg1):
                neg1 = a
        # 代わりに入れる
        pos1 = None
        for a in AArem:
            if a > 0:
                pos1 = a
                break
        # print(neg1, pos1)

        # 正を1つとり除き，負を1つ加える
        pos2 = float("inf")
        for a in AArk:
            if a > 0 and abs(a) < abs(pos2):
                pos2 = a
        if pos2 == float("inf"):
            ans = ans // neg1 * pos1
            ans %= MOD
        else:
            # 非負にする
            neg2 = None
            for a in AArem:
                if a < 0:
                    neg2 = a
                    break

            # (pos1, neg1) と (pos2, neg2) を比較
            ans1 = ans // neg1 * pos1
            ans2 = ans // pos2 * neg2
            ans = max(ans1, ans2)
            ans %= MOD

print(ans)

### FIXED CODE ###

N, K = map(int, input().split())
A = list(map(int, input().split()))
MOD = 10 ** 9 + 7

neg_a = sorted([a for a in A if a < 0], reverse=True)
pos_a = sorted([a for a in A if a >= 0])
ans = 1

if len(pos_a) == 0 and K % 2 == 1:
    for a in neg_a[:K]:
        ans = ans * a % MOD
    print(ans)
    exit()

while K > 0:
    if K == 1 or len(neg_a) <= 1:
        if len(pos_a) == 0:
            ans *= neg_a.pop()
        elif len(pos_a) > 0:
            ans *= pos_a.pop()
        K -= 1
    elif len(pos_a) <= 1:
        ans *= neg_a.pop() * neg_a.pop()
        K -= 2
    elif pos_a[-1] * pos_a[-2] > neg_a[-1] * neg_a[-2]:
        ans *= pos_a.pop()
        K -= 1
    else:
        ans *= neg_a.pop() * neg_a.pop()
        K -= 2
    ans %= MOD

print(ans)
listed = input().split()
mul = 1
maxi = 10**18
for num in listed:
  mul*=num
  if num == 0:
    print(mul)
  if num > maxi**18:
    print(mul)
print(mul)

### FIXED CODE ###

N = input()
listed = input().split()
mul = 1
for num in listed:
  num = int(num)
  if num == 0:
    mul = 0
    break
  if mul != -1:
    mul *= num
    if mul > 10**18:
      mul = -1
print(mul)
n,k=map(int,input().split())
A=sorted(map(int,input().split()))

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))%(10**9+7)
    return nCr[(n,r)]

ans=0
for i in range(n-k+1):
    ans+=cmb(n-1-i,n-k-i)*(A[-i-1]-A[i])%(10**9+7)
    ans%=10**9+7
print(ans)

### FIXED CODE ###

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

def cmb(n,r,mod):
    if (r<0 or r>n):
        return 0
    r=min(r,n-r)
    return g1[n]*g2[r]*g2[n-r]%mod

mod=10**9+7
N=10**5
g1=[1,1]
g2=[1,1]
inverse=[0,1]

for i in range(2,N+1):
    g1.append((g1[-1]*i)%mod)
    inverse.append((-inverse[mod%i]*(mod//i))%mod)
    g2.append((g2[-1]*inverse[-1])%mod)

ans=0
for i in range(n-k+1):
    ans+=cmb(n-1-i,k-1,10**9+7)*(A[-i-1]-A[i])%(10**9+7)
    ans%=10**9+7
print(ans)
def get_prime(n):
    max_p = int(n ** 0.5)
    p = 0  # 素数
    pl = []  # 素数リスト
    el = [i for i in range(2, n + 1)]  # 探索リスト
    D = [i for i in range(n + 1)]
    while p <= max_p:
        nxt = []
        p = el[0]
        pl.append(p)
        for e in el:
            if e % p == 0:
                D[e] = p
            else:
                nxt.append(e)
        el = nxt
    pl.extend(el)
    return D, pl


def f2(n, D):
    s = set()
    x = n
    while x > 1:
        p = D[x]
        s.add(p)
        x = x // p
    return s


from math import gcd
from collections import defaultdict


def is_nc(n, al):
    g = al[0]
    for i, a in enumerate(al):
        if i == 0:
            continue
        else:
            g = gcd(g, a)
            if g == 1:
                return False
    return True


def is_sc(n, al):
    D, pl = get_prime(max(al))
    count = {p: 0 for p in pl}
    for a in al:
        p_s = f2(a, D)
        for p in p_s:
            if count[p] == 1:
                return True
            else:
                count[p] += 1
    return False


n = int(input())
al = list(map(int, input().split()))
if is_nc(n, al):
    print('not coprime')
elif is_sc(n, al):
    print('setwise coprime')
else:
    print('pairwise coprime')


### FIXED CODE ###

def f1(n):
    max_p = int(n ** 0.5)
    p = 0  # 素数
    pl = []  # 素数リスト
    el = [i for i in range(2, n + 1)]  # 探索リスト
    D = [i for i in range(n + 1)]
    while p <= max_p:
        nxt = []
        p = el[0]
        pl.append(p)
        for e in el:
            if e % p == 0:
                D[e] = p
            else:
                nxt.append(e)
        el = nxt
    for e in el:
        D[e] = e
    pl.extend(el)
    return D, pl


def f2(n, D):
    s = set()
    x = n
    while x > 1:
        p = D[x]
        s.add(p)
        x = x // p
    return s


from math import gcd


def is_nc(n, al):
    g = al[0]
    for i, a in enumerate(al):
        if i == 0:
            continue
        else:
            g = gcd(g, a)
            if g == 1:
                return False
    return True


def is_sc(n, al):
    max_al = max(al)
    if max_al == 1:
        return False
    D, pl = f1(max_al)
    count = {p: 0 for p in pl}
    for a in al:
        p_s = f2(a, D)
        for p in p_s:
            if count[p] == 1:
                return True
            else:
                count[p] += 1
    return False


n = int(input())
al = list(map(int, input().split()))
if is_nc(n, al):
    print('not coprime')
elif is_sc(n, al):
    print('setwise coprime')
else:
    print('pairwise coprime')
# 配るDP
import math
import numpy as np
import copy
from collections import defaultdict, Counter
from itertools import product
from bisect import bisect_left, bisect_right

def s_inpl(): return map(int,input().split())
def inpl(): return list(map(int, input().split()))

N = int(input())
h = inpl()

INF = float('inf')

# 最小化問題なのでINFに初期化
dp = [ INF for _ in range(100010) ]

# 初期状態
dp[0] = 0

# ループ
for i in range(0, N):
    dp[i+1] = min(dp[i+1], dp[i] + abs(h[i+1] - h[i]))
    dp[i+2] = min(dp[i+2], dp[i] + abs(h[i+2] - h[i]))

print(dp[N-1])

### FIXED CODE ###

import math
import numpy as np
import copy
from collections import defaultdict, Counter
from itertools import product
from bisect import bisect_left, bisect_right

def s_inpl(): return map(int,input().split())
def inpl(): return list(map(int, input().split()))

N = int(input())
h = inpl()

INF = 10e11

# 最小化問題なのでINFに初期化
dp = [ INF for _ in range(100010) ]

# 初期状態
dp[0] = 0

# ループ
for i in range(1, N):
    dp[i] = min(dp[i], dp[i-1] + abs(h[i] - h[i-1]))
    if i > 1:
        dp[i] = min(dp[i], dp[i-2] + abs(h[i] - h[i-2]))

print(dp[N-1])
s = input()
t = input()
ss = s+s
NEXT = [[-1]*(len(s)+1) for _ in range(26)]
cur = [-1]*26
for i in range(len(ss)):
    char = ord(ss[i])-97
    if cur[char] < len(s):
        for j in range(cur[char],min(i,len(s))):
            NEXT[char][j+1] = i
            cur[char] = i
ans = 0
tmp = -1
for i in range(len(t)):
    char = ord(t[i])-97
    if NEXT[char][tmp+1] == -1:
        print(-1)
        exit()
    ans += NEXT[char][tmp+1]-tmp
    tmp = NEXT[char][tmp+1]
    if tmp >= len(s)+1:
        tmp -= len(s)
print(ans)


### FIXED CODE ###

s = input()
t = input()
ss = s+s
NEXT = [[-1]*(len(s)+1) for _ in range(26)]
cur = [-1]*26
for i in range(len(ss)):
    char = ord(ss[i])-97
    if cur[char] < len(s):
        for j in range(cur[char],min(i,len(s))):
            NEXT[char][j+1] = i
            cur[char] = i
ans = 0
tmp = -1
for i in range(len(t)):
    char = ord(t[i])-97
    if NEXT[char][tmp+1] == -1:
        print(-1)
        exit()
    ans += NEXT[char][tmp+1]-tmp
    tmp = NEXT[char][tmp+1]
    if tmp >= len(s):
        tmp -= len(s)
print(ans)
N, M = [int(nm) for nm in input().split()]
X = [int(x) for x in input().split()]

if N >= M:
  print(0)
else:
  X.sort()
  mn_X = X[0]
  for m in range(M):
    X[m] = X[m] - mn_X #一番座標が小さい点を原点とする

  DX = [] #隣り合う二点間の距離
  for mm in range(M-1):
    dx = X[mm+1] - X[mm] #隣り合う二点間の距離を求める
    DX.append(dx)
  #print(DX)
  
  DXX = list(tuple(DX))
  DXX.sort(reverse=True) #DXXのi=0,1,2,...,N-2、つまり大きい値を取ってきたい
  I = [] #「XをN個に分割するとき、どの座標で分割するか」
  for i in range(N-1):
    big_dx = DXX[i]
    idx = DX.index(big_dx)
    I.append(idx)
  I.sort()
  #print(I)
  
  #最初のコマは原点に置く
  move = X[I[0]] - 0
  #print(move)
  
  for j in range(0, N-2):
    move += (X[I[j+1]] - X[I[j]+1])
  #print(move)
  
  #最後のコマ
  move += (X[-1] - X[I[N-2]+1])
  
  print(move)

### FIXED CODE ###

N, M = [int(nm) for nm in input().split()]
X = [int(x) for x in input().split()]

if N >= M:
  print(0)
elif N == 1:
  ans = max(X) - min(X)
  print(ans)
else:
  X.sort()
  mn_X = X[0]
  for m in range(M):
    X[m] = X[m] - mn_X #一番座標が小さい点を原点とする

  DX = [] #隣り合う二点間の距離
  for mm in range(M-1):
    dx = X[mm+1] - X[mm] #隣り合う二点間の距離を求める
    DX.append(dx)
  #print(DX)
  
  DXX = list(tuple(DX))
  DXX.sort(reverse=True) #DXXのi=0,1,2,...,N-2、つまり大きい値を取ってきたい
  I = [] #「XをN個に分割するとき、どの座標で分割するか」
  for i in range(N-1):
    big_dx = DXX[i]
    idx = DX.index(big_dx)
    I.append(idx)
  I.sort()
  #print(I)
  
  #最初のコマは原点に置く
  move = X[I[0]] - 0
  #print(move)
  
  for j in range(0, N-2):
    move += (X[I[j+1]] - X[I[j]+1])
  #print(move)
  
  #最後のコマ
  move += (X[-1] - X[I[N-2]+1])
  
  print(move)
import math
a,b = map(int,input().split())
print(a*b//(math.gcd(a,b))) 

### FIXED CODE ###

import fractions
a,b = map(int,input().split())
print(a*b//(fractions.gcd(a,b)))
import sys


def _ia(): return map(int, sys.stdin.readline().strip().split())


def calc(arr, k):
    s = sum(arr)
    n = len(arr)
    flag = s > 0 and k > n

    kp = k % n if flag else k
    l = min(kp, n)

    cm = max(arr) if s <= 0 else 0
    for i in range(n):
        cn = 0
        for ki in range(i, i+l):
            cn += arr[ki % n]
            cm = max(cn, cm)

    if flag:
        return s * (k//n) + cm
    else:
        return cm


def main():
    n, k = _ia()
    p = list(map(lambda x: x-1, _ia()))
    c = list(_ia())

    f = [False] * n
    g = []
    for idx in range(n):
        if f[idx]:
            continue

        nxt = idx
        tmp = [c[nxt]]
        f[nxt] = True

        for _ in range(n):
            nxt = p[nxt]
            if nxt == idx:
                break
            tmp.append(c[nxt])
            f[nxt] = True

        g.append(tmp)

    return calc(g[1], k)

    # return max(calc(gi, k) for gi in g)


if __name__ == "__main__":
    print(main())


### FIXED CODE ###

import sys


def _ia(): return map(int, sys.stdin.readline().strip().split())


def calc(arr, k):
    s = sum(arr)
    n = len(arr)
    kp = k % n if s > 0 else k
    if kp == 0:
        kp = n

    ll = min(kp, n)
    cm = max(arr)
    for i in range(n):
        cn = 0
        for ki in range(i, i+ll):
            cn += arr[ki % n]
            cm = max(cn, cm)

    if s > 0:
        return s * ((k-1)//n) + cm
    else:
        return cm


def main():
    n, k = _ia()
    p = list(map(lambda x: x-1, _ia()))
    c = list(_ia())

    f = [False] * n
    g = []
    for idx in range(n):
        if f[idx]:
            continue

        nxt = idx
        tmp = [c[nxt]]
        f[nxt] = True

        for _ in range(n):
            nxt = p[nxt]
            if nxt == idx:
                break
            tmp.append(c[nxt])
            f[nxt] = True

        g.append(tmp)

    return max(calc(gi, k) for gi in g)


if __name__ == "__main__":
    print(main())
n=int(input())
a=list(map(int,input().split()))
plus=[a[i] for i in range(n) if a[i]>=0]
l_plus=len(plus)
minus=[a[i] for i in range(n) if a[i]<0]
l_minus=len(minus)
x_cal=[]
y_cal=[]
if n==2:
  a.sort()
  print(a[1]-a[0])
  print(a[0],a[1])
else:
  if plus!=[] and minus!=[]:
    x_cal.append(minus[0])
    for j in range(1,l_plus-1):
      x_cal.append(x_cal[-1]-plus[j])
    for k in range(1,l_plus):
      y_cal.append(plus[k])
    y_last=x_cal[-1]-y_cal[-1]
    x_cal.append(plus[0])
    for j in range(1,l_minus):
      x_cal.append(x_cal[-1]-minus[j])
    for k in range(1,l_minus):
      y_cal.append(minus[k])
    y_cal.append(y_last)
    print(x_cal[-1]-y_cal[-1])
    for ii in range(n-1):
      print(x_cal[ii],y_cal[ii])
  elif minus==[]:
    a.sort()
    print(sum(a)-2*a[0])
    x_cal.append(a[0])
    for ij in range(1,n-2):
      x_cal.append(x_cal[-1]-a[ij])
    for jj in range(0,n-2):
      y_cal.append(a[jj+1])
    y_cal.append(x_cal[-1]-y_cal[-1])
    x_cal.append(a[-1])
    for ii in range(n-1):
      print(x_cal[ii],y_cal[ii])
  else:
    a.sort()
    print(a[-1]*2-sum(a))
    x_cal.append(a[-1])
    for ij in range(1,n-2):
      x_cal.append(x_cal[-1]-a[ij])
    for jj in range(0,n-2):
      y_cal.append(a[jj+1])
    x_cal.append(x_cal[-1]-y_cal[-1])
    y_cal.append(a[0])
    for ii in range(n-1):
      print(x_cal[ii],y_cal[ii])

### FIXED CODE ###

n=int(input())
a=list(map(int,input().split()))
plus=[a[i] for i in range(n) if a[i]>=0]
l_plus=len(plus)
minus=[a[i] for i in range(n) if a[i]<0]
l_minus=len(minus)
x_cal=[]
y_cal=[]
if n==2:
  a.sort()
  print(a[1]-a[0])
  print(a[0],a[1])
else:
  if plus!=[] and minus!=[]:
    if l_plus>1:
      x_cal.append(minus[0])
    for j in range(1,l_plus-1):
      x_cal.append(x_cal[-1]-plus[j])
    for k in range(1,l_plus):
      y_cal.append(plus[k])
    if l_plus>1:
      y_last=x_cal[-1]-y_cal[-1]
    else:
      y_last=minus[0]
    x_cal.append(plus[0])
    for j in range(1,l_minus):
      x_cal.append(x_cal[-1]-minus[j])
    for k in range(1,l_minus):
      y_cal.append(minus[k])
    y_cal.append(y_last)
    print(x_cal[-1]-y_cal[-1])
    for ii in range(n-1):
      print(x_cal[ii],y_cal[ii])
  elif minus==[]:
    a.sort()
    print(sum(a)-2*a[0])
    x_cal.append(a[0])
    for ij in range(1,n-2):
      x_cal.append(x_cal[-1]-a[ij])
    for jj in range(0,n-2):
      y_cal.append(a[jj+1])
    y_cal.append(x_cal[-1]-y_cal[-1])
    x_cal.append(a[-1])
    for ii in range(n-1):
      print(x_cal[ii],y_cal[ii])
  else:
    a.sort()
    print(a[-1]*2-sum(a))
    x_cal.append(a[-1])
    for ij in range(1,n-2):
      x_cal.append(x_cal[-1]-a[ij])
    for jj in range(0,n-2):
      y_cal.append(a[jj+1])
    x_cal.append(x_cal[-1]-y_cal[-1])
    y_cal.append(a[0])
    for ii in range(n-1):
      print(x_cal[ii],y_cal[ii])
h,w=map(int,input().split())
for i in range(n):
    s=input()
    print(s)
    print(s)

### FIXED CODE ###

h,w=map(int,input().split())
for i in range(h):
    s=input()
    print(s)
    print(s)
N, M = map(int, input().split())
A_list = [[int(i) for i in input().split()] for i in range(N)] 

a = A_list[0].pop(0)
for i in range(1, N):
  a = set(a) & set(A_list[i].pop(0))

if len(a)==0:
  print(0)
else:
  print(a)

### FIXED CODE ###

N, M = map(int, input().split())
A_list = [[int(i) for i in input().split()] for n in range(N)] 

A_list[0].pop(0)
a = A_list[0]
for i in range(1, N):
  A_list[i].pop(0)
  a = set(a) & set(A_list[i])

if len(a)==0:
  print(0)
else:
  print(len(a))
N,K = map(int, input().split())

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

A.sort()

if A[-1] < K:
    print("IMPOSSIBLE")
    exit()

if K in A or 1 in A:
    print("POSSIBLE")
    exit()

def gcd(a,b):
    x = max([a,b])
    y = min([a,b])
    while y:
        x, y = y, x % y
    return x

g = A[0]
for i in range(1,N):
    g = gcd(A[i], g)
    

print("POSSIBLE" ig K % g == 9 else "IMPOSSIBLE")

### FIXED CODE ###

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

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

A.sort()

if A[-1] < K:
    print("IMPOSSIBLE")
    exit()

if K in A or 1 in A:
    print("POSSIBLE")
    exit()

def gcd(a,b):
    x = max([a,b])
    y = min([a,b])
    while y:
        x, y = y, x % y
    return x

g = A[0]
for n in A[1:]:
    g = gcd(n, g)
    

print("POSSIBLE" if K % g == 0 else "IMPOSSIBLE")
import sys
def LI(): return [int(x) for x in sys.stdin.readline().split()]
def LI_(): return [int(x) - 1 for x in sys.stdin.readline().split()]
def LF(): return [float(x) for x in sys.stdin.readline().split()]
def LS(): return sys.stdin.readline().split()
def II(): return int(sys.stdin.readline())
def SI(): return int(input())
from collections import defaultdict, Counter
import bisect

sys.setrecursionlimit(10000000000)

n = SI()
xy = [(0,0) for _ in range(n)]
div = []
for i in range(n):
    x, y = LI()
    xy[i] = (x, y)
for i in range(n):
    for j in range(n):
        if i == j:
            continue
        else:
            div.append("{}_{}".format(xy[i][0] - xy[j][0], xy[i][1]- xy[j][1]))
c = Counter(div)
max_ = c.most_common()[0][1]
print(n - max_)

### FIXED CODE ###

import sys
def LI(): return [int(x) for x in sys.stdin.readline().split()]
def LI_(): return [int(x) - 1 for x in sys.stdin.readline().split()]
def LF(): return [float(x) for x in sys.stdin.readline().split()]
def LS(): return sys.stdin.readline().split()
def II(): return int(sys.stdin.readline())
def SI(): return int(input())
from collections import defaultdict, Counter
import bisect

sys.setrecursionlimit(10000000)

n = SI()
xy = [(0,0) for _ in range(n)]
div = defaultdict(int)
for i in range(n):
    x, y = LI()
    xy[i] = (x, y)
if n==1:
    print(1)
else:
    for i in range(n):
        for j in range(n):
            if i == j:
                continue
            else:
                div["{}_{}".format(xy[i][0] - xy[j][0], xy[i][1]- xy[j][1])] += 1

    max_ = max(div.values())
    print(n - max_)
N, K = map(int, input().split())
X = list(map(int, input().split()))
town = []
dic = {}
i = 0
j = 0
while i not in dic and j < K:
    dic[i] = j
    town.append(i)
    i = X[i] - 1
    j += 1

if j == K:
    print(town[K] + 1)

else:
    num = town.index(i)
    loop = j - num
    print(town[(K - num) % loop + num]+1)


### FIXED CODE ###

N, K = map(int, input().split())
X = list(map(int, input().split()))
town = []
dic = {}
i = 0
j = 0
while i not in dic and j < K:
    dic[i] = j
    town.append(i)
    i = X[i] - 1
    j += 1

if j == K:
    print(i + 1)

else:
    num = dic[i]
    loop = j - num
    print(town[((K - num) % loop) + num] + 1)
if (a*b)%2 == 0:
    print(Even)
  else:
    print(Odd)

### FIXED CODE ###

a, b = map(int, input().split())

if (a*b % 2 == 0):
  print('Even')
else:
  print('Odd')
import numpy as np
import math
import sys
sys.setrecursionlimit(10000000)
from math import gcd

def lcm(a, b):
    return int(a * b / gcd(a, b))

def main():
    A, B, C, D = [int(c) for c in input().split()]
    N_U = (B) - (A - 1)
    N_C = B // C - (A - 1) // C
    N_D = B // D - (A - 1) // D
    N_C_D = int(B // lcm(C, D) - (A - 1) // lcm(C, D))
    excluded_N_C_D = N_C + N_D - N_C_D
    print(int(N_U - excluded_N_C_D))


if __name__ == '__main__':
    main()

### FIXED CODE ###

import numpy as np
import math
import sys
sys.setrecursionlimit(10000000)

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

def lcm(a, b):
    return int(a * b / gcd(a, b))

def main():
    A, B, C, D = [int(c) for c in input().split()]
    N_U = (B) - (A - 1)
    N_C = B // C - (A - 1) // C
    N_D = B // D - (A - 1) // D
    N_C_D = int(B // lcm(C, D) - (A - 1) // lcm(C, D))
    excluded_N_C_D = N_C + N_D - N_C_D
    print(int(N_U - excluded_N_C_D))


if __name__ == '__main__':
    main()
N, M = map(int, input().split())
#A = [int(input()) for i in range(M)]
flag = [0]*N
for i in range(M):
    flag[int(input())-1] = 1
#A = [i*3 for i in range(N//3)]
#for i in range(N//3):
    #flag[i] = 1

mod = 10**9+7

dp = [0] * N

if flag[0]==0:
#if 1 not in A:
    dp[0] = 1
    if flag[1]==0 and N>1:
    #if (2 not in A) and N > 1:
        dp[1] = 2
elif N > 1:
    if flag[1]==0:
    #if 2 not in A:
        dp[1] = 1
    else:
        dp[1] = 0

loop = []
'''
for i in range(2, N):
    if i not in A:
        loop.append(i)
'''
for i in range(2, N):
    if flag[i]==0:
        dp[i] = (dp[i-2] + dp[i-1]) % mod
        #dp[i] = (sum(dp[i-2:i])) % mod

print(dp[N-1])
#print(dp)

### FIXED CODE ###

N, M = map(int, input().split())
#A = [int(input()) for i in range(M)]
flag = [0]*N
for i in range(M):
    flag[int(input())-1] = 1
#A = [i*3 for i in range(N//3)]
#for i in range(N//3):
    #flag[i] = 1

mod = 10**9+7

dp = [0] * N

if flag[0]==0:
#if 1 not in A:
    dp[0] = 1
    if N>1:
        if flag[1]==0:
    #if (2 not in A) and N > 1:
            dp[1] = 2
elif N > 1:
    if flag[1]==0:
    #if 2 not in A:
        dp[1] = 1
    else:
        dp[1] = 0

loop = []
'''
for i in range(2, N):
    if i not in A:
        loop.append(i)
'''
for i in range(2, N):
    if flag[i]==0:
        dp[i] = (dp[i-2] + dp[i-1]) % mod
        #dp[i] = (sum(dp[i-2:i])) % mod

print(dp[N-1])
#print(dp)