Harryxun/stf_run huggingface dataset:
n, k = map(int, input().split())
a = list(map(int, input().split()))

d = {}
for i in range(1, n + 1):
    d[i] = a[i - 1]

did = set()
route = [1]

now = 1
for i in range(k):
    now = d[now]
    route.append(now)
    if now in did:
        break
    did.add(now)


for i in range(len(route)):
  if route[i] == route[-1]:#routeには第二ループの始めがギリ入っている
    roop = route[i:-1]
    print(roop[(k - i) % len(roop)])#k-iは残り移動階数
    exit()


### FIXED CODE ###

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

d = {}
for i in range(1, n + 1):
    d[i] = a[i - 1]

did = set()
route = [1]

now = 1
for i in range(k):
    now = d[now]
    route.append(now)
    if now in did:
        break
    did.add(now)

if k < 10 ** 6:
    now = 1
    for i in range(k):
        now = d[now]

    print(now)

else:
    for i in range(len(route)):
        if route[i] == route[-1]:
            roop = route[i:-1]
            print(roop[(k - i) % len(roop)])
            exit()
N = int(raw_input().split())
A = map(int, raw_input().split())
A.sort()
ans = 10**18
for i in xrange(1, N):
  ans = min(ans, abs(sum(A[:i]) - sum(A[i:])))
print ans

### FIXED CODE ###

N = int(raw_input())
A = map(int, raw_input().split())
ans = 10**18
for i in xrange(1, N):
  ans = min(ans, abs(sum(A[:i]) - sum(A[i:])))
print ans
N = int(input())
A = list(map(int, input().split()))
whole_length = sum(A)
middle_length = whole_length / 2
sum_length_before = 0
sum_length = 0
sum = 0
cost_before = abs(sum_length_before - middle_length)
cost_after = abs(sum_length_after - middle_length)

for i in range(N):
    if A[i] < middle_length:
        sum_length_before = sum_length
        sum_length_after += A[i]
        sum = i
    else:
        break

if cost_before >= cost_after:
    print(cost_after)

else:
    print(cost_before)


### FIXED CODE ###

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

if X == 1 and Y == 1:
    print(1000000)

elif (X == 1 and Y == 2) or (X == 2 and Y == 1):
    print(500000)

elif (X == 1 and Y == 3) or (X == 3 and Y == 1) or (X == 2 and Y == 2):
    print(400000)

elif (X == 1 and Y >= 4) or (X >= 4 and Y == 1) or (X == 2 and Y == 3) or (X == 3 and Y == 2):
    print(300000)

elif (X == 2 and Y >= 4) or (X >= 4 and Y == 2) or (X == 3 and Y == 3):
    print(200000)

elif (X == 3 and Y >= 4) or (X >= 4 and Y == 3):
    print(100000)

else:
    print(0)
x <- list(map(int(), input().split()))

for i in len(x):
    print("Case 1:", x[i])



### FIXED CODE ###

for i in range(10000):
    x = input()
    x = int(x)
    
    if x == 0:
        break
    else:
        print("Case "+ str(i+1) + ": " + str(x))
import scipy.special

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

M = m
lst, count = [],[]
for i in range(2,int(math.sqrt(m))+1):
    while M % i == 0:
        M = M // i
        if i not in lst:
            count.append(1)
            lst.append(i)
        else:
            count[-1] += 1
if M > 1:
    lst.append(M)
    count.append(1)       

ans = 1
for i in count:
    ans *= scipy.special.comb(i+n-1,i)
    ans = ans % (10**9+7) 

print(int(ans))

### FIXED CODE ###

import scipy.misc
import math

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

M = m
lst, count = [],[]
if M == 1:
    print(1)
else:
    for i in range(2,int(math.sqrt(m))+1):
        while M % i == 0:
            M = M // i
            if i not in lst:
                count.append(1)
                lst.append(i)
            else:
                count[-1] += 1
    if M > 1:
        lst.append(M)
        count.append(1)       

    ans = 1
    for i in count:
        ans = ans * scipy.misc.comb(i+n-1,i, exact=1)
        ans = ans % (10**9+7) 

    print(int(ans))
A,B=(int(x) forx in input.split())
if A=1:
  A==14
if B=1:
  B==14
if A>B:
  print('Alice')
elif B>A:
  print('Bob')
else:
  ('Drow')

### FIXED CODE ###

A,B=[int(x) for x in input().split()]
if A==1:
  A=14
if B==1:
  B=14
if A>B:
  print('Alice')
elif B>A:
  print('Bob')
else:
  print('Draw')
n = int(input())
ab = [tuple(map(int,input().split())) for i in range(n-1)]

es = [[] for i in range(n)]
for i, (a,b) in enumerate(ab):
    a,b = a-1,b-1
    es[a].append((b, i))
    es[b].append((a, i))


# BFS
colors = {}
root = 0 # 頂点1が存在することが問題文中で保証されてるからここを根ノードとしよう
root_child0, _ = es[root][0]
colors[(root,root_child0)] = 1
K = 0
queue = [root]
visited = [0]*n
visited[root] = 1

ans_color = [0]*(n-1)

while queue:
    v = queue.pop(0)
    visited[v] = 1

    color = 1
    parent, _ = es[v][0] # vがrootの時は変なことになるけど後で弾くから大丈夫
    color_parent = colors[(v, parent)]

    for to, j in es[v]:
        if visited[to]: continue
        queue.append(to)

        if color == color_parent and v != root:
            color += 1

        colors[(v,to)] = color
        colors[(to,v)] = color

        ans_color[j] = color

        K = max(K, color)
        color += 1


print(K)
print(*ans_color, sep='\n')

### FIXED CODE ###

import sys
sys.setrecursionlimit(10 ** 7)

n = int(input())
ab = [tuple(map(int,input().split())) for i in range(n-1)]

es = [[] for i in range(n)]
for i, (a,b) in enumerate(ab):
    a,b = a-1,b-1
    es[a].append((b, i))
    es[b].append((a, i))

visited = [0]*n
ans_color = [0]*(n-1)

# DFS
def dfs(v, fromColor):
    color = 1
    visited[v] = 1
    for to, i in es[v]:
        if visited[to]: continue

        if color == fromColor:
            color += 1
        ans_color[i] = color
        dfs(to, color)
        color += 1

root = 0 # 頂点1が存在することが問題文中で保証されてるからここを根ノードとしよう
dfs(root, 0)

print(max(ans_color))
print(*ans_color, sep='\n')
import copy
S = list(input())
T = list(input())
for i in range(len(S) - len(T) + 1):
    c = 0
    A=copy.copy(S)
    check = False
    for j in range(len(T)):
        if A[i + j] == T[j]:
            c += 1
        elif A[i + j] == "?":
            A[i + j] = T[j]
            c += 1
        else:
            break
        if c == len(T):
            check = True
    if check:
        break
print("".join(A).replace("?","a") if check else "UNRESTORABLE")

### FIXED CODE ###

import copy

S = list(input())
T = list(input())
candidate = []
if len(T) > len(S):
    print("UNRESTORABLE")
    exit()
for i in range(len(S) - len(T) + 1):
    c = 0
    A = copy.copy(S)
    check = False
    for j in range(len(T)):
        if A[i + j] == T[j]:
            c += 1
        elif A[i + j] == "?":
            A[i + j] = T[j]
            c += 1
        else:
            break
        if c == len(T):
            candidate = A
print("".join(candidate).replace("?", "a") if candidate else "UNRESTORABLE")
n,m=map(int,input().split())
ans=["x"]*n

for i in range(m):
    a,b=map(int,input().split())
    
    if ans[a-1]=="x" or ans[a-1]==b:
        ans[a-1]=b
    else:
        print(-1)
        exit()

if n==1 and ans[0]==0:
    print(0)
elif n>1 and ans[0]==0:
    print(-1)
elif "x" not in ans:
    print ("".join(ans))
    
else:
    for j in range(n):
        if ans[j]=="x":
            ans[j]=0
        print(ans[j], end="")
            


### FIXED CODE ###

n,m=map(int,input().split())
ans=[]

for i in range(m):
    ans.append(list(map(int,input().split())))
for j in range(10**n):
    if len(str(j))==n and all(str(j)[s-1]==str(c) for s,c in ans):
        print(j)
        break
else:
    print(-1)
N,K=map(int,input().split())
S=input()
T=list(S)
T[K-1]=T[K-1].lower()
S_changed="".join(T)
print(S_changed

### FIXED CODE ###

N,K=map(int,input().split())
S=input()
T=list(S)
T[K-1]=T[K-1].lower()
S_changed="".join(T)
print(S_changed)
a,b,c,k = map(int,input().split())
if k <= a:
  print(k)
  else:
    if k>a and k <= a+b:
      print(a)
      else:
        print(k-a)

### FIXED CODE ###

a,b,c,k = map(int,input().split())
if k <= a:
  print(k)
else:
  if k>a and k <= a+b:
    print(a)
  else:
    print(a-(k-a-b))
S=list(input())
line=[]
A=["A","C","G","T"]
num_list=[]
flag=False
for s in S:
    if s in A:
        line.append(s)
        flag=True
    elif flag:
        num_list.append(len(line))
        line=[]
        flag=False
print(max(num_list))

### FIXED CODE ###

S=list(input())
line=[]
A=["A","C","G","T"]
num_list=[]
flag=False
for s in S:
    if s in A:
        line.append(s)
        flag=True
    elif flag:
        num_list.append(len(line))
        line=[]
        flag=False
num_list.append(len(line))
if len(num_list)==0:print(0)
else:
    print(max(num_list))
d = [int(input()) for _ in range(5)]

ans = 0
r =[]
for i in range(5):
  if d[i]%10!=0:
    r.append(d[i]%10)
    ans += d[i]-(d[i]%10)+10
  else:
    ans += d[i]

ans -= 10-min(r)
print(ans)

### FIXED CODE ###

d = [int(input()) for _ in range(5)]

ans = 0
r =[]
for i in range(5):
  if d[i]%10!=0:
    r.append(d[i]%10)
    ans += d[i]-(d[i]%10)+10
  else:
    ans += d[i]

if len(r) == 0:
  print(ans)
  exit()
else:
  ans -= 10-min(r)
  print(ans)
a = input()
b = input()
c = input()

subitem1 = a
a = b
b = subitem1

subitem2 = a
a = c
c = subitem2

print(a,b,c)

### FIXED CODE ###

x, y, z = map(int, input().split())
 
x_ = y
y_ = x
 
x__ = z
z_ = x_
 
print(x__, y_, z_)
a,b,c = map(int,input().split())
if b-a == c-b:
    print("YES")
else:
    pritn("NO")

### FIXED CODE ###

a,b,c = map(int,input().split())
if b-a == c-b:
    print("YES")
else:
    print("NO")
a, b = map(int, input().split(" "))
     
    if (a%3 ==0) or (b%3 ==0) or ((a+b)%3 ==0):
        print("Possible")
    else:
        print("Impossible")


### FIXED CODE ###

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

if (a+b)%3 == 0:
    print("Possible")
elif a%3 == 0:
    print("Possible")
elif b%3 == 0:
    print("Possible")
else:
    print("Impossible")
n, m  = map(int, input().split())
a = list(map(int, input().split()))
a.sort()
cb = []
for i in range(m):
  b, c = map(int, input().split())
  cb.append([c,b])
cb.sort(reverse=True)

j = 0
for i in range(m):
  k = 0
  while k<cb[i][1] and a[k+j]<cb[i][0] and k+j<n:
    a[k+j] = cb[i][0]
    k += 1
  j += k
  if j == n:
    break
    
print(sum(a))

### FIXED CODE ###

n, m = map(int, input().split())
a = list(map(int, input().split()))
a.sort()
cb=[]
for i in range(m):
    b, c = map(int, input().split())
    cb.append([c,b])
cb.sort(reverse=True)
k=0
for i in range(m):
    j=0
    while j<cb[i][1] and k+j<n and a[k+j]<cb[i][0]:
        a[k+j] = cb[i][0]
        j+=1
    k+=j
    if k==n:
        break
print(sum(a))
# coding: utf-8

def popcount(x):
    '''xの立っているビット数をカウントする関数
    (xは64bit整数)'''

    # 2bitごとの組に分け、立っているビット数を2bitで表現する
    x = x - ((x >> 1) & 0x5555555555555555)

    # 4bit整数に 上位2bit + 下位2bit を計算した値を入れる
    x = (x & 0x3333333333333333) + ((x >> 2) & 0x3333333333333333)

    x = (x + (x >> 4)) & 0x0f0f0f0f0f0f0f0f # 8bitごと
    x = x + (x >> 8) # 16bitごと
    x = x + (x >> 16) # 32bitごと
    x = x + (x >> 32) # 64bitごと = 全部の合計
    return x & 0x0000007f

N = int(input())
y = input(); x = 0

dic = dict()
dic[0] = 0
for i in range(1, N+1):
    cnt = popcount(i)
    b = i%cnt
    dic[i] = b

    if y[i-1] == '1':
        x += 1

X = int('0b' + y, 0)

res = 1 << N-1
for i in range(N):
    now = X ^ res
    nx = x
    if y[i] == '1':
        nx -= 1
    else:
        nx += 1
    #print(now, res)
        
    a = bin(now)
    #print(a)
    
    b = now%nx
    #print(now, nx, b)
    ans = 1
    while b > 0:
        b = dic[b]
        ans += 1
    print(ans)
    
    res = res >> 1

### FIXED CODE ###

N = int(input())
X = input()

arr = [0 for _ in range(N+1)]
for i in range(1, N+1):
    cnt = bin(i).count('1')
    arr[i] = arr[i%cnt] + 1

x = int(X, 2)
pop = X.count('1')
plu = x % (pop+1)
mai = x % (pop-1) if pop>1 else 0

#bi = 1 << N
for i in range(N):
    #bi = bi >> 1
    if X[i] == '0':
        #res = (plu + bi % (pop+1)) % (pop+1)
        res = (plu + pow(2, N-1-i, pop+1)) % (pop+1)
    else:
        if pop == 1:
            print(0)
            continue
        #res = (mai - bi % (pop-1)) % (pop-1)
        res = (mai - pow(2, N-1-i, pop-1)) % (pop-1)
    print(arr[res] + 1)
# coding:utf-8
readline = sys.stdin.buffer.readline
H1 = int(readline())
M1 = int(readline())
H2 = int(readline())
M2 = int(readline())
K = int(readline())
while not 0 <= H1 < 23 and 0 <= M1 < 59 and 0 <= H2 < 23 and 0 <= M2 < 59:
    H1 = int(readline())
    M1 = int(readline())
    H2 = int(readline())
    M2 = int(readline())
    K = int(readline())
if M2 > M1:
    a = (H2 - H1) * 60 + M2 - M1
    print(a - K)
if M2 < M1:
    b = (H2 - H1) * 60 + M1 - M2
    print(b - K)

### FIXED CODE ###

import sys
readline = sys.stdin.buffer.readline
h1, m1, h2, m2, k = map(int, readline().split())
print(60 * (h2 - h1) + m2 - m1 - k)
n = int(input())
m = int(input())

x = 0
a = str(m)
for i in range(n):
    if a.find(a[i]) != i:
        print("Yes")
        break
    x += 1

if x == n:
    print("No")


### FIXED CODE ###

n = int(input())
a = list(int(x) for x in input().split())
x = 0
 
a.sort()
for i in range(n-1):
    if a[-1] - a[-2] == 0:
        print("NO")
        x = 1
        break
    a.pop()
 
if x == 0:
    print("YES")
import sys

l1 = sys.stdin.readline()
l2 = sys.stdin.readline()

nums = [int(x) for x in l1.rstrip('\n').split(' ')]
l2 = int(l2)

out = max(nums)

for i in xrange(l2):
  out *= 2
print out + sum(l1) - max(nums)


### FIXED CODE ###

import sys
 
l1 = sys.stdin.readline()
l2 = sys.stdin.readline()
 
nums = [int(x) for x in l1.rstrip('\n').split(' ')]
l2 = int(l2)
 
out = max(nums)
 
for i in xrange(l2):
  out *= 2
print out + sum(nums) - max(nums)
import math
a, b, c, d= list(map(int, input().split()))
m=0
for i in range(a,b+1):
	if i%c==0:
		x=1+math.floor((b-i)/c)
		break
for i in range(a,b+1):
	if i%d==0:
		y=1+math.floor((b-i)/d)
		break
for i in range(a,b+1):
	if i%(c*d)==0:
		z=1+math.floor((b-i)/(c*d))
		break
print(b-a+1-x-y+z)
print(x, y, z)


### FIXED CODE ###

from fractions import gcd
a,b,c,d=map(int,input().split())
lenth=b-a+1

def lcm(m,n):
	return (m*n)//gcd(m,n)

def divnumber(c):
	ans=lenth//c
	rem1=a%c
	if rem1==0:rem1+=c
	rem2=lenth%c-1
	if rem1+rem2>=c:
		ans+=1
	return ans

print(lenth-divnumber(c)-divnumber(d)+divnumber(lcm(c,d)))
import re
import sys
import math
import itertools
import bisect
from copy import copy
from collections import deque,Counter
from decimal import Decimal
import functools
def v(): return input()
def k(): return int(input())
def S(): return input().split()
def I(): return map(int,input().split())
def X(): return list(input())
def L(): return list(input().split())
def l(): return list(map(int,input().split()))
def lcm(a,b): return a*b//math.gcd(a,b)
sys.setrecursionlimit(10 ** 9)
mod = 10**9+7
cnt = 0
ans = 0
inf = float("inf")

n,k=I()
a = l()
town = []
num = [0]*(n+1)
cnt = 1
num[0]=1

for i in range(n):
    num[a[cnt-1]] += 1
    if num[a[cnt-1]] == 2:
        ans = a[cnt-1]
        break
    town.append(a[cnt-1])
    cnt = a[cnt-1]

p = town.index(ans)
b = town[p:]
x = len(town)
y = len(b)
q = k-x+y
if y == 0:
    print(town[n-1])
    sys.exit()
if q < 0:
    print(town[k-1])
    sys.exit()
z = q%y
if z == 0:
    print(town[k-1])
else:
    print(b[z-1])


### FIXED CODE ###

import re
import sys
import math
import itertools
import bisect
from copy import copy
from collections import deque,Counter
from decimal import Decimal
import functools
def v(): return input()
def k(): return int(input())
def S(): return input().split()
def I(): return map(int,input().split())
def X(): return list(input())
def L(): return list(input().split())
def l(): return list(map(int,input().split()))
def lcm(a,b): return a*b//math.gcd(a,b)
sys.setrecursionlimit(10 ** 9)
mod = 10**9+7
cnt = 0
ans = 0
inf = float("inf")

n,k=I()
a = l()
town = []
num = [0]*(n+1)
cnt = 1
num[0]=1

for i in range(n):
    num[a[cnt-1]] += 1
    if num[a[cnt-1]] == 2:
        ans = a[cnt-1]
        p = town.index(ans)
        b = town[p:]
        x = len(town)
        y = len(b)
        q = k-x+y
        if y == 0:
            print(town[n-1])
            sys.exit()
        if q < 0:
            print(town[k-1])
            sys.exit()
        z = q%y
        if z == 0:
            print(town[z-1])
        else:
            print(b[z-1])
        sys.exit()
        break
    town.append(a[cnt-1])
    cnt = a[cnt-1]
N=int(input())

a=[0]*10**4
count=0
for x in range(1,(N+1)):
     for y in range(1,(N+1)):
         for z in range(1,(N+1)):
             n=(x+y+z)**2-(x*y+y*z+z*x)
             a[n]+=1

for n in range(1+N+1):
    print(a[n])

### FIXED CODE ###

N=int(input())

a=[0]*10**4

for x in range(1,100):
     for y in range(1,100):
         for z in range(1,100):
             n=(x+y+z)**2-(x*y+y*z+z*x)
             if n<=10000:
                 a[n-1]+=1

for n in range(N):
    print(a[n])
N,M = map(int,input().split())
info = [[] for _ in range(N+1)] # i -> info[i] 行き先
for _ in range(M):
    x,y = map(int,input().split())
    info[x].append(y)

len_list = []
visited_list = []
def visited(p):
    for e in visited_list:
        if e == p:
            return True
    return False
def dfs(p, length = 0):
    # 訪問済みならlength-1をメモ
    if visited(p) is True:
        len_list.append(length-1)
    # 訪問の印を付ける
    visited_list.append(p)
    # 行き場所がなければlengthをメモ
    if info[p] == []:
        len_list.append(length)
    for d in info[p]:
        dfs(d, length + 1)
for i in range(1,N+1):
    dfs(i)
    visited_list.clear()
ans = max(len_list)
print(ans)

### FIXED CODE ###

import sys
input = sys.stdin.readline
sys.setrecursionlimit(10**6)

N,M = map(int,input().split())
ad = [[] for i in range(N)]
for _ in range(M):
    x,y = map(int,input().split())
    x -= 1; y -= 1
    ad[x].append(y)

dp = [-1]*N

def rec(nodes):
    if dp[nodes] != -1:
        return dp[nodes]
    res = 0
    for ne in ad[nodes]:
        option = rec(ne)+1
        if res < option:
            res = option
    dp[nodes] = res
    return dp[nodes]

ans = 0
for i in range(N):
    res = rec(i)
    if ans < res:
        ans = res
print(ans)
A, B, T = map(int, input().split())
cnt = 0

for i in range(0, T+0.5, A):
  cnt += B
print(cnt)

### FIXED CODE ###

A, B, T = map(int, input().split())
cnt = 0

for i in range(A, T+1, A):
  cnt += B
print(cnt)
def main():
	N = int(input())
	A = list(map(int, input().split()))
	for i in range(N):
		A[i] -= i+1
	A.sort()

	mid1 = A[N//2]
	mid2 = A[N//2 + 1]
	ans1 = 0
	ans2 = 0
	for i in range(N):
		ans1 += abs(A[i] - mid1)
		ans2 += abs(A[i] - mid2)

	print(min(ans1, ans2))


if __name__ == '__main__':
    main()

### FIXED CODE ###

def main():
	N = int(input())
	A = list(map(int, input().split()))
	for i in range(N):
		A[i] -= i+1
	A.sort()


	mid1 = A[N//2]
	mid2 = A[N//2]
	if N >= 2:
		mid2 = A[N//2 + 1]

	ans1 = 0
	ans2 = 0
	for i in range(N):
		ans1 += abs(A[i] - mid1)
		ans2 += abs(A[i] - mid2)

	print(min(ans1, ans2))


if __name__ == '__main__':
    main()
N, K = map(int, input().split())
A = list(map(int, input().split()))
m = 10**9+7
pos = [*filter(lambda x: x >= 0, A)]
neg = [*filter(lambda x: x<0, A)]
pos.sort(reverse=True)
neg.sort()

ans = 1
i,j = 0,0# 使った数
while i+j < K:
    flag = True
    if i == len(pos):
        flag = False
    elif j == len(neg):
        flag = True
    elif pos[i] >= -neg[j]:
        flag = True
    else:
        flag = False

    if flag:
        ans = ans * pos[i] % m
        i += 1
    else:
        ans = ans * neg[j] % m
        j += 1
# print(i,j)
if j % 2 == 0 or N==K:
    print(ans)
elif len(pos) == 0:
    ans = 1
    for i in range(K):
        ans = ans * neg[len(neg)-1-i] % m
    print(ans)
else:
    flag2 = True
    if i == len(pos):
        flag2 = False
    elif j == len(neg):
        flag2 = True
    elif pos[i-1]*pos[i] >= neg[j-1]*neg[j]:
        flag2 = True
    else:
        exit(1)
        flag2 = False

    if flag2:
        ans = ans * pow(neg[j-1],m-2,m) % m
        ans = ans * pos[i] % m
    else:
        ans = ans * pow(pos[i-1],m-2,m) % m
        ans = ans * neg[j] % m
    print(ans)

### FIXED CODE ###

N, K = map(int, input().split())
A = list(map(int, input().split()))
m = 10**9+7
pos = [*filter(lambda x: x>=0, A)]
neg = [*filter(lambda x: x<0, A)]
pos.sort(reverse=True)
neg.sort()

ans = 1
i,j = 0,0# 使った数
while i+j < K:
    flag = True
    if i == len(pos):
        flag = False
    elif j == len(neg):
        flag = True
    elif pos[i] >= -neg[j]:
        flag = True
    else:
        flag = False

    if flag:
        ans = ans * pos[i] % m
        i += 1
    else:
        ans = ans * neg[j] % m
        j += 1

if j % 2 == 0 or N==K:
    print(ans)
elif len(pos) == 0:
    ans = 1
    for i in range(K):
        ans = ans * neg[len(neg)-1-i] % m
    print(ans)
else:
    flag2 = True
    if i == 0:
        flag2 = True
    elif j == 0:
        flag2 = False
    elif i == len(pos):
        flag2 = False
    elif j == len(neg):
        flag2 = True
    elif pos[i-1]*pos[i] > neg[j-1]*neg[j]:# = を抜いた
        flag2 = True
    else:
        flag2 = False

    if flag2:
        ans = ans * pow(neg[j-1],m-2,m) % m
        ans = ans * pos[i] % m
    else:
        ans = ans * pow(pos[i-1],m-2,m) % m
        ans = ans * neg[j] % m
    print(ans)
N = input()
if int(x[2])=7:
    print(Yes)
else if int(x[1])=7:
    print(Yes)
else if int(x[0])=7:
    print(Yes)
else:
    print(No)

### FIXED CODE ###

N = input()
if int(N[2])==7:
    print("Yes")
elif int(N[1])==7:
    print("Yes")
elif int(N[0])==7:
    print("Yes")
else:
    print("No")
tem = int.input()
if tem >= 30:
  print("Yes")
else:
  print("No")

### FIXED CODE ###

tem = int(input())
if tem >= 30:
  print("Yes")
else:
  print("No")
n.m=map(int,input().split())
print(round(n/m))

### FIXED CODE ###

import math
n,m=map(int,input().split())
print(math.ceil(n/m))
s = input()
t = input()

cont = 0
y = s[::-1]
for i,x in enumerate(y):
    print(i,y[i])
    if x == "?":
        cont += 1
        if cont == len(t):
            break
        elif (cont == len(t)-1)&(y[i+1] == t[0]):
            break
    else:
        cont = 0
            
if cont == 0:
    print("UNRESTORABLE")
else:
    print((s[:len(s)-i-1]+t+s[len(s)-i+len(t):]).replace("?","a"))

### FIXED CODE ###

s = input()
t = input()

flg = 0
y = s[::-1]
z = t[::-1]
result = []
for j,x in enumerate(range(0,len(y))):
    result = []
    for i,k in enumerate(y[x:x+len(t)]):
        if (k == z[i])|(k=="?"):
            result.append(True)
    if all(result)&(len(result)==len(t)):
        flg = 1
        break
if flg == 1:
    print((s[:len(s)-j-len(t)]+t+s[len(s)-j:]).replace("?","a"))
else:
    print("UNRESTORABLE")
a, b = map(int, input().split())
if abs(a - b) >= 2:
    print(0)
else:
    x = math.factorial(a)
    y = math.factorial(b)
    ans = x * y
    if a == b:
        print(ans * 2 % (10 ** 9 + 7))
    else:
        print(ans % (10 ** 9 + 7))

### FIXED CODE ###

import math
a, b = map(int, input().split())
if abs(a - b) >= 2:
    print(0)
else:
    x = math.factorial(a)
    y = math.factorial(b)
    ans = x * y
    if a == b:
        print(ans * 2 % (10 ** 9 + 7))
    else:
        print(ans % (10 ** 9 + 7))