peterverebics/CodeNet_Python_428 huggingface dataset:
# Judge status: Accepted
def dfs(S):
    if len(S) == N:
        ans.append(S)
    else:
        for c in range(max(S) + 2):
            dfs(S + [c])


N = int(input())
ans = []
dfs([0])
for li in ans:
    print("".join(chr(c + ord("a")) for c in li))
# Judge status: Accepted
N = int(input())
ans = 0
if N%2 == 0:
    N //= 2
    for i in range(40):
        ans += N//5
        N = N//5

print(ans)
# Judge status: Accepted
k,s=map(int,input().split())
ans=0
for i in range(k+1):
    for j in range(k+1):
        if i+j<=s and i+j+k>=s:
            ans+=1    
print(ans)
# Judge status: Wrong Answer
N,K = (int(x) for x in input().split())
S = list(input())
i = 0
ans = N

while i < len(S)-1:
    if S[i] == 'R' and S[i+1] == 'L':
        if K == 0:
            ans -= 2
        else:
            K -= 1

    i += 1

if S[0] == 'L':
    if K > 0:
        K -= 1
    else:
        ans -= 1

if S[N-1] == 'R':
    if K > 0:
        K -= 1
    else:
        ans -= 1   

print(ans)
# Judge status: Wrong Answer
N, M = (int(x) for x in input().split())
H = [int(x) for x in input().split()]

high = set()
low = set()
lonely = set()

for i in range(M):
	i1, i2 = [int(x) for x in input().split()]
	if H[i1 - 1] != H[i2 - 1]:
		high.add(i2)
		low.add(i1)
	lonely.add(i1)
	lonely.add(i2)

result = len((high - low)) + (N  - len(lonely))
print(result)
# Judge status: Wrong Answer
#!/usr/bin/env python3

x = int(input())

if x <= 11:
    print(2)
else:
    print(x//11 * 2 + 1)
# Judge status: Wrong Answer
N = int(input())
keta = len(str(N))
SN = str(N)
if N <= 9:
    print(N)
elif SN.count('9') == keta:
    print(N)
elif SN.count('9') == keta-1 and SN[0] != '9':
    print((keta - 1) * 9 + int(SN[0]))
else:
    print((keta - 1) * 9 + int(SN[0])-1)
# Judge status: Accepted
A, B, C = map(int, input().split())
K = int(input())
M = max(A, B, C)
ans = (A + B + C) - M + M * pow(2, K)
print(ans)
# Judge status: Wrong Answer
N = int(input())
A = [int(input()) for i in range(N)]
ans = 0
for i in range(N-1):
    ans += (A[i] + A[i+1])//2
    A[i+1] = min(A[i+1], (A[i] + A[i+1]) % 2)
if N == 1:
    print(N//2)
    exit()
print(ans)
# Judge status: Accepted
D,T,S=map(int,input().split())

if T >= D/S:
  print('Yes')
else:
  print('No')
# Judge status: Accepted
from bisect import bisect_right
N,C,K = map(int,input().split())
T = sorted([int(input()) for _ in range(N)])
cur = 0
cnt = 0
while cur<N:
    ind = bisect_right(T,T[cur]+K)
    if ind-cur<=C:
        cnt += 1
        cur = ind
    else:
        cnt += 1
        cur += C
print(cnt)
# Judge status: Accepted
H=int(input())
W=int(input())
N=int(input())
a=0
i=0
if H>=W:
  a=H
else:
  a=W

while a*i<N:
  i+=1
print(i)
# Judge status: Accepted
N, K = [int(s) for s in input().split(' ')]
S = input()
k = K - 1
print(S[:k] + S[k].lower() + S[k+1:])
# Judge status: Accepted
N, K = map(int, input().split())
li = list(map(int, input().split()))

ans = 10**10

for i in range(N - K + 1):  
  left = li[i]
  right = li[i + K - 1]
  ans = min(ans, min(abs(left), abs(right)) + right - left)

print(ans)
# Judge status: Accepted
N = int(input())
ans = 0
for i in range(1, N + 1, 2):
    cnt = 0
    for j in range(1, N + 1):
        if i % j == 0:
            cnt += 1
    if cnt == 8:
        ans += 1

print(ans)
# Judge status: Accepted

def main():
    a, b, h, m = map(int, input().split())

    from math import sin, cos, pi, sqrt

    ar = pi/2 - 2*pi/12*h - 2*pi/60/12*m
    br = pi/2 - 2*pi/60*m

    ax, ay = a * cos(ar), a * sin(ar)
    bx, by = b * cos(br), b * sin(br)

    c = sqrt((ax-bx)**2+(ay-by)**2)

    print(c)


if __name__ == "__main__":
    main()
# Judge status: Accepted
a=['MON','TUE','WED','THU','FRI','SAT','SUN']

b=input()

print(6-a.index(b) if b!='SUN' else '7')
# Judge status: Accepted
N, K = list(map(int, input().split()))
D = list(map(int, input().split()))

D = set(D)

while True:
    S = str(N)
    for s in list(S):
        if int(s) in D:
            N += 1
            break
    else:
        break
    continue
print(N)
# Judge status: Wrong Answer
a=input()
n=len(a)
t=0
for i in range(n-4):
  if i<n-5:
    if int(a[i:i+5])%2019==0:
      t+=1
    if int(a[i:i+6])%2019==0:
      t+=1
  else:
    if int(a[i:i+5])%2019==0:
      t+=1
print(t)
# Judge status: Wrong Answer
a, b, t = map(lambda x: int(x), input().split())

n = int(t/a)
print(n*a)
# Judge status: Accepted
N = int(input())

ans = 0
for i in range(1, N+1):
    if len(str(i)) % 2 != 0:
        ans += 1
print(ans)
# Judge status: Wrong Answer
N, K = map(int, input().split())
A = list(map(int, input().split()))

visited = [-1] * N
visited[0] = 0
nxt = 1
cnt = 1
for i in range(N):
    nxt = A[nxt-1]
    if visited[nxt-1] == -1:
        visited[nxt-1] = cnt
        cnt += 1
    else:
        cycl = i + 1 - visited[nxt-1]
        m = visited[nxt-1]
        break
print(visited, cycl)

k = (K - m) % cycl + m

for i in range(N):
    if visited[i] == k:
        print(i+1)
        break
# Judge status: Wrong Answer
a,b,c,k = map(int,input().split())

tmp = abs(a - b)
if tmp > k:
    print("Unfair")
elif k % 2 == 0:
    print(a - b)
else:
    print(b - a)
# Judge status: Accepted
N = int(input())
A = list(map(int, input().split()))

if N == 0:
    if A[0] != 1:
        print(-1)
    else:
        print(1)
    exit()


leaf = []
miki = []
under = 1

for i, a in enumerate(A):
    if a > under:
        print(-1)
        exit()
    miki.append(under - a)
    under = miki[-1] * 2


ans = 0
child = 0
for i in reversed(range(N + 1)):
    child = min(child, miki[i]) + A[i]
    ans += child

print(ans)
# Judge status: Accepted
n,m=map(int,input().split())
print ((n*(n-1)//2)+(m*(m-1)//2))
# Judge status: Accepted
N = int(input())
a_list = list(map(int,input().split()))

a_list.sort(reverse=True)

sum = 0
for i in range(1, 2*N, 2):
    sum += a_list[i]

print(sum)
# Judge status: Wrong Answer
s = input()
t = input()
s_len = len(s)
for i in range(s_len-1):
    if s == t:
        print("Yes")
        exit()
    s = s[s_len-1] + s[0:s_len-1]
print("No")
# Judge status: Accepted
s = input()
if s[1] == 'B':
    print("ARC")
else:
    print("ABC")
# Judge status: Wrong Answer
N, Y = map(int, input().split())
total = 0
for x in range(N + 1):
    for y in range(N + 1 - x):
        for z in range(N + 1 - x - y):
            if Y == 10000 * x + 5000 * y + 1000 * z:
                total = total + 1
                ans = str(x) + " " + str(y) + " " + str(z)
                print(ans)
                break
            else:
                continue
if total ==0:
    print("-1 -1 -1")
# Judge status: Accepted
n,m = map(int,input().split())
l,r = map(int,input().split())

for i in range(m-1):
    
    nl,nr = map(int,input().split())
    if l<nl :
        l = nl
    if r > nr:
        r = nr
print(max(r-l + 1, 0))
# Judge status: Accepted
n,m = map(int,input().split())
s = []
ans = 0
for i in range(n):
    a,b = map(int,input().split())
    s.append([a,b])
s.sort()
for i in s:
    if m<i[1]:
        ans += m*i[0]
        break
    else:
        ans += i[0]*i[1]
        m -= i[1]
print(ans)
# Judge status: Wrong Answer
a = int(input())
print(a//5*500+a//5*5)
# Judge status: Accepted
n,k = map(int,input().split())
a = list(map(int,input().split()))
import math
l = 0
r = max(a)+1
for _ in range(100):
  m = (l+r)/2
  kn = 0
  for i in a:
    kn += i//m
  if kn > k:
    l = m
  else:
    r = m
print(math.ceil(l))
# Judge status: Wrong Answer
import math

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

w = list(range(n + 1))
a = [0 for _ in range(n)]

mx = sum(w[(n // 2) + 1:]) - sum(w[:(n // 2) + 1]) + 1
a[(n // 2)] = mx

cnt = 1
prev = mx
for i in range((n // 2) - 1, -1, -1):
    a[i] = prev - cnt
    a[n - i - 1] = prev - cnt
    cnt += 2
    prev = a[i]

print(sum(a[k - 1:]) + 1)
# Judge status: Wrong Answer
INF = 1000000007


def modmulti(a, b):
    # aとbを掛けた値をmodする(a * b mod p)
    res = 0
    mod = a % INF
    while b > 0:
        if b == 1:
            res += mod
            if res > INF:
                res -= INF
        mod <<= 1
        if mod > INF:
            mod -= INF
        b >>= 1
    return res


N = int(input())

ans = 1

for i in range(1, N + 1):
    ans = modmulti(ans, i)

print(ans)
# Judge status: Accepted
n,m = map(int,input().split())
a = list(map(int,input().split()))

import math
lcm = 1
for i in range(n):
    b = a[i]//2
    lcm = lcm*b //math.gcd(lcm,b)
if any(2*lcm//i % 2 == 0 for i in a):
    print(0)
else:
    print((m-lcm)//(2*lcm) + 1)
# Judge status: Wrong Answer
N = int(input())
A = list(map(int, input().split()))
B = list(map(int, input().split()))
allSousa = sum(B)-sum(A)
atob = 0
for a, b in zip(A, B):
  if a < b:
    atob += (b-a)//2
if atob < allSousa:
  print("Yes")
else:
  print("No")
# Judge status: Wrong Answer
N,M=map(int,input().split())

ab=[list(map(int,input().split())) for i in range(N)]
cd=[list(map(int,input().split())) for i in range(M)]

ans=[0 for i in range(N)]
for i in range(N):
    dis=10**6
    for j in range(M):
        xx=abs(ab[i][0]-cd[j][0])
        yy=abs(ab[i][1]-cd[j][1])
        temp=xx+yy
        if dis>temp:
            dis=temp
            ans[i]=j
for a in ans:
    print(a+1)
# Judge status: Wrong Answer
nums = list(map(int, input().split()))
K = int(input())
max_num = max(nums)
ans = 0
for num in nums:
    if max_num == num:
        ans += num * (2 ** K)
    else:
        ans += num
print(ans)
# Judge status: Accepted
n=int(input())
num=[]
def ap(num1):
    num.append(num1)
for i in range(n):
    ap(list(map(int,input().split())))
num2=0
str1= lambda val: val[1]
num.sort(key=str1)
ans=0
for i in range(n):
    num2+=num[i][0]
    if num2>num[i][1]:
        ans=1
        break
if ans==1:
    print("No")
else:
    print("Yes")
# Judge status: Accepted
S = input()
f=0
l=0
for i in range(len(S)):
    if(S[i] =="A"):
        f = i+1
        break
for j in range(len(S)-1,0,-1):
    if(S[j] == "Z"):
        l = j+1
        break
print(l-f+1)
# Judge status: Wrong Answer
import numpy as np
import itertools
N,M,X = map(int,input().split( ))
CA = np.array([list(map(int,input().split( ))) for _ in range(N)])
A = CA[:,1:]
C = CA[:,0]
ans = -1
for i in range(N):
    money = []
    xs = []
    for j in itertools.permutations(np.arange(N),i+1):
        x = np.min(np.sum(A[list(j)],0))
        xs.append(x)
        if x >= X:
            money.append(np.sum(C[list(j)]))
    if np.max(xs) >= X:
        ans = np.min(money)
        break
print(ans)
# Judge status: Wrong Answer
a,b,c = map(int,input().split())

print(a//b) if a//b<c else print(c)
# Judge status: Accepted
S = int(input())

def memo(func):
  D = {}
  def ret(*args):
    if args not in D:
      D[args] = func(*args)
    return D[args]
  return ret

@memo
def func(x):
  if x<3:
    return 0
  ret = 1
  for i in range(3, x-3+1):
    ret = (ret + func(i)) % 1000000007
  return ret

print(func(S))
# Judge status: Accepted
n, m = map(int, input().split())
p_y = []
for i in range(m):
    p, y = map(int, input().split())
    p_y.append([p, y, i])

p_y.sort()
# print(p_y)

res = [0] * m
order = 0
for i in range(m):
    ken, _, index = p_y[i]
    if ken != p_y[i - 1][0] and i > 0:
        order = 1
    else:
        order += 1
    res[index] = [ken, order]


# print(res)

for i in range(m):
    ken = str(res[i][0]).zfill(6)
    order = str(res[i][1]).zfill(6)
    print(ken + order)
# Judge status: Wrong Answer
val = input().split(' ')
n = int(val[0])
m = int(val[1])

result = n * (n-1) / 2 + m * (m-1) / 2

print(result)
# Judge status: Accepted
N,x = map(int, input().split())
a = list(map(int, input().split()))

a.sort()
ans = 0
for i in range(N):
  if x-a[i] >=0:
    ans += 1
    x -= a[i]
  else:
    break

if x == 0 or ans < N:
  print(ans)
else:
  print(ans-1)
# Judge status: Accepted
import sys
import math
# input処理を高速化する
input = sys.stdin.readline

A,B,C,D = map(int,input().split())

while True:
    C=C-B
    if C<=0:
        print('Yes')
        exit(0)
    A=A-D
    if A<=0:
        print('No')
        exit(0)
# Judge status: Wrong Answer
N,K = map(int,input().split())
R,S,P = map(int,input().split())
T = str(input())
lst = []

for i in range(len(T)):
    if T[i] == 'r':
        lst.append(P)
    elif T[i] == 's':
        lst.append(R)
    else: # T[i] == 'p'
        lst.append(S)

for j in range(N):
    if j >= K and lst[j] == lst[j-K]:
        lst[j] = 0
print(sum(lst))
# Judge status: Accepted
print("YNeos"[not ''.join(sorted(input()))=="abc"::2])
# Judge status: Accepted
k,x = map(int,input().split())
if 500 * k >= x :
    print('Yes')
else:
    print('No')
# Judge status: Accepted
A, B = map(int, input().split())
if A + B < 24:
  print(A + B)
else:
  print(A + B - 24)
# Judge status: Accepted
from scipy.special import comb

s = int(input())
mod = 10**9 + 7

d = s // 3

ans = 0
for i in range(d):
  ans += comb((s-3*(i+1))+i,i,exact=True) % mod
  
print(ans % mod)
# Judge status: Accepted
print('Yes' if len(set(input().split()))==2 else 'No')
# Judge status: Accepted
n,*a=map(int,open(0).read().split())
mod=998244353
b=[0]*n
for i in a:
    b[i]+=1
ans=0
if a[0]==0 and 1==b[0]:
    ans=1
for i,j in zip(b,b[1:]):
    ans=ans*i**j%mod
print(ans)
# Judge status: Wrong Answer
print('red') if int(input()) >= 3200 else print(input())
# Judge status: Accepted
from collections import Counter

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

    unchange = sum(tuple[1] for tuple in Counter(A).most_common(K))
    print(N-unchange)

main()
# Judge status: Accepted
import sys
import os


def main():
    if os.getenv("LOCAL"):
        sys.stdin = open("input.txt", "r")

    A, B = list(map(int, sys.stdin.buffer.readline().split()))
    print((A+B)//2 if (A+B)%2 == 0 else 'IMPOSSIBLE')


if __name__ == '__main__':
    main()
# Judge status: Accepted
n = int(input())
A = [int(i) for i in input().split()]

c = 0
for i in A: c += 1 if i<3200 else 0
Am = set()
for i in A:
    if i<3200:
        Am.add(i//400)

minc = len(Am) if c>0 else len(Am)+1

AM = set([int(v)//400 if v<3200 else i+50 for i, v in enumerate(A)])
maxc = len(AM)

print(minc, maxc)
# Judge status: Accepted
t = str(input())
a = []
cnt = 0
show = 0
for i in range(len(t)):
    if t[i] == '?':
        a.append('D')
    else:
        a.append(t[i])
print("".join(a))
# Judge status: Accepted
n = int(input())
A = list(map(int, input().split()))
ans = [0]*n
for i in range(n):
    ans[A[i]-1]=i+1
print(*ans)
# Judge status: Accepted
def main():
 s = input()
 if s == 'Sunny':
     print('Cloudy')
 elif s == 'Cloudy':
     print('Rainy')
 else:
     print('Sunny')
main()
# Judge status: Accepted
s,c = map(int,input().split())

ans = min(s,c//2)
c -= ans*2
print(ans + c//4)
# Judge status: Accepted
A,B=map(int,input().split())
if A>=13:
  print(B)
elif A>=6 and A<=12:
  print(B//2)
else:
  print(0)
# Judge status: Accepted
S=list(input())

ans=[]

for s in S:
  if s == "B":
    if len(ans)>0:
      del ans[-1]
  else:
    ans.append(s)
    
print("".join(ans))
# Judge status: Accepted
def resolve():
    n = int(input())
    a = list(map(int, input().split()))
    b = list(map(int, input().split()))

    ori = sum(a)

    for i in range(n):
        bt = b[i]
        if a[i] < bt:

            a[i+1] = max(a[i+1]-(bt-a[i]), 0)
            a[i] = 0
        else:
            a[i] -= bt
    end = sum(a)
    print(ori-end)
resolve()
# Judge status: Wrong Answer
S=input();
K=input();
i = 0;
for i in range(len(S)) :
    if int(S[i]) > 1 :
        print(S[i]);
        break;
# Judge status: Accepted
N = int(input())

from collections import deque
tmp = []
tmp = deque(tmp)
num = [0]*(10**4*7)
for i in range(1,10**2+1):
    tmp.append(i**2)

for x in tmp:
    xx = int(x**0.5)
    for y in tmp:
        yy = int(y**0.5)
        for z in tmp:
            zz = int(z**0.5)
            ans = x + y + z + xx*yy + yy*zz + zz*xx
            num[ans] += 1
            
for i in range(1,N+1):
    print(num[i])
# Judge status: Accepted
week=['SUN','MON','TUE','WED','THU','FRI','SAT']
S=input()
day=week.index(S)
print(7-day)
# Judge status: Accepted
a, b, c = map(int, input().split())
s = set({a, b, c})
print(len(s))
# Judge status: Accepted
import sys

def solve():
    input = sys.stdin.readline
    Q, H, S, D = map(int, input().split())
    N = int(input())
    Double = [Q * 8, H * 4, S * 2, D]
    Single = [Q * 4, H * 2, S]
    if N % 2 == 0: print(min(Double) * N // 2)
    else: print(min(Double) * (N - 1) // 2 + min(Single))

    return 0

if __name__ == "__main__":
    solve()
# Judge status: Accepted
R, G, B = map(int, input().split())
K = int(input())

for i in range(K):
    ng = i
    nb = K-i
    g = G * 2 ** ng
    b = B * 2 ** nb
    if R < g < b:
        print("Yes")
        break
else:
    print("No")
# Judge status: Wrong Answer
#k = int(input())
#s = input()
#a, b = map(int, input().split())
#s, t = map(str, input().split())
#l = list(map(int, input().split()))
#l = [list(map(int,input().split())) for i in range(n)]
#a = [list(input()) for _ in range(n)]

o = input()
n = input()

for i in range(len(n)):
    print(o[i], end="")
    print(n[i], end="")

if len(o) - len(n) == 1:
    print(o[:-1])
# Judge status: Accepted
n,k=map(int,input().split())
d={}
for _ in range(n):
    a,b=map(int,input().split())
    if a in d:
        d[a]+=b
    else:
        d[a]=b
s=0
for i in sorted(d):
    s+=d[i]
    if s>=k:
        print(i)
        exit()
# Judge status: Accepted
MOD = 1000000007
INF = float("inf")

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

h = set()
for elem in A:
    if elem in h:
        print("NO")
        exit()
    h.add(elem)

print("YES")
# Judge status: Accepted
N=int(input())

A=[]
B=[]
for i in range(N):
    a, b=map(int, input().split())
    A.append(a)
    B.append(b)

A.sort()
B.sort()

if N%2==0:
    sca=scb=N//2-1
    lca=lcb=N//2
    x=A[lca]+A[sca]
    y=B[lcb]+B[scb]
    print(y-x+1)
    
    
else:
    ca=cb=N//2
    ans=B[cb]-A[ca]+1
    print(ans)
# Judge status: Accepted
from heapq import heapify, heappush, heappop

def main():
    N = int(input())
    A = list(map(int, input().split()))
    heapify(A)
    while len(A) > 1:
        m = heappop(A)
        A = [a % m for a in A if a % m != 0]
        A.append((m))

    print(m)


if __name__ == "__main__":
    main()
# Judge status: Accepted
n = int(input())
abc  = [[], [], []]

abc = [list(map(int, input().split())) for _ in range(n)] # DB取得方法のみ違う, 分かればどっちでもok
#print(abc)

dp = [[0,0,0] for _ in range(n)]
dp[0] = abc[0]
#print(dp)

for i in range(1, n):
    for j in range(3):
        for k in range(3):
            if j != k:
                dp[i][j] = max(dp[i][j], dp[i-1][k] + abc[i][j]) # ここのDB指定方法に影響

print(max(dp[-1]))
# Judge status: Wrong Answer
N,M = [int(i) for i in input().split()]
S = 0

M += 2*N

S = M // 4

print(S)
# Judge status: Accepted
from collections import Counter
n = int(input())
s = [input() for _ in range(n)]

cs = Counter(s).most_common()
m = cs[0][1]
ms = ([i for i in cs if i[1] == m])

for i in sorted(ms):
    print(i[0])
# Judge status: Accepted
x1, x2, x3, x4, x5 = map(int, input().split())

if x1 == 0:
    print(1)
elif x2 == 0:
    print(2)
elif x3 == 0:
    print(3)
elif x4 == 0:
    print(4)
elif x5 == 0:
    print(5)
# Judge status: Wrong Answer
import bisect
n,m=map(int,input().split())
A=list(map(int,input().split()))
BC=[list(map(int,input().split())) for _ in range(m)]

BC.sort(key=lambda x:(x[1],x[0]))
for b,c in BC:
  A.sort()
  if A[0]>=c: break
  idx=bisect.bisect_left(A,c)
  for i in range(min(b,idx)):
    A[i]=c
print(sum(A))
# Judge status: Wrong Answer
n,m=map(int,input().split())
l=[list(map(int,input().split())) for i in range(m)]

a=[]
for i in range(n-1):
  a.append([])

for i in range(m):
  a[l[i][0]-2].append(l[i][1])
  a[l[i][1]-2].append(l[i][0])

k=[]
k.append(1)
while len(k)>0:
  for i in range(n-1):
    if k[0] in a[i]:
      a[i]=[k[0]]
      k.append(i+2)
  k.pop(0)

print("Yes")
for i in range(n-1):
  print(*a[i])
# Judge status: Accepted
INT = lambda: int(input())
INTM = lambda: map(int,input().split())
STRM = lambda: map(str,input().split())
STR = lambda: str(input())
LIST = lambda: list(map(int,input().split()))
LISTS = lambda: list(map(str,input().split()))
def do():
    s=STR()
    if s=='Sunny':
        print('Cloudy')
    elif s=='Cloudy':
        print('Rainy')
    else:
        print('Sunny')
if __name__ == '__main__':
    do()
# Judge status: Wrong Answer
a,b=map(int,input().split())
if a%b==0:
    print(a/b)
else:
    print(int(a/b)+1)
# Judge status: Wrong Answer
import math
n = int(input())
print(math.floor(n/2))
# Judge status: Accepted
def action(A, N):
  B = [0] * N
  for i, bright in enumerate(A):
    s = max(0, i - bright)
    B[s] += 1
    e = min(N, i + bright)
    if e < N - 1:
      B[e + 1] -= 1
  
  for i in range(N - 1):
    B[i + 1] += B[i]
  return B

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

  for i in range(K):
    A = action(A, N)
    if (A[0] == N) & all(A):
      break
      
  print(*A, sep=" ")

if __name__ == '__main__':
  main()
# Judge status: Accepted
K,S = map(int,input().split())
a = 0

for X in range(K+1):
  for Y in range(K+1):
    if 0<=S-X-Y<=K:
      a+=1

print(a)
# Judge status: Accepted
#https://atcoder.jp/contests/abc055/tasks/abc055_b
n = int(input())

ans=1

for i in range(1,n+1):
    ans=(ans*i)%(10**9+7)
print(ans)
# Judge status: Accepted
N, x = map(int, input().split())
a = sorted(map(int, input().split()))
ans = 0
 
for i in range(N):
    x -= a[i]
    if x < 0:
        break
    else:
        ans += 1
 
print(ans if x <= 0 else ans-1)
# Judge status: Accepted
ii = lambda : int(input())
mi = lambda : map(int,input().split())
li = lambda : list(map(int,input().split()))

s = input()
if s == "ABC":
    print("ARC")
else:
    print("ABC")
# Judge status: Accepted
x = int(input())
print(8- (x - 400)//(200))
# Judge status: Wrong Answer
N, K = map(int, input().split(' '))
p = list(map(int, input().split(' ')))



cumsum = []
cumsum_diff = 0
for i in range(N):
    if i == 0:
        cumsum.append((p[i] + 1)/2)
    else:
        cumsum.append(cumsum[i - 1] +( p[i] + 1)/2)

# print(cumsum)

for i in range(N - K + 1):
    if i <= N - K:
        if cumsum_diff < cumsum[i + K - 1] - cumsum[i-1]:
            cumsum_diff = cumsum[i + K - 1] - cumsum[i-1]

print(cumsum_diff)
# Judge status: Accepted
N, A, B = map(int, input().split())
if (B-A)%2 == 0:
  print((B-A)//2)
else:
  print(min((A+B)//2, (2*N-B-A+1)//2))
# Judge status: Wrong Answer
A = int(input())
S = input()

if A >= 3200:
  print("red")
else:
  print(S)
# Judge status: Accepted
n = int(input())
v = list(map(int,input().split()))
v = sorted(v)
ans = v[0]
for i in range(1,len(v)):
  ans = (ans + v[i]) /2
print(ans)
# Judge status: Wrong Answer
N = int(input())
X = list(map(int, input().split()))

X.sort()
center = len(X) // 2

med_l = X[center - 1]
med_r = X[center]

for n in range(N):
  if n <= center - 1:
    print(med_r)
  else:
    print(med_l)
# Judge status: Accepted
[N,K]=[int(i) for i in input().split()]
h=[int(i) for i in input().split()]
DP=[1000000000 for i in range(N)]
DP[0]=0
for i in range(N):
	for j in range(max(i-K,0),i):
		DP[i]=min(DP[j]+abs(h[i]-h[j]),DP[i])


print(DP[N-1])
# Judge status: Accepted
a,b = input().split()
c = int(a+b)

x = (int(c**0.5))**2
if x == c:
    print("Yes")
else:
    print("No")
# Judge status: Accepted
n=int(input())
monsters=list(map(int,input().split()))
heroes=list(map(int,input().split()))
ans=0
for i in range(n):
    if heroes[i]>monsters[i]:
        heroes[i]-=monsters[i]
        ans+=monsters[i]
        ans+=min(heroes[i],monsters[i+1])
        monsters[i+1]-=min(heroes[i],monsters[i+1])
    else:
        ans+=heroes[i]
print(ans)
# Judge status: Accepted
def I(): return int(input())
def MI(): return map(int, input().split())
def LMI(): return list(map(int, input().split()))

N = I()
A = [I() for _ in range(N)]

seen = set()
i = 0
light = 1
while light != 2:
    seen.add(light)
    light = A[light - 1]
    if light in seen:
        print(-1)
        exit(0)
    i += 1
print(i)