Harryxun/stf_run huggingface dataset:
X, Y = map(int, input().split())
mod = 10**9 + 7

if (X + Y) % 3 != 0:
    print(0)
else:
    n2x = (2*X - Y) // 3
    n1x = (2*Y - X) // 3
    n = n2x + n1x

    # nCn2xを求める
    def combs(n,n2x):
        facs = [1] * (n+1)
        invs = [1] * (n+1)
        nfac = 1
        for i in range(1, n+1):
            nfac = nfac * i % mod
            facs[i] = nfac
            invs[i] = pow(facs[i], mod-2, mod)
        return facs[n] * invs[n2x] * invs[n-n2x] % mod

    print(combs(n, n2x))


### FIXED CODE ###

X, Y = map(int, input().split())
mod = 10**9 + 7

if (X + Y) % 3 != 0 or X > 2*Y or Y > 2*X:
    print(0)
else:
    n2x = (2*X - Y) // 3
    n1x = (2*Y - X) // 3
    n = n2x + n1x

    # nCn2xを求める
    def combs(n,n2x):
        invs = [1] * (n+1)
        nfac = 1
        for i in range(1, n+1):
            nfac = nfac * i % mod
            invs[i] = pow(nfac, mod-2, mod)
        return nfac * invs[n2x] * invs[n-n2x] % mod

    print(combs(n, n2x))
import sys
sys.setrecursionlimit(10000)

def dfs(v):
    global node_chk
    global edge_chk
    global B
    global connect
    global value

    node_chk[v] = 1
    connect[v] = value
    for x in B[v]:
        if(node_chk[x] == 0):
                dfs(x)



n,m = map(int,input().split())
B = [[]for i in range(n)] # 隣接リスト
edge_chk = [[]for i in range(n)]
node_chk = [0 for i in range(n)]
connect = [0 for i in range(n)]
value = 0

for i in range(m):
    A = list(map(int,input().split()))
    B[A[0]].append(A[1])
    B[A[1]].append(A[0])
    edge_chk[A[0]].append(0)
    edge_chk[A[1]].append(0)

for i in range(n):
    if(node_chk[i] == 1):
        continue
    dfs(i)
    value += 1


q = int(input())
for i in range(q):
    start,target = map(int,input().split())
    if(connect[start] == connect[target]):
        print("yes")
    else:
        print("no")


### FIXED CODE ###

import sys
sys.setrecursionlimit(200000)

def dfs(v):
    global node_chk
    global B
    global connect
    global value

    node_chk[v] = 1
    connect[v] = value
    for x in B[v]:
        if(node_chk[x] == 0):
                dfs(x)



n,m = map(int,input().split())
B = [[]for i in range(n)] # 隣接リスト
node_chk = [0 for i in range(n)]
connect = [0 for i in range(n)]
value = 0

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

for i in range(n):
    if(node_chk[i] == 1):
        continue
    dfs(i)
    value += 1


q = int(input())
for i in range(q):
    start,target = map(int,input().split())
    if(connect[start] == connect[target]):
        print("yes")
    else:
        print("no")
from sys import stdin
import sys
import itertools
import array
import textwrap
import math

N = int(input())
X = input()
temp = X.count("1")
t = [0, 0, 0]
t[0] = int(X, 2) % (temp-1)
# t[1] = int(X, 2) % (temp)
t[2] = int(X, 2) % (temp+1)
# print(X)
cnt = 0
# X = int(X, 2)
# print(X)
for i in range(N):
    if X[i] == "1":
        p = (1 << (N-i-1)) % (temp-1)
        a = (t[0]-p) % (temp-1)
    elif X[i] == "0":
        m = (1 << (N-i-1)) % (temp+1)
        a = (t[2]+m) % (temp+1)
    cnt = 1
    # print(a)
    while a > 0:
        a = a % str(bin(a)).count("1")
        # print(a)
        cnt += 1
    print(cnt)


### FIXED CODE ###

N = int(input())
X = input()
temp = X.count("1")
t = [0, 0, 0]

t[0] = int(X, 2) % (temp-1) if temp != 1 else 0
t[2] = int(X, 2) % (temp+1)
cnt = 0
for i in range(N):
    if X[i] == "1" and temp == 1:
        print(0)
        continue
    if X[i] == "1":
        # p = (1 << (N-i-1)) % (temp-1)
        p = pow(2, N-1-i, temp-1)
        a = (t[0]-p) % (temp-1)
    elif X[i] == "0":
        # m = (1 << (N-i-1)) % (temp+1)
        m = pow(2, N-1-i, temp+1)
        a = (t[2]+m) % (temp+1)
    cnt = 1
    while a > 0:
        a = a % format(a, 'b').count("1")
        cnt += 1
    print(cnt)
n=int(input())
c=list(map(int,input().split()))
q=int(input())
su=0
w={}
for i in range(len(c)):
	su=su+c[i]
	if(c[i] not in w):
		w[c[i]]=1
	else:
		w[c[i]]=w[c[i]]+1
for j in range(q):
	r,s=map(int,input().split())
	count=w[r]
	if(s in w):
		w[s]=w[s]+count
	else:
		w[s]=count
	su=su-count*r+count*s
	print(su)



### FIXED CODE ###

n=int(input())
c=list(map(int,input().split()))
q=int(input())
su=0
d=[]
for i in range(1000003):
	d.append(0)
for i in range(len(c)):
	d[c[i]]=d[c[i]]+1
	su=su+c[i]
for j in range(q):
	r,s=map(int,input().split())
	su=su-d[r]*r+d[r]*s
	d[s]=d[s]+d[r]
	d[r]=0
	print(su)
for i in range(N-1):
  if li[i] == li[i+1]:
    b += 1
  else:
    a += 1
for j in range(K):
  if a >= 2:
    a -= 2
    b += 2
  elif a == 1:
    a -= 1
    b += 1
  else:
    break
print(b)

### FIXED CODE ###

N, K = map(int, input().split())
li = list(input())
a = 0
b = 0
for i in range(N-1):
  if li[i] == li[i+1]:
    b += 1
  else:
    a += 1
for j in range(K):
  if a >= 2:
    a -= 2
    b += 2
  elif a == 1:
    a -= 1
    b += 1
  else:
    break
print(b)
n = int(input())
a = []
s = [1]
t = 1
ans = 0
for i in range(n):
  a.append(int(input())
while t != 2:
  t = a[t-1]
  s.append(t)
  if s.count(t) == 2:
    ans = -1
    break
  ans += 1
print(ans)
  

### FIXED CODE ###

import sys 
N = list(map(int, sys.stdin))
bot = N[1]
for i in range(N[0]):
  if bot == 2:
    print(i+1)
    break
  bot = N[bot]
else:
  print(-1)
n = int(input)
count = 0
tenwari = n%10
baiwari = n%100
ichi = tenwari
jyu = (baiwari-tenwari)//10
hyaku = (n-jyu*10-ichi)//100

if ichi != 7:
  count = count + 1
if jyu != 7:
  count = count + 1
if hyaku != 7:
  count = count + 1
  
if count ==0:
  print('Yes')
else:
  print('No')


### FIXED CODE ###

n = int(input())
count = 0
tenwari = n%10
baiwari = n%100
ichi = tenwari
jyu = (baiwari-tenwari)//10
hyaku = (n-jyu*10-ichi)//100

if ichi != 7:
  count = count + 1
if jyu != 7:
  count = count + 1
if hyaku != 7:
  count = count + 1
  
if count == 3:
  print('No')
else:
  print('Yes')
N, X = list(map(int, input().split()))
bounds = list(map(int, input().split()))

zahyos = [0]
for i, bound in enumerate(bounds):
    zahyo = zahyos[i] + bound
    zahyos.append(zahyo)
    
cnt = 0
zahyo = 0
index = 0
while zahyo <= X:
    cnt += 1
    index += 1
    zahyo = zahyos[index]
    
print(cnt)

### FIXED CODE ###

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

zahyos = [0]
for i, bound in enumerate(bounds):
    zahyo = zahyos[i] + bound
    zahyos.append(zahyo)
    
cnt = 0
for num in zahyos:
    if num <= X:
        cnt += 1
    
print(cnt)
throw = []
blow = 0
cnt = 0
n,h = map(int, input().split())
for _ in range(n):
  a,b = map(int, input().split())
  blow = max(blow,a)
  throw.append(b)
throw.sort()
while h and throw[-1]>blow:
  h -= throw.pop()
  cnt += 1
if h > 0:
  cnt += h//blow + (h%blow>0)
print(cnt)  

### FIXED CODE ###

throw = []
blow = 0
cnt = 0
n,h = map(int, input().split())
for _ in range(n):
  a,b = map(int, input().split())
  blow = max(blow,a)
  throw.append(b)
throw.sort()
while h>0 and throw and throw[-1]>blow:
  h -= throw.pop()
  cnt += 1
if h > 0:
  cnt += h//blow + (h%blow>0)
print(cnt)
num=list(map(int,input().split()))
odd_num=[]
even_num=[]
count=0
for i in num:
    if i%2!=0:
        count+=1
        odd_num+=[i]
    else:
        even_num+=[i]

if count==1:
    if max(odd_num)>max(even_num):
        ans=abs(even_num[0]-even_num[1])//2+ood_num[0]-max(even_num)
        print(ans)
    else:
        ans=abs(even_num[0]-even_num[1])//2+1+(max(even_num)+1-odd_num[0])//2
        print(ans)
elif count==2:
    if max(odd_num)>max(even_num):
        ans=even_num[0]-max(odd_num)+abs(odd_num[0]-odd_num[1])//2
        print(ans)
    else:
        ans=abs(odd_num[0]-odd_num[1])//2+even_num-max(odd_num)
        print(ans)
else:
    if count==3:
        ans=(3*max(odd_num)-sum(odd_num))//2
        print(ans)
    else:
        ans=(3*max(even_num)-sum(even_num))//2
        print(ans)

### FIXED CODE ###

a=list(map(int,input().split()))
a=sorted(a)
maxim=a[-1]
for i in range(3):
    a[i]=a[-1]-a[i]

ans=a[1]+(a[0]-a[1])//2 if (a[0]-a[1])%2==0 else a[1]+(a[0]-a[1])//2+2
print(ans)
S=input()
for i in S.len():
  S[:2*i+1]+"1"+S[2*i+1:]
print(eval(S))

### FIXED CODE ###

S=input()
for i in range(len(S)):
  S=S[:2*i+1]+"1"+S[2*i+1:]
print(eval("0"+S))
print("YNeos"[len(set(input())>1)::2])

### FIXED CODE ###

print("YNeos"[len(set(input()))<2::2])
import itertools
from sys import stdin
N,A,B,C,D=[int(x) for x in stdin.readline().rstrip().split()]
S=(stdin.readline().rstrip())
lst = [1 if i == "#" else 0 for i in list(S)]
cumsum = itertools.accumulate(lst)
cumsum = [0] + list(cumsum) 

flag = True
flag_oinuki = False
for i in range(0,(len(cumsum) - 2)):
    if cumsum[i+2] - cumsum[i] == 2 and j+2 <= D:
        flag = False
        break
for j in range(0,(len(cumsum) - 3)):
    if cumsum[j] == cumsum[j+3]:
        flag_oinuki = True

if C > D:
    if flag_oinuki and flag:
        print("Yes")
    else:
        print("No")
else:
    if flag:
        print("Yes")
    else:
        print("No")

### FIXED CODE ###

import itertools
from sys import stdin
N,A,B,C,D=[int(x) for x in stdin.readline().rstrip().split()]
S=(stdin.readline().rstrip())
lst = [0] + [1 if i == "#" else 0 for i in list(S)]
cumsum = itertools.accumulate(lst)
cumsum = list(cumsum) 
 
flag = True
flag_oinuki = False
for i in range(A,(len(cumsum) - 2)):
    if ((cumsum[i+2] - cumsum[i]) == 2) and A <= i <= (max(C,D)-1):
        flag = False
        break
for j in range(A,(len(cumsum) - 3)):
    if cumsum[j] == cumsum[j+3] and (B <= j + 2 <= D):
        flag_oinuki = True
 
if C > D:
    if flag_oinuki and flag:
        print("Yes")
    else:
        print("No")
else:
    if flag:
        print("Yes")
    else:
        print("No")
import sys
sys.setrecursionlimit(200000)
N, M = map(int, input().split())
if N == 1:
    print(1) 
    
elif M == 0:
    print(dp[N-1])
    
else:
    dp = [0]*N
    dp[0] = 1
    dp[1] = 2
    for i in range(N-2):
        dp[i+2] = dp[i]+dp[i+1]
        
    a = [int(input()) for _ in range(M)]
    
    for i in range(M-1):
        if a[i+1] == a[i] + 1:
            ans = 0
            break
    else:
        if a[0] == 1:
            ans == 1
        else:
            ans = dp[a[0]-2]
                
    for i in range(M-1):
        if a[i+1]-a[i] >= 3:
            ans *= dp[a[i+1]-a[i]-3]
    if N-a[M-1]-2 >= 0:
        ans *= dp[N-a[M-1]-2] 
    print(ans%1000000007)

### FIXED CODE ###

N, M = map(int, input().split())
a = [int(input()) for _ in range(M)]
dp = [0]*(N+1)
for i in a:
    dp[i] = -1

for i in range(N+1):
    if dp[i] == -1:
        dp[i] = 0
    elif i > 1:
        dp[i] = dp[i-1] + dp[i-2]
    else:
        dp[i] = 1
        
print(dp[N]%1000000007)
a = input()
print(a + a**2 +a**3)

### FIXED CODE ###

a = int(input())
print(a+a**2+a**3)
import sys

def parent(i):
    return (i + 1) / 2 - 1

def left(i):
    return 2 * i + 1

def right(i):
    return 2 * i + 2

def sibling(i):
    if i % 2 == 0:
        return i - 1
    else:
        return i + 1

def insert(S, k):
    S.append(k)
    now = len(S) - 1
    while True:
        p = parent(now)
        if p < 0:
            break
        elif S[now] > S[p]:
            S[now], S[p] = S[p], S[now]
        else:
            now = p

def extract(S):
    print S[0]
    S[0] = S[-1]
    S.pop()

    now = 0
    while True:
        l, r = left(now), right(now)
        if l < len(S):
            if r >= len(S) or S[now] < S[r] and S[l] < S[r]:
                S[now], S[r] = S[r], S[now]
                now = left
            elif S[now] < S[l] and S[r] < S[l]:
                S[now], S[r] = S[r], S[now]
                now = r
        else:
            break

if __name__ == "__main__":
    lines = sys.stdin.readlines()
    lines.pop()

    S = []
    for line in lines:
        if line[0] == "i":
            insert(S, int(line[7:]))
        else:
            extract(S)

### FIXED CODE ###

import sys

def insert(k):
    global S, last
    S[last] = k
    idx = last
    while True:
        p = (idx + 1) / 2 - 1
        if S[idx] <= S[p]:
            break
        else:
            S[idx], S[p] = S[p], S[idx]
            idx = p
    last += 1

def maxHeapify(i):
    global S, last
    l = 2 * i + 1
    r = 2 * i + 2

    if l < last and S[l] > S[i]:
        largest = l
    else:
        largest = i

    if r < last and S[r] > S[largest]:
        largest = r

    if largest != i:
        S[i], S[largest] = S[largest], S[i]
        maxHeapify(largest)

def extract():
    global S, last
    print S[0]
    last -= 1
    S[0], S[last] = S[last], 0
    maxHeapify(0)

lines = sys.stdin.readlines()
lines.pop()

S = [0] * 2000001
S[2000000] = 2000000000
last = 0
for line in lines:
    if line[0] == "i":
        insert(int(line[7:]))
    else:
        extract()
W, H, x, y, r = map(int, raw_input().split())
if r <= x and r <= y and r + y <= H and r + x <= W 
print "Yes"
else:
print "No"

### FIXED CODE ###

W, H, x, y, r = map(int, raw_input().split())
if r <= x and r <= W - x and r <= y and r <= H - y:
   print 'Yes'
else:
   print 'No'
if B<=0:
    if A+B<=A*B:
        print(A*B);
    else:
        print(A+B);
else:
    if A-B<=A*B:
        print(A*B);
    else:
        print(A-B);

### FIXED CODE ###

l=input().split()
a=int(l[0])
b=int(l[1])

sum=a+b
sub=a-b
multi=a*b
if ((sum>=sub)and(sum>=multi)):
    print(sum)
elif((sub>sum)and(sub>multi)):
    print(sub)
else:
    print(multi)
S = input()
if S[0] == S [1]:
	if S[2] == S[3]:
		print("Yes")
	else:
		print("No")
elif S[0] == S[2]:
	if S[1] == S[3]:
		print("Yes")
	else:
		print("No")
elif S[0] == S[3]:
	if S[1] == S[2]:
		print("Yes")
	else:
		print("No")
else:

### FIXED CODE ###

S = input()
if S[0]==S[1]==S[2]==S[3]:
	print("No")
else:
	if S[0] == S [1]:
		if S[2] == S[3]:
			print("Yes")
		else:
			print("No")
	elif S[0] == S[2]:
		if S[1] == S[3]:
			print("Yes")
		else:
			print("No")
	elif S[0] == S[3]:
		if S[1] == S[2]:
			print("Yes")
		else:
			print("No")
	else:
		print("No")
# -*- coding: utf-8 -*-
"""
AtCoder A
"""

import sys, math, random
import numpy as np

# N = int(input())
# A = list(map(int,input().split())) # N row 1 column
# A = [int(input()) for _ in range(N)] # 1 row N column
# S = str(input()) # str(input()) == input() -> 'abc'
# S = list(input()) # abc -> ['a','b','c']
# S.replace('ABC','X') # "testABCABC" -> "testXX"
 
inf = 10**20
eps = 1.0 / 10**10
mod = 10**9+7
dd = [(-1,0),(0,1),(1,0),(0,-1)]
ddn = [(-1,0),(-1,1),(0,1),(1,1),(1,0),(1,-1),(0,-1),(-1,-1)]
 
def LI(): return list(map(int, sys.stdin.readline().split()))
def LLI(): return [list(map(int, l.split())) for l in sys.stdin.readlines()]
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 I(): return int(sys.stdin.readline())
def F(): return float(sys.stdin.readline())
def S(): return input()

def P(n, r):
    return math.factorial(n)//math.factorial(n-r)

def C(n, r):
    return P(n, r)//math.factorial(r)

def main():
    N, K = list(map(int,input().split()))
    for k in range(K):
        tmp= C(N-K+1,k+1)
        tmp2=C(K-1,k)
        print(tmp*tmp2%mod)
    
if __name__ == "__main__":
    main()

### FIXED CODE ###

# -*- coding: utf-8 -*-
"""
AtCoder A
"""

import sys, math, random
import numpy as np

# N = int(input())
# A = list(map(int,input().split())) # N row 1 column
# A = [int(input()) for _ in range(N)] # 1 row N column
# S = str(input()) # str(input()) == input() -> 'abc'
# S = list(input()) # abc -> ['a','b','c']
# S.replace('ABC','X') # "testABCABC" -> "testXX"
 
inf = 10**20
eps = 1.0 / 10**10
mod = 10**9+7
dd = [(-1,0),(0,1),(1,0),(0,-1)]
ddn = [(-1,0),(-1,1),(0,1),(1,1),(1,0),(1,-1),(0,-1),(-1,-1)]
 
def LI(): return list(map(int, sys.stdin.readline().split()))
def LLI(): return [list(map(int, l.split())) for l in sys.stdin.readlines()]
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 I(): return int(sys.stdin.readline())
def F(): return float(sys.stdin.readline())
def S(): return input()

def P(n, r):
    return math.factorial(n)//math.factorial(n-r)

def C(n, r):
    return P(n, r)//math.factorial(r)


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

def main():
    N, K = list(map(int,input().split()))
    for k in range(K):
        # print(N-K+1,k+1,K-1,k)
        if (N-K+1<k+1):
            print("0")
            continue
        tmp= cmb(N-K+1,k+1)
        tmp2=cmb(K-1,k)
        print(tmp*tmp2%mod)
    
if __name__ == "__main__":
    main()
import math
def lcm_base(x, y):
    return int((x * y) / math.gcd(x, y))
def lcm_list(numbers):
    answer=numbers[0]
    for number in numbers:
        answer=lcm_base(answer,number)
    return answer
nm=list(map(int, input().split()))
a=list(map(int, input().split()))
n=nm[0]
m=nm[1]
b=0
# while a[0]%2==0:
#     for i in range(len(a)):
#         if a[i]%2==0:
#             a[i]=int(a[i]/2)
#         else:
#             b=1
#             break
if b==1:
    print(0)
else:
    amc=lcm_list(a)
    print(int((m+amc)/(2*amc)))



### FIXED CODE ###

import fractions
from functools import reduce
def lcm_base(x, y):
    return (x * y) // fractions.gcd(x, y)
def lcm_list(numbers):
    return reduce(lcm_base, numbers, 1)
nm=list(map(int, input().split()))
a=list(map(int, input().split()))
n=nm[0]
m=nm[1]
b=0
c=a[0]
dnum=0
while c%2==0:
    dnum+=1
    c=c//2
for i in range(len(a)):
    c=a[i]
    dnum1=0
    while c%2==0:
        dnum1+=1
        c=c//2
    #print(dnum)
    if dnum1!=dnum:
        b=1
        break

#print(a)
if b==1:
    print(0)
else:
    for i in range(len(a)):
        a[i]=a[i]//2
    #print(a)
    amc=lcm_list(a)
    #print(amc)
    # version3.5にてgcdがfractionsからmathに移動した
    print(int((m+amc)/(2*amc)))
L = int(input())

    # 普通に立方体が一番大きい
    print(pow(L/3,3))


### FIXED CODE ###

L = int(input())

# 普通に立方体が一番大きい
print(pow(L/3,3))
from fractions import gcd
import sys
import math

read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines

n, m = map(int, readline().split())
a = list(map(int, readline().split()))

for i in range(n-1):
    a[i+1] = int(a[i] * a[i+1] / gcd(a[i], a[i+1]))

t = (a[n-1] // 2)
t = m // t
ans = math.ceil(t / 2)
print(ans)


### FIXED CODE ###

from fractions import gcd
from functools import reduce

import sys
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines
 
N, M, *A = map(int, read().split())
 
# 「奇数倍」に帰着
A = [x >> 1 for x in A]
 

def merge(a, b):
    g = gcd(a, b)
    a //= g
    b //= g
    if a % 2 == 0:
        return 0
    if b % 2 == 0:
        return 0
    n = a * b * g
    if n > 10 ** 9:
        return 0
    return n


x = reduce(merge, A)

if x == 0:
    answer = 0
else:
    answer = (M//x) - (M//(x+x))
 
print(answer)
n = int(input())
li = list(map(int, input().split()))

if 0 in li:
  print(0)
else:
  result = 1
  flag = True
  for i in range(n):
    result *= li[i]
    if result > 10 ** 18:
      flag = False
      print(-1)
      break
if flag == True:
  print(result)

### FIXED CODE ###

n = int(input())
li = list(map(int, input().split()))

if 0 in li:
  print(0)
else:
  result = 1
  flag = True
  for i in range(n):
    result *= li[i]
    if result > 10 ** 18:
      flag = False
      print(-1)
      break
  if flag == True:
    print(result)
N, K = map(int, input().split())
A = list(map(int, input().split()))

node = [0] * (N + 1)
index = 1
loop_flag = False

for i in range(1, N + 1):
    tmp = A[index - 1]
    if not node[tmp]:
        index = tmp
        node[index] += i
    else:
        pre = node[tmp]
        loop = index - node[tmp]
        if loop > 1:
            answer = node.index((K - pre) % loop + pre)
        else:
            answer = tmp
        loop_flag = True
        print(answer)
        break

if loop_flag:
    print(index)

### FIXED CODE ###

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

index = 1
route = [index]
node = {index}

for i in range(1, K + 1):
    index = A[index - 1]
    if index in node:
        pre = route.index(index)
        loop = len(route)
        route_idx = (K - pre) % (loop - pre) + pre
        print(route[route_idx])
        break
    else:
        route.append(index)
        node.add(index)
else:
    print(index)
N = int(input())
X = list(map(int, input().split()))
ans = 100 ** 100

for p in range(1, 101):
	now = 0
	for x in X:
		now += (p - x) ** 2
	ans = min(ans, now)
print(ans)


### FIXED CODE ###

N, K = list(map(int, input().split()))
ans = 0
while N > 0:
    N //= K
    ans += 1
print(ans)
H, W, K = map(int, input().split())
r = []
tmp = []
for i in range(W):
    r.append(0)
    tmp.append(0)
r[0] = 1
p = [1, 2, 4, 7, 12, 20]
ans = 0
for j in range(H):
    if W == 1 and K == 1:
        ans = 1
        break
    for i in range(W):
        u = i
        v = (W - 1) - i
        a, b, c, d = 1, 1, 1, 1
        if u >= 2:
            a += p[u - 2] 
        if v >= 2:
            b += p[v - 2]
        if u - 1 >= 2:
            c += p[u - 3]
        if v - 1 >= 2:
            d += p[v - 3]
        if i == 0:
            tmp[i] = r[i] * a * b + r[i + 1] * a * d
        elif i == (W - 1):
            tmp[i] = r[i - 1] * c * b + r[i] * a * b
        else:
            tmp[i] = r[i - 1] * c * b  + r[i] * a * b + r[i + 1] * a * d
    for i in range(len(tmp)):
        r[i] = tmp[i]
ans = r[K - 1] % 1_000_000_007
print(ans)

### FIXED CODE ###

def fib(W):
    a, b = 1, 1
    n = [a, b]
    while W > len(n):
        a, b = b, b + a
        n.append(b)
    return n
H, W, K = map(int, input().split())
f = fib(W)
r = [1] + [0] * (W - 1)
for i in range(H):
    tmp = [0] * W
    for j in range(W):
        if j == 0:
            tmp[j] = r[j] * f[W - j - 1] + r[j + 1] * f[W - j - 2] if W != 1 else 1
        elif j == W - 1:
            tmp[j] = r[j] * f[j] + r[j - 1] * f[j - 1]
        else:
            tmp[j] = r[j] * f[j] * f[W - j - 1] + r[j + 1] * f[W - j - 2] * f[j] + r[j - 1] * f[W - j - 1] * f[j - 1]
    r = tmp
print(r[K - 1] % 1000000007)
import itertools

n = int(input())
p_list = tuple(map(int, input().split()))
q_list = tuple(map(int, input().split()))

seq = [i for i in range(1,n+1)]
seq_list = list(itertools.permutations(seq))
sorted_seq = sorted(seq_list)

for i in range(1, len(sorted_seq)):
  if p_list == sorted_seq[i]:
    a = i
  if q_list == sorted_seq[i]:
    b = i
print(abs(a - b))

### FIXED CODE ###

import itertools

n = int(input())
p_list = tuple(map(int, input().split()))
q_list = tuple(map(int, input().split()))

seq = [i for i in range(1,n+1)]
seq_list = list(itertools.permutations(seq))
sorted_seq = sorted(seq_list)

for i in range(len(sorted_seq)):
  if p_list == sorted_seq[i]:
    a = i
  if q_list == sorted_seq[i]:
    b = i
print(abs(a - b))