peterverebics/CodeNet_Python_428 huggingface dataset:
# Judge status: Accepted
N = int(input())
As = [int(input())-1 for i in range(N)]
seen = [-1] * N
# print(As)
from collections import deque
q = deque()
q.append(0)
seen[0] = 1
cnt = 1
while len(q) > 0:
    a = q.popleft()
    n = As[a]
    # print("pop",n)
    if n == 1:
       print(seen[a])
       exit()
    if seen[n] > -1: continue
    seen[n] = seen[a] + 1
    q.append(n)
print(-1)
# Judge status: Accepted
n = int(input())
A = list(map(int,input().split()))

odd = A[0::2]
even = A[1::2][::-1]

ans = even + odd

if n % 2 == 1:
    ans = ans[::-1]
    
print(*ans)
# Judge status: Accepted
N, M=map(int, input().split())
ans=["-1"]*N
f=0
for i in range(M):
  s, c=map(int, input().split())
  if s==1 and c==0 and N!=1:
    f=1
  if ans[s-1]!=str(c) and ans[s-1]!="-1":
    f=1
  ans[s-1]=str(c)

if f==1:
  print(-1)
else:
  if ans[0]=="-1" and N!=1:
    ans[0]="1"
  elif M==0 and N==1:
    ans[0]="0"
  a="".join(ans)
  b=a.replace("-1", "0")
  print(b)
# Judge status: Accepted
n = int(input())
q, r = divmod(n, 2)
print(q*(q+r))
# Judge status: Accepted
import bisect
from collections import deque
N = int(input())
nums = [int(input()) for _ in range(N)]
# i<jで、 AiとAjが同じ色で塗られている場合、Ai < Ajが成り立つ.
# その際に、色の最小数をだす。
LIS = deque([nums[0]])
count = 0
for index, num in enumerate(nums):
    if index == 0:
        continue
    if num <= LIS[0]:
        LIS.appendleft(num)
    else:
        insert_index = bisect.bisect_left(LIS, num)
        LIS[insert_index - 1] = num
print(len(LIS))
# Judge status: Accepted
N=int(input())
N_26=[]

while N>0:
    N-=1
    N_mod=N%26
    N=N//26
    N_26.append(chr(97+N_mod))
print("".join(list(reversed(N_26))))
# Judge status: Accepted
h, n = map(int, input().split())
a = list(map(int, input().split()))

if h <= sum(a):
    print('Yes')
else:
    print('No')
# Judge status: Accepted
n,d=map(int,input().split())
print((n+2*d)//(2*d+1))
# Judge status: Wrong Answer
s = input()
ans = 0
for i in range(0,len(s)):
  if s[i] != s[len(s)-i-1]:
    ans += 1
print(ans/2)
# Judge status: Wrong Answer
c=raw_input()
if c=="a,e,i,o,u,y":
  print "vowel"
else:
  print "consonant"
# Judge status: Accepted
n,m=map(int,input().split())

limax=0
rimin=n
for i in range(m):
    li,ri=map(int,input().split())
    if li>limax:
        limax=li
    if ri<rimin:
        rimin=ri
if rimin<limax:
    print(0)
else:
    print(rimin-limax+1)
# Judge status: Accepted
import itertools
import math
n = int(input())
x,y = [0] * n, [0] * n
for i in range(n):
  dx,dy = map(int,input().split())
  x[i], y[i] = dx, dy
ans = 0
for i in itertools.permutations(range(n)):
  i = list(i)
  for j in range(n - 1):
    ans += math.sqrt(pow(x[i[j]] - x[i[j + 1]], 2) + pow(y[i[j]] - y[i[j + 1]], 2))
num = 1
for i in range(n):
  num *= i + 1
print(ans / num)
# Judge status: Wrong Answer
n = int(input())
count = 0
for a in range(1, n):
    count += (n - 0.5) // a
print(count)
# Judge status: Wrong Answer
N=int(input())
A=list(map(int,input().split()))
for i in range(N):
  A[i] = A[i] - i - 1
b = sum(A) // N
b1 = b + 1
ans = 0
ans1 = 0
for i in range(N):
  ans += abs(A[i] - b)
  ans1 += abs(A[i] - b1)
print(min(ans,ans1))
# Judge status: Accepted
A, B, C, K = map(int, input().split())
 
if K <= A:
    print(K)
elif A < K <= A+B:
    print(A)
else:
    K -= (A+B)
    print(A-K)
# Judge status: Accepted
def main():
    x = input()

    s = 0
    count = 0
    for cur in x:
        if cur == "S":
            s += 1
        else:
            if s != 0:
                s -= 1
            else:
                count += 2

    print(count)


if __name__ == '__main__':
    main()
# Judge status: Wrong Answer
x, y, z = map(int, input().split())

ans = 0
while x > y + z:
    ans += 1
    x -= y + z

print(ans)
# Judge status: Accepted
print((sum(map(int,input().split()))+1)//2)
# Judge status: Wrong Answer
n = int(input())

d = {}
ans = 0
for i in range(n):
    s = str(input())
    s = "".join(sorted(list(s)))
    if s in d:
        d[s] += 1
    else:
        d[s] = 1

for j in d.values():
    if j == 1:
        pass
    elif j == 2:
        ans += 1
    else:
        ans += j
        
print(ans)
# Judge status: Accepted
S,W = map(int, input().split())
s = 'safe'  if S > W else 'unsafe'
print(s)
# Judge status: Accepted
#import math
#g = math.gcd
import fractions
g = fractions.gcd
n = int(input())
a = [int(_) for _ in input().split()]
mod = 10**9 + 7
lcm = 1
for x in a:
    lcm *= x // g(lcm, x)
ans = 0
for x in a:
    ans += lcm * pow(x, mod - 2, mod)
    ans %= mod
print(ans)
# Judge status: Wrong Answer
s = input()

k = 'keyence'


for i in range(1, 8):
    a, b = i, 7-i
    l, r = k[:i], k[i:]
    
    if l in s and r in s:
        print("YES")
        exit()

print('NO')
# Judge status: Wrong Answer
s = input()

if '00' in s:
    print('NA')
elif int(s[:2]) <= 12 and int(s[2:]) <= 12:
    print('AMBIGUOUS')
elif int(s[2:]) > 13:
    print('MMYY')
elif int(s[:2]) > 13:
    print('YYMM')
else:
    print('NA')
# Judge status: Accepted
x=int(input())
from math import gcd
g=gcd(x,360)
print(360//g)
# Judge status: Accepted
import math
a,b,c,d = map(int,input().split())

if math.ceil(c/b) <= math.ceil(a/d):
    print("Yes")
else:
    print("No")
# Judge status: Accepted
a,b,t = list(map(int,input().split()))
print("{:}".format(t//a*b))
# Judge status: Accepted
import fractions

a, b = map(int, input().split()) 
print(a*b//fractions.gcd(a,b))
# Judge status: Accepted
n = int(input())
a = list(map(int, input().split()))
b = [0] * n
for i, x in enumerate(a):
    b[x - 1] = i + 1
print(' '.join(map(str, b)))
# Judge status: Accepted
a,b=map(int,input().split())
if 0<a:
  print("Positive")
  exit()
else:
  if b<0:
    S=(b-a+1)%2
    if S==1:
      print("Negative")
    else:
      print("Positive")
  else:
    print("Zero")
# Judge status: Wrong Answer
n, l = map(int, input().split())

aji = (l + l+n-1)*(n/2)

if l >= 0 :
    ans = aji - l
elif l < 0 and abs(l)-n > 0 :
    ans = aji - (l+n-1)
else :
    ans = aji

print(int(ans))
# Judge status: Wrong Answer
n = int(input())
S = input()

tmp = []
for s in S:
    if ord(s)+n > ord('Z'):
        tmp.append(ord('A')+(ord(s)+n)%ord('Z'))
    else:
        tmp.append(ord(s)+n)

ans = ''
for i in tmp:
    ans += chr(i)
print(ans)
# Judge status: Wrong Answer
N,M,X,Y = map(int,input().split())
x = [X] + list(map(int,input().split()))
y = [Y] + list(map(int,input().split()))

if max(x) >= min(y):
    print("War")
else:
    print("NO War")
# Judge status: Wrong Answer
n=int(input())
a=int(input())
b=int(input())
c=int(input())
d=int(input())
e=int(input())
from math import floor
print(5+floor(n/min(a,b,c,d,e)))
# Judge status: Wrong Answer
n,x,y = list(map(int,input().split()))
ans = [0]*(n-1)
for i in range(n-1):
    for j in range(i+1,n):
        ans[min(j-i,1+abs(x-1-i)+abs(y-1-j))]+=1
for num in ans:
    print(num)
# Judge status: Accepted
n = int(input())
a = list(map(int, input().split()))
even = []
odd = []
for i in range(n):
    if i % 2:
        even.append(a[i])
    else:
        odd.append(a[i])
if n % 2 == 0:
    print(*even[::-1], end=" ")
    print(*odd)
else:
    print(*odd[::-1], end=" ")
    print(*even)
# Judge status: Accepted
import sys

input = sys.stdin.readline
d = {}
for _ in range(int(input())):
    s = input().replace("\n", "")
    if s in d:
        d[s] += 1
    else:
        d[s] = 1

x = max(d.values())
l = sorted(s for (s, i) in d.items() if i == x)
print(*l, sep="\n")
# Judge status: Accepted
n, m, k = map(int, input().split())

for i in range(n+1):
    for j in range(m+1):
        area = i*j + (n-i) * (m-j)
        if k == area:
            print('Yes')
            exit()
print('No')
# Judge status: Accepted
from collections import deque
n = int(input())
a = list(map(int,input().split()))
b = deque()
for i in range(n):
  if i%2==0:
    b.append(a[i])
  else:
    b.appendleft(a[i])
if n%2==0:
  print(*b)
else:
  print(*reversed(b))
# Judge status: Accepted
h, n = list(map(int,input().split()))
a = list(map(int,input().split()))

if(sum(a) >= h):
    print('Yes')
else:
    print('No')
# Judge status: Accepted
k = int(input())

x = 7
e = 10

for i in range(10000000):
    # print(x)
    if x % k == 0:
        print(i + 1)
        exit()
    x = (x * e + 7) % k

print("-1")
# Judge status: Accepted
# -*- coding: utf-8 -*-

s = str(input())

if s[0] == s[1] or s[1] == s[2] or s[2] == s[3]:
    print('Bad')
else:
    print('Good')
# Judge status: Accepted
def main():
    A, B = input().split()
    A = int(A)
    B_big, B_small = B.split(".")
    B_big = int(B_big)
    B_small = int(B_small)
    print(A*B_big + A*B_small//100)
 
 
if __name__ == "__main__":
    main()
# Judge status: Accepted
n=int(input())
exist=False
for i in range(n):
  for j in range(n):
    if 4*i+7*j==n:
      print("Yes")
      exist=True
    if exist:
      break
  if exist:
    break
if not exist:
  print("No")
# Judge status: Wrong Answer
L,R = map(int,input().split())
L = L%2019 
R = R%2019
ans = 2018
for i in range(L,R+1):
    for j in range(i+1,R+1):
        ans=min(ans,i*j)
print(ans)
# Judge status: Wrong Answer
comp=753
s=input()
ans=1000000000
for i in range(7,0,-1):
  if s.count(str(i)):
    left = s.find(str(i))
    while left!=-1 and left<=len(s)-3:
      tmp = max(ans,int(s[left:left+3]))
      ans = min(ans, abs(comp-ans))
      left = s.find(str(i),left+1)
    break
print(ans)
# Judge status: Accepted
list_n = list(input())
l = len(list_n)

a = list_n.count("0")
b = list_n.count("1")
ab = max(a, b) - min(a, b)

print(l-ab)
# Judge status: Accepted
n = int(input())
a = list(map(int, input().split()))
c1 = c2 = 0
for x in a:
    if x % 4 == 0:
        c1 += 1
    elif x % 2 == 0:
        c2 += 1
print(("Yes" if c1 + int(c2 / 2) >= int(n / 2) else "No"))
# Judge status: Accepted
import math
N = int(input())
ans = 10**13
for k in range(1,math.floor(math.sqrt(N))+1):
    if N % k == 0:
        ans = min(ans,k+N//k-2)
print(ans)
# Judge status: Accepted
n=int(input())
flag=0
for i in range(1,10):
	for j in range(1,10):
		if i*j==n:
			flag+=1
if flag>=1:
	print('Yes')
else:
	print('No')
# Judge status: Accepted
n,k = map(int,input().split())
count = 0
for i in range(k, n+2):
    min_num = int((i-1) * i /2)
    max_num = int(i*(2*n-i+1)/2)
    count += (max_num - min_num+1)
print(count % (10**9 + 7))
# Judge status: Wrong Answer
n,d=map(int,input().split())
print(n//d)
# Judge status: Wrong Answer
k=int(input())
s=str(input())
if(len(s)==k):
    print(s)
elif (len(s)>k):
    i=len(s)-k
    palabra=s[i:len(s)]+s[0:i]
    print(palabra)
# Judge status: Wrong Answer
n=int(input())
d=list(map(int,input().split()))
d.sort()
a=int(n/2)
i=int(n/2-1)
print(d)
if d[a]!=d[i]:
    num=d[a]-d[i]
    print(num)
else:
    print(0)
# Judge status: Accepted
s=input()
if(s[-1]=='s'):
  print(s+'es')
else:
  print(s+'s')
# Judge status: Wrong Answer
a, b, n = map(int, input().split())
print(a * (b-1) // b)
# Judge status: Wrong Answer
N, X, Y = list(map(int,input().split()))
X -= 1
Y -= 1
out = [0]*N
for i in range(N-1):
  for j in range(i+1,N):
    out[min(j-i, abs(i-X)+1+abs(j-Y))] += 1
for i in range(N-1):
  print(out[i])
# Judge status: Wrong Answer
import sys
input = sys.stdin.readline

W,H,N = list(map(int,input().split()))
x0 = 0
y0 = 0
x1 = W
y1 = H
X = [x0,x1,y0,y1]
for i in range(N):
    x,y,a = list(map(int,input().split()))

    if a == 1:
        x0 = x
    elif a == 2:
        x1 = x
    elif a == 3:
        y0 = y
    elif a == 4:
        y1 = y

print(max(0,(x1-x0)*(y1-y0)))
# Judge status: Accepted
s = input()
a = ""
for i in s:
    if i == "0":
        a+="0"
    elif i == "1":
        a+="1"
    else:
        if a!="":
            a=a[:-1]
        
print(a)
# Judge status: Wrong Answer
n, m, k = map(int, input().split())
for i in range(n):
    for j in range(m):
        if i * (m - j) + j * (n - i) == k:
            print("Yes")
            exit()
print("No")
# Judge status: Wrong Answer
def main():
    N, X, T = map(int, input().split())
    print(T * (N//X+1))


if __name__ == "__main__":
    main()
# Judge status: Accepted
import collections
n=int(input())
a=list(map(int,input().split()))
if a[0]==0 and a.count(0)==1:
  ans=1
else:
  ans=0
a=collections.Counter(a)
for i in range(max(a)):
  ans*=a[i]**a[i+1]
  ans%=998244353
print(ans)
# Judge status: Accepted
a=ina=input()
b=input()

if a[0]==b[2] and a[1]==b[1] and a[2]==b[0]:
    print("YES")
else:
    print("NO")
# Judge status: Accepted
N = int(input())
H = list(map(int, input().split()))

for i in range(N-1):
    if H[i+1] > H[i]:
        H[i+1] -= 1
    if H[i+1] < H[i]:
        print("No")
        break
else:
        print("Yes")
# Judge status: Accepted
N=int(input())
R=(1000-N%1000)%1000
print(R)
# Judge status: Accepted
S=list(input())
T=list(input())
p=-1; i=0; e=0
for i in range(len(S)-len(T)+1):
  for j in range(len(T)):
    if S[j+i]==T[j] or S[j+i]=="?":
      e=e+1
      #print(i,p,e)
    else:
      e=0
      break
    if e==len(T):
      p=i
      e=0
    #print(i,p,e)
if p==-1:
  print("UNRESTORABLE")
else:
  S[p:p+len(T)]=T
  for i in range(len(S)):
    if S[i]=="?":
      S[i]="a"
  print("".join(S))
# Judge status: Accepted
n = int(input())
p = list(map(int,input().rstrip().split()))
pp = sorted(p)
cnt = 0
for i in range(n):
    if p[i]!=pp[i]:
        cnt+=1
if cnt>2:
    print("NO")
else:
    print("YES")
# Judge status: Wrong Answer
ab,bc,ca = map(int,input().split())

print(ab*bc/2)
# Judge status: Wrong Answer
a,b=input().split()
a=int(a)
b=int(b)
c=list(map(int,input().split()))
c.sort()
d=sum(c)
e=0
if a<=b:
  print(0)
else:
  for i in range(b):
    e=e+c[-b]
  print(d-e)
# Judge status: Accepted
s = list(input())
ans = ""

for c in s:
  if c == "0":
    ans += "0"
  if c == "1":
    ans += "1"
  if c == "B":
    if ans != "":
      ans = ans[:len(ans)-1]

print(ans)
# Judge status: Accepted
A, B = map(int, input().split())
if A <= 9 and B <= 9:
    print(A * B)
else:
    print(-1)
# Judge status: Accepted
from itertools import accumulate
N = int(input())
an = list(map(int, input().split()))
res = [0] + an
res = list(accumulate(res))
ans = 10e+9
for i in range(1, N):
    ans = min(ans, abs(res[i] - (res[-1]-res[i])))
print(ans)
# Judge status: Accepted

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

print('Yes' if a <= c <= b else 'No')
# Judge status: Wrong Answer
def main():
    '''
    N = aq + r (0 <= r <= a-1)よりΣrを最大にするのはr = a-1のとき 
    '''
    N = int(input())
    N -= 1
    print(N * N // 2)


if __name__ == '__main__':
    main()
# Judge status: Accepted
S=input()
res=0
for i in range(len(S)+1):
    for j in range(i):
        t=True
        s=S[j:i]
        for k in range(len(s)):
            if(s[k]!='A' and s[k]!='C' and s[k]!='G' and s[k]!='T'):
                t=0
                break
        if(t):
            res=max(res,len(s))
print(res)
# Judge status: Accepted
N, K = [int(x) for x in input().split()]
D = input().split()

for payment in range(N, 10*N+1):
    if all(char not in D for char in str(payment)):
        print(payment)
        break
# Judge status: Accepted
x,y=map(int,input().split())
A=[2]
B=[4,6,9,11]
C=[1,3,5,7,8,10,12]
if x in B and y in B:
  print("Yes")
elif x in C and y in C:
  print("Yes")
else:
  print("No")
# Judge status: Accepted
N,M = map(int,input().split())

if N == 1 and M == 1:
    ans = 1
elif N == 1:
    ans = (M-2)
elif M == 1:
    ans = (N-2)
else:
    ans = (M-2) * (N-2)
print(ans)
# Judge status: Wrong Answer
a,b=map(int,input().split())
attack=[int(i) for i in input().split()]
sum=0
for j in attack:
  sum+=j
if sum>a:
  print("YES")
else:
  print("NO")
# Judge status: Accepted
N = int(input())
Ss = []
d = 97
for i in range(N):
    Ss.append(input())
from collections import Counter
counter = [float('inf') for i in range(26)]
for S in Ss:
    D = Counter(S)
    for key in range(d,d+26):
        counter[key-d] = min(D[chr(key)],counter[key-d])
ans = ''
for i,e in enumerate(counter):
    if e == float('inf'):
        continue
    for j in range(e):
        ans += chr(i+d)
print(ans)
# Judge status: Wrong Answer
def main():
    n = int(input())
    print(n * (n - 1) / 2)


main()
# Judge status: Wrong Answer
N,K = map(int,input().split())
p = [int(m) for m in input().split()]
p.sort()
ans = 0

if K == 1:
    print(*p)
elif K == 2:
    print(p[0]+p[1])
else:
    for i in range(K):
        ans += p[i]
    print(ans)
# Judge status: Wrong Answer
n = int(input())
w = list(map(int,input().split()))
l = []
for i in range(n-1):
  a = abs(sum(w[0:i+1]) - sum(w[i+1:n+1]))
  l.append(a)
print(l.index(min(l))+1)
# Judge status: Accepted
N=int(input())
A=[int(input()) for i in range(N)] 
B=sorted(A)
for i in A:
    if i==B[-1]:
        print(B[-2])
    else:
        print(B[-1])
# Judge status: Accepted
from collections import Counter

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

cnt = Counter(A)

cmb = 0
for a, c in cnt.items():
    if c >= 2:
        cmb += c * (c - 1) // 2

for a in A:
    minus = 0 if cnt[a] < 2 else cnt[a] * (cnt[a]-1) // 2
    c = cnt[a] - 1
    plus = 0 if c < 2 else c * (c-1) // 2
    ans = cmb - minus + plus
    print(ans)
# Judge status: Wrong Answer
N = int(input())
A = map(int, input().split())
import collections

A_count = collections.Counter(A)

keys = sorted(list(A_count.keys()), reverse=True)

hen_list = []
flag = 0
for key in keys:
    if A_count[key] >= 4:
        hen_list.append(key)
        hen_list.append(key)
    if A_count[key] >= 2:
        hen_list.append(key)
    if len(hen_list) == 2:
        flag = 1
        break
if flag == 1:
    print(hen_list[0] * hen_list[1])
else:
    print(0)
# Judge status: Accepted
n = int(input())
s = input()
ans = []
for i in range(len(s)):
    ans.append( chr((ord(s[i]) + n - 65) % 26 + 65) )
for i in range(len(s)):
    print(ans[i], end='')
print()
# Judge status: Accepted
n=int(input())
H=list(map(int, input().split()))

ans = 0
p = 0
for i in range(n-1):
    if H[i] >= H[i+1]:
        p += 1
    else:
        ans = max(ans, p)
        p = 0
ans = max(ans, p)
print(ans)
# Judge status: Wrong Answer
S=list(input())
T=list(input())
b=0
print(S)
print(T)

for i in range(0,len(S)):
    if S[i]!= T[i]:
        b+=1

print(b)
# Judge status: Accepted
def main():
    a, b, c, d = tuple([int(_x) for _x in input().split()])
    print(max(a*c, a*d, b*c, b*d))


main()
# Judge status: Accepted
n = int(input())

cnt = 0
for i in range(1, n+1):
  if len(str(i)) % 2 == 1:
    cnt += 1
print(cnt)
# Judge status: Accepted
N, M = map(int, input().split())

real = M - 2*N

if real < 0:
    ans = M // 2
elif real == 0:
    ans = real
else:
    a = real // 4
    ans = a + N

print(ans)
# Judge status: Accepted
s =int(input())
sl =[s]
for i in range(10**6):
    if sl[-1]%2 ==0:
        new_sl =sl[-1] //2
    else:
        new_sl =3*sl[-1]+1
    if new_sl in sl:
        print(i+2)
        break

    sl.append(new_sl)
# Judge status: Accepted
w = input()
for i in range(len(w)):
    if w.count(w[i]) % 2 == 1:
        print('No')
        exit()
print('Yes')
# Judge status: Accepted
import math
from decimal import Decimal
a, b = map(float, input().split())
print(math.floor(Decimal(str(a))*Decimal(str(b))))
# Judge status: Accepted
print((int(input()) + int(input())) * int(input()) // 2)
# Judge status: Accepted
import math
H = int(input())
ans = 1
atk = 1
while H > 1:
    H = math.floor(H/2)
    atk *= 2
    ans += atk
print(ans)
# Judge status: Wrong Answer
n = int(input())
s = input()
a = []
ans = 0

for i in s:
    a.append(i)

for i in range(n):
    b = set(a[:i + 1]) & set(a[i:])
    ans = max(ans, len(b))

print(ans)
# Judge status: Accepted
N = int(input())
T, X, Y = 0, 0, 0
count = 0
for i in range(N):
  t, x, y = map(int, input().split())
  dt = t - T
  dist = abs(x - X) + abs(y - Y)
  if dist <= dt and t%2 == (x+y)%2:
    count += 1
  T, X, Y = t, x, y
print('Yes' if count == N else 'No')
# Judge status: Accepted
import math as mp
a,b=map(int,input().split())
print(a*b//mp.gcd(a,b))
# Judge status: Accepted
import sys
def I(): return int(sys.stdin.readline())
def LI(): return [int(x) for x in sys.stdin.readline().split()]

def main():
    H = I()

    count = 0
    while(H>0):
        H = H // 2
        count += 1

    print(pow(2,count)-1)



if __name__ == "__main__":
    main()
# Judge status: Accepted
mod = 10**9+7
n, m = map(int, input().split())
if abs(n-m) >= 2:
    print(0)
    exit()
x, y = 1, 1
for i in range(1, n+1):
    x *= i
    x %= mod
for i in range(1, m+1):
    y *= i
    y %= mod
if n == m:
    print((2*x*y)%mod)
else:
    print((x*y)%mod)
# Judge status: Accepted
S = input()
K = int(input())

oz = ord("z")

ans = ""

for s in S[:-1]:
    if s != "a" and oz+1-ord(s) <= K:
        K -= oz+1-ord(s)
        ans += "a"
    else:
        ans += s

ans += chr(((ord(S[-1])-ord("a")+K)%26)+ord("a"))

print(ans)
# Judge status: Accepted
W,H,N = map(int,input().split())
Xu,Xd,Yu,Yd=W,0,H,0
for i in range(N):
  x,y,a = map(int,input().split())
  if a==1:
    Xd=max(Xd,x)
  elif a==2:
    Xu=min(Xu,x)
  elif a==3:
    Yd=max(Yd,y)
  elif a==4:
    Yu=min(Yu,y)
X = max(0,Xu-Xd)
Y = max(0,Yu-Yd)
print(X*Y)
# Judge status: Accepted
a,b = map(int,input().split())
ans = ""

if a > b:
    for i in range(a):
        ans += str(b)
else:
    for i in range(b):
        ans += str(a)

print(ans)
# Judge status: Wrong Answer
T = list(input())
N = len(T)
for i in range(N):
  if i < N-1:
    if T[i] == '?':
      if T[i+1] == '?':
        T[i] = 'P'
        T[i+1] = 'D'
      elif T[i+1] == 'D':
        T[i] = 'P'
      else:
        T[i] = 'D'
  else:
    if T[i] == '?':
      T[i] = 'D'
      
print(''.join(T))
# Judge status: Accepted
s ,t= [x for x in input().split()]
A , B = [int(x) for x in input().split()]
U = input()
if s != t:
    if U == t :
        B -=1
    if U == s:
        A-= 1
print('{} {}'.format(A,B))
# Judge status: Accepted
x = list(map(int, input().split()))
# 0が何番目に有るか　リストなので＋１
print(x.index(0) + 1)
# Judge status: Wrong Answer
def main():
    N, T = map(int, input().split())
    min_c = 1001
    for _ in range(N):
        c, t = map(int, input().split())
        if t <= T and c < min_c:
            min_c = c
    if min_c == 1001:
        print("LTE")
    else:
        print(min_c)


if __name__ == '__main__':
    main()
# Judge status: Wrong Answer
import math
N = int(input())
a = math.ceil(N / 4)
b = math.ceil(N / 7)
ans = "No"
for i in range(a):
  for j in range(b):
    if i * 4 + j * 7 == N:
      ans = "Yes"
      break
  else:
    continue
  break
print(ans)
# Judge status: Accepted
n=int(input())


ans=0
tmp=0
p=1
if n%2==0:
    k=n//2
    while True:
        tmp =k//pow(5,p)

        ans+=tmp
        p+=1

        if tmp==0:
            break

print(ans)
# Judge status: Accepted
import sys
input = sys.stdin.readline
# sys.setrecursionlimit(100000)


def main():
    A, B, X = [int(i) for i in input().strip().split()]
    for i in range(B+1):
        if A + i == X:
            return "YES"
    return "NO"


if __name__ == "__main__":
    print(main())
# Judge status: Accepted
s=sorted(input())
t=sorted(input(),reverse=True)

if ''.join(t)>''.join(s):
    print('Yes')
else:
    print('No')
# Judge status: Accepted
n=input()
print("Yes" if n[0]==n[1]==n[2]or n[1]==n[2]==n[3] else "No")

#or and notを使う
# Judge status: Wrong Answer
from collections import deque
n = int(input())
a = list(map(int,input().split()))
b = deque()
for i in range(n):
    if i%2==0:
        b.append(a[i])
    else:
        b.appendleft(a[i])
print(*b)
# Judge status: Wrong Answer
ma = lambda :map(int,input().split())
n,k = ma()
A = list(ma())
import collections
co = collections.Counter(A)
print(max(0,len(co.items()) -k))
# Judge status: Accepted
#-*-coding:utf-8-*-
import sys
input=sys.stdin.readline
import numpy as np

def main():
    numbers=[]
    dp=[]
    n = int(input())
    numbers=np.array(list(map(int,input().split())),dtype=int)
    numbers.sort()
    print(numbers[n::2].sum())

if __name__=="__main__":
    main()
# Judge status: Accepted
import sys
input = lambda : sys.stdin.readline().rstrip()
sys.setrecursionlimit(max(1000, 10**9))
write = lambda x: sys.stdout.write(x+"\n")


h,n = map(int, input().split())
a = [None]*n
b = [None]*n
for i in range(n):
    a[i], b[i] = map(int, input().split())
    
dp = [float("inf")]*(h+1)
dp[0] = 0
for i in range(n):
    for j in range(1,h+1):
        dp[j] = min(dp[j], dp[max(0, j-a[i])] + b[i])
print(dp[h])