peterverebics/CodeNet_Python_428 huggingface dataset:
# Judge status: Accepted
def main():
    from collections import Counter
    N = int(input())
    S_count = Counter(input())
    P = 10**9+7
    ans = 1
    for v in S_count.values():
        ans *= v+1
        ans %= P
    print(ans-1)



main()
# Judge status: Wrong Answer
s = list(input())
k = int(input())
t = list(map(lambda x:ord(x)-ord("a"),s)) #a-zを0-25に正規化

for i in range(len(t)):
  diff = 26-t[i] #aになるまでの差
  if diff <= k:
    t[i]+=diff
    k-=diff
  else:
    continue
t[-1]+=k #k余りを一番最後に足す

#print("s:",s)
#print("t:",t)
u = "".join(list(map(lambda x:chr((x%26+ord("a"))),t)))
print(u)
# Judge status: Accepted
a, b, n = map(int, input().split())
x = min(b-1,n)
print((a*x)//b - a*(x//b))
# Judge status: Accepted
print("Heisei"if input()<="2019/04/30" else "TBD")
# Judge status: Accepted
N = input()
N = int(N)
x = N
total = 0
while x >=1:
    total += x
    x = x - 1
else: print(total)
# Judge status: Accepted
N = int(input())
if N == 2:
    print(2)
    exit()
ans = float('inf')
for i in range(2,N):
    A = i
    B = N - i
    tmp = 0
    for k in str(A):
        tmp += int(k)
    for k in str(B):
        tmp += int(k)
    ans = min(ans,tmp)
print(ans)
# Judge status: Wrong Answer
n = input()
if n.isupper() == True:
  print(n.lower())
elif n.islower() == True:
  print(n.upper())
# Judge status: Accepted
n = int(input())
r1 = 2
r2 = 1
if n == 1:
    print(1)
    exit()
else:
    for _ in range(n-1):
        r2 = r1 + r2
        r1 = r2 - r1
print(r2)
# Judge status: Accepted
n = int(input())
b = list(map(int,input().split()))
ans = 0
for i in range(n-2):
    ans += min(b[i],b[i+1])
print(b[0] + ans + b[-1])
# Judge status: Accepted
n,k=map(int,input().split())
d=list(map(int,input().split()))

for i in range(n,n*10+1):
     for x in d:
         if str(x) in str(i):
             break
     else:
         print(i)
         break
# Judge status: Accepted
d = int(input())
if d == 25:
    print('Christmas')
if d == 24:
    print('Christmas Eve')
if d == 23:
    print('Christmas Eve Eve')
if d == 22:
    print('Christmas Eve Eve Eve')
# Judge status: Accepted
s_17 = list(input())
s_18 = ''

for s in range(len(s_17)):
    if (s == 3):
        s_18 += '8'
    else:
        s_18 += s_17[s]

print(s_18)
# Judge status: Wrong Answer
n, d = map(int, input().split())
cnt = 0
for ti in range(n) :
  x, y = map(int, input().split())
  dist = (x**2 + y**2)**0.5
  if(dist >= d):
    cnt += 1
    
print(cnt)
# Judge status: Wrong Answer
import heapq

num = int(input())
a = [int(input()) for i in range(num)]
b = [max(a) for f in range(num)]
if sorted(a)[0] == sorted(a)[1]:
  for j in b:
    print(j)
else:
  b[a.index(max(a))] = sorted(a)[1]
  for j in b:
    print(j)
# Judge status: Wrong Answer
import math
from decimal import *

n, k = map(int, input().split())
nos = list(map(int, input().split()))
arr = [int(10e4)+1 for i in range(n)]
arr[0] = 0
if(n>1):
    arr[1] = abs(nos[1]-nos[0])
for i in range(2, n):
    for x in range(1, min(k, i)+1):
        arr[i] = min(arr[i], abs(nos[i-x]-nos[i])+arr[i-x])
print(arr[n-1])
# Judge status: Accepted
S = input()
if S[2]==S[3] and S[4]==S[5]:
  print("Yes")
else:
  print("No")
# Judge status: Accepted
a,b,c = map(int,input().split())

if a <= c <= b or (b <= c <= a):
  print("Yes")
else:
  print("No")
# Judge status: Wrong Answer
n,m=map(int, input().split())

num1=n*(n-1)*0.5
num2=m*(m-1)*0.5
# Judge status: Accepted
a = list(map(int, input().split()))
a.sort()
ans = a[0] * a[1]

for i in a:
    if i % 2 == 0:
        ans = 0
        break

print(ans)
# Judge status: Wrong Answer
n = int(input())
for i in range(1,10):
    for j in range(1,10):
        if(i*j==n):
            print("YES")
            exit()
print("NO")
# Judge status: Accepted
n, d = [int(e) for e in input().split()]

count = 0


for i in range(n):
    x, y = [int(e) for e in input().split()]
    
    if x * x + y * y <= d * d:
        count += 1

print(count)
# Judge status: Wrong Answer
import math

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

min_ind = a.index(min(a))

l = min_ind
r = n - (min_ind + 1)

b, c = divmod(l, k-1)
d, e = divmod(r, k-1)

if c + e >= k-1:
    print(math.ceil(l/(k-1)) + math.ceil(r/(k-1)) - 1)
else:
    print(math.ceil(l/(k-1)) + math.ceil(r/(k-1)))
# Judge status: Accepted

import math

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

print(int(math.ceil(H/A)))
# Judge status: Accepted
import re
n = input()
m = re.search('(\d+)\s(\d+)\s(\d+)', n)
a = int(m.group(1))
b = int(m.group(2))
c = int(m.group(3))
i = b // a
if c <= i:
    print(c)
else:
    print(i)
# Judge status: Wrong Answer
k, a, b = map(int, input().split())
if b - a < 2:
    print(k + 1)
elif b - a > 2:
    cnt = k - (a - 1)
    print((b - a) * cnt // 2 + 1 * cnt % 2 + a)
# Judge status: Accepted
S,W = map(int, input().split())
if W >= S:
    print('unsafe')
else:
    print('safe')
# Judge status: Accepted
import bisect

N = int(input())
A = [int(input()) for _ in range(N)]
dp = [-1] * N
dp[N-1] = A[0]

ans = 0
for i in range(1, N):
    target_index = bisect.bisect_left(dp, A[i])
    dp[target_index-1] = A[i]

print(N - dp.count(-1))
# Judge status: Accepted
a,b,c=map(int,input().split())
d=a+b+c
m=max(a,b,c)
if d%2==0:
  if m%2==0:
    m=m
  else:
    m=m+1
else:
  if m%2==0:
    m=m+1
  else:
    m=m
s=3*m
ans=s-d
ans//=2
print(ans)
# Judge status: Accepted
A, B = map(int, input().split())

if A % 2 != B % 2:
  K = "IMPOSSIBLE"
else:
  # B - K = - (A - K)
  # 2K = B - A
  K = int((B + A) / 2)
print(K)
# Judge status: Wrong Answer
s=input()
for i in range(len(s)):
    s[i]=="x"
print(s)
# Judge status: Wrong Answer
A,B,C = map(int,input().split())
#print(A,B,C)

if (C>=A) and (C<=B):
  print("YES")
else:
  print("NO")
# Judge status: Accepted
k,a,b = map(int,input().split())
cokie = 1
if b < a:
    cokie += k
    print(cokie)
else:
    if k < a-1 or b-a < 2:
        cokie += k
        print(cokie)
    else:
        cokie += a-1
        k -= a-1
        b_a = k//2
        hit = k%2
        cokie += b_a*(b-a) + hit 
        print(cokie)
# Judge status: Accepted
def gcd(a, b):
  if (b == 0): 
    return a
  return gcd(b, a % b)

arr = [int(input()) for i in range(int(input()))]
ans = 1
for i in arr:
  ans = (ans*i)//gcd(ans, i)
print(ans)
# Judge status: Accepted
c1 = input()
c2 = input()

if c1 == c2[::-1]:
    print('YES')
else:
    print('NO')
# Judge status: Accepted
N,M = map(int,input().split())
if M<2*N:
    cnt = M//2
else:
    cnt = N
    k = M-2*N
    cnt += k//4
print(cnt)
# Judge status: Wrong Answer
C=[0,0]
C[0]=list(map(str,input()))
C[1]=list(map(str,input()))
ans="No"
X=C[0][::-1]
if C[1]==X:
    ans="Yes"
print(ans)
# Judge status: Accepted
n = int(input())
h = (n // 500)*1000+((n%500)//5)*5
print(h)
# Judge status: Wrong Answer

import math
def main():

    a, b, c = map(int, input().split())
    if (c-a-b) > pow(10, 5):
        if c-a-b > 2 * math.sqrt(a*b): return "Yes"
        return "No"
    if (c-a-b) * (c-a-b) > 4 * a * b: return "Yes"
    return "No"

if __name__ == '__main__':
    print(main())
# Judge status: Wrong Answer
n, k = map(int, input().split())
a = [0] * n
b = [0] * n
sum = 0
arr = []
for i in range(n):
    a[i], b[i] = map(int, input().split())
# print(a, b)   
arr_list = list(zip(a, b))
# print(arr_list)
arr_list.sort()
# print(arr_list)

for i in range(n):
    # print(arr_list[i][1])
    sum += arr_list[i][1]
    if sum >= k:
        answer = a[i]
        break

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

if sum(a) >= 22:
    print('bust')
else:
    print('win')
# Judge status: Wrong Answer
s=str(input())
if s[2]==s[3] and s[4]==s[5]:
    print("YES")
else:
    print("NO")
# Judge status: Accepted
N = int(input())
pre = None
is_inc = None
ans = 1
for num in list(map(int, input().split())):
    if pre is None:
        pre = num
        continue

    if is_inc is None and num > pre:
        is_inc = True
    elif is_inc is None and num < pre:
        is_inc = False
    elif (is_inc and num < pre) or (not is_inc and num > pre):
        ans += 1
        is_inc = None

    pre = num

print(ans)
# Judge status: Accepted
N,L = map(int,input().split())
S = sorted([input() for n in range(N)])

print("".join(S))
# Judge status: Accepted
import math
a, b = map(int, input().split())
print(math.ceil((a + b) / 2))
# Judge status: Accepted
N, A, B = [int(x) for x in input().split()]
S = input()
total = 0
Btotal = 0
for n in range(N):
  if S[n]=="a" and total<A+B:
    print("Yes")
    total += 1
  elif S[n]=="b" and total<A+B and Btotal<B:
    print("Yes")
    total += 1
    Btotal += 1
  else:
    print("No")
# Judge status: Accepted
from collections import deque
n=int(input())
a=list(map(int,input().split()))
ans=deque()
rev=False
if n&1:
   rev=True 
for i in a:
    if rev:
        ans.appendleft(i)
    else:
        ans.append(i)
    rev=not rev
print(*ans)
# Judge status: Accepted
N = int(input())
A = list(map(int, input().split()))
cap = [[0, 0] for _ in range(N+1)]
cap[-1] = [A[-1], A[-1]]
for i in range(N-1,-1,-1):
    cap[i][0] = (cap[i+1][0] + 2 - 1)//2
    cap[i][1] = cap[i+1][1] + A[i]
ans = 1
nodes = 1
failed = nodes < cap[0][0]
for i in range(N):
    nodes = min((nodes - A[i])*2, cap[i+1][1])
    if nodes < cap[i+1][0]:
        failed = True
        break
    ans += nodes
print(-1 if failed else ans)
# Judge status: Wrong Answer
def is_sum_nine(str_N):
    sum = 0
    for i in range(len(str_N)):
        sum += int(str_N[i])
    if len(str(sum)) < 5:
        if sum % 9 == 0:
            return True
        else:
            return False
    else:
        is_sum_nine(str(sum))


def main():
    N = str(abs(int(input())))
    if is_sum_nine(N):
        print("Yes")
    else:
        print("No")


if __name__ == "__main__":
    main()
# Judge status: Wrong Answer
import math
x = int(input())
if x % 11 == 0:
  print(math.ceil(x/11)*2)
elif x % 11 <= 5:
  print(math.ceil(x/11)*2-1)
elif 5 < x % 11 < 11:
  print(math.ceil(x/11)*2)
# Judge status: Accepted
def calc(n):
	if n % 100 != 0:
		return 0
	return calc(n/100) + 1

def resolve():
	d, n = map(int, input().split())
	n = n + calc(n)
	print(100**d*n)
resolve()
# Judge status: Accepted
N = int(input())

ans = 10000000000000000000
for i in range(1,1000001):
  if N%i == 0:
    ans = min(ans,i+N//i-2)
    
print(ans)
# Judge status: Wrong Answer
N, L = map(int, input().split())
S = [input() for i in range(N)]
S.sort(reverse = True)
print(''.join(S))
# Judge status: Wrong Answer

X, Y, A, B, C = map(int, input().split())
P = sorted(map(int, input().split()))
Q = sorted(map(int, input().split()))
R = sorted(map(int, input().split()))

ans = 0
for _ in range(X):
    if not R or P[-1] > R[-1]:
        ans += P.pop()
    else:
        ans += R.pop()

for _ in range(Y):
    if not R or Q[-1] > R[-1]:
        ans += Q.pop()
    else:
        ans += R.pop()

print(ans)
# Judge status: Accepted

N = int(input())

memo = [0]*100

for n in range(1,N+1):
    s = str(n)
    memo[int(s[0])*10+int(s[-1])] += 1

cnt = 0
for i in range(10):
    for j in range(i,10):
        cnt += memo[i*10+j]*memo[j*10+i]*(1+int(i!=j))

print(cnt)
# Judge status: Accepted
import sys, math

max_int = 1000000001  # 10^9+1
min_int = -max_int

a, b, h, m = map(int, sys.stdin.readline().split())

alpha = abs(math.pi * (h / 6 + m / 360 - m / 30))
if alpha > math.pi:
    alpha = 2 * math.pi - alpha

print((a ** 2 + b ** 2 - 2 * a * b * math.cos(alpha)) ** 0.5)
# Judge status: Accepted
s = input()
top = ''
n = int(input())
isReverse = False
for i in range(n):
    Q = input().split()
    if(Q[0] == '1'):
        isReverse = not isReverse
    else:
        if Q[1] == '1':
            if isReverse: s += Q[2]
            else: top += Q[2]
        else:
            if isReverse: top += Q[2]
            else: s += Q[2]
if isReverse: s = s[::-1] + top
else: s = top[::-1] + s
print(s)
# Judge status: Wrong Answer
N = int(input())
A, B = [0]*N, [0]*N
for i in range(N):
  A[i], B[i] = map(int, input().split())

ans = 0
for i in range(N-1, -1, -1):
  j = 1
  while j*B[i] - (A[i] + ans) < 0:
    j += 1
  ans += j*B[i] - (A[i] + ans)
print(ans)
# Judge status: Wrong Answer
x,y = map(int,input().split())
if (x<=5):
    print(y)
elif (x>=13):
    print(0)
else :
    print(y/2)
# Judge status: Accepted
N=int(input())
count = 0
for a in range(1,1000001):
	count+=(N-1)//a
print(count)
# Judge status: Accepted
a,b,k = map(int, input().split())

if a-k >= 0:
    print(a-k, b)
elif a+b-k>=0:
    print(0, a+b-k)
else:
    print(0, 0)
# Judge status: Accepted
L = list(input())

if L[len(L)-1]=='3':
	print('bon')
elif L[len(L)-1]=='0' or L[len(L)-1]=='1' or L[len(L)-1]=='6' or L[len(L)-1]=='8':
	print('pon')
else:
	print('hon')
# Judge status: Accepted
from collections import defaultdict


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

A.sort()

dict = defaultdict(int)

count = 0
select = []
for _ in range(n):
    length = A.pop()

    if dict[length] > 0:
        dict[length] -= 1
        select.append(length)
        count += 1
    else:
        dict[length] += 1

    if count == 2:
        break

if len(select) < 2:
    print(0)
else:
    a = select.pop()
    b = select.pop()
    print(a*b)
# Judge status: Accepted
S = input()
len_S = len(S)

if len_S == len(set(S)):
  print("yes")
else:
  print("no")
# Judge status: Accepted
k=int(input())
a,b=map(int,input().split())
print("OK" if (b//k)*k>=a else "NG")
# Judge status: Accepted
A, V = map(int, input().split())
B, W = map(int, input().split())
T = int(input())
print("YES" if abs(A-B)<=(V-W)*T else "NO")
# Judge status: Accepted
import sys
import math
read = sys.stdin.buffer.read #全てまとめて文字列として格納
readline = sys.stdin.buffer.readline # 一行読む
readlines = sys.stdin.buffer.readlines # 全行リストに格納
H = int(read())
if H == 1:
  print(1)
  exit()

EXP = math.floor(math.log(H,2))
print(str(int(2**(EXP+1)-1)))
# Judge status: Accepted
n=int(input())
a=[int(input()) for i in range(n)]
c=0
for i in range(1,n+1):
  c=a[c]-1
  if c==1:
    print(i)
    break
else:
  print(-1)
# Judge status: Accepted
k = int(input())
print(k // 2 * ((k + 1) // 2))
# Judge status: Accepted
N = int(input())

ans = 0
for a in range(1, N+1):
    x = N // a

    if N % a == 0:
        ans += x - 1
    else:
        ans += x

print(ans)
# Judge status: Accepted
n, k = map(int, input().split())
a = list(map(int, input().split()))
s = 1
c = 0
d = {}
t = []
# 順番をdictで持つ
while not s in d.keys():
    d[s] = c
    t.append(s)
    c += 1
    s = a[s-1]
l = c - d[s]
m = len(d.keys()) - l
if m >= k:
    print(t[k])
else:
    print(t[(k - m) % l + m])
# Judge status: Accepted
N = int(input())
a = list(map(int,input().split()))

a.sort(reverse=True)
Alice = 0
Bob = 0

for i in range(N):
    if i%2 == 0:
        Alice += a[i]
    else:
        Bob += a[i]
        
print(Alice-Bob)
# Judge status: Accepted
X,N=map(int,input().split())
P=set(map(int,input().split()))
l=[0]+[(1+i//2)*(-1 if i%2==0 else 1) for i in range(101)]
for i in l:
    if X+i not in P:
        print(X+i)
        break
# Judge status: Wrong Answer
import sys
s = str(input())

a = int((len(s)-1)/2)
b = int(((len(s)+3)/2)-1)
s1 = s[:a]
s2 = s[b:]

for i in range(len(s1)//2):
    if s1[i] != s1[-1-i] or s2[i] != s2[-1-i]:
        print("No")
        sys.exit()

print("Yes")
# Judge status: Wrong Answer
N,L = map(int,input().split())
wordlist = []
for i in range(N):
    x = input()
    wordlist.append(x)

print(sorted(wordlist))
# Judge status: Accepted
S = input()
N = len(S)
mod = 2019
num = [0 for i in range(2019)]
num[0] = 1
t = 1
rem = 0

for i in reversed(S):
    rem += int(i) * t
    rem %= mod
    t *= 10
    t %= mod
    num[rem] += 1

print(int(sum([i * (i-1) / 2 for i in num])))
# Judge status: Accepted
a, b, c = map(int, input().split())
if b - a == c - b:
  print("YES")
else:
  print("NO")
# Judge status: Accepted
n = int(input())
a = list(map(int, input().split()))

sumA = sum(a)
x_y = []
x = 0

for i in range(n-1):
    x += a[i]
    y = sumA - x
    x_y.append(abs(x-y))

print(min(x_y))
# Judge status: Accepted
import sys

r, g, b = sys.stdin.readline().split()

def main():
    ans = 'YES' if not int(g + b) % 4 else 'NO'
    print(ans)

if __name__ ==  '__main__':
    main()
# Judge status: Accepted
s =input()
if ("a" in s and "b" in s and "c" in s):
    print("Yes")
else:
    print("No")
# Judge status: Accepted
a,b =map(int,input().split())
print("Even" if (a*b)%2==0 else "Odd")
# Judge status: Accepted
def i():
	return int(input())
def i2():
	return map(int,input().split())
def s():
	return str(input())
def l():
	return list(input())
def intl():
	return list(int(k) for k in input().split())

x,y = i2()
for i in range(x+1):
	if 2*i + 4*(x-i) == y:
		print("Yes")
		exit()
print("No")
# Judge status: Accepted
S = input()
a = S.count("a")
b = S.count("b")
c = S.count("c")

if abs(a-b) <= 1 and abs(a-c) <= 1 and abs(b-c) <= 1:
  print("YES")
else:
  print("NO")
# Judge status: Accepted
from itertools import permutations

n = int(input())
p = tuple(map(int, input().split()))
q = tuple(map(int, input().split()))
a = list(permutations(range(1, n + 1)))
print(abs(a.index(p) - a.index(q)))
# Judge status: Accepted
K,X=map(int,input().split())
print(" ".join(map(str,range(X-K+1,X+K))))
# Judge status: Accepted
N = int(input())
H = [int(h) for h in input().split()]

cnt = 0
ans = 0

i = 0

while i < N-1:
    if H[i] < H[i+1]:
        ans = max(ans, cnt)
        cnt = 0
    else:
        cnt += 1
    i += 1
ans = max(ans, cnt)
print(ans)
# Judge status: Accepted
# print('a' if 'a' <= input() <= 'z' else 'A')
print(['A','a']['a' <= input() <= 'z'])
# Judge status: Wrong Answer
in_str = input()
N = int(in_str)
in_list = input().split(' ')
count = 0

for i in range(N):
    if i%2==0:
        print(i)
        if int(in_list[i])%2==1:
            count += 1
            print(i)
            print(count)

print(count)
# Judge status: Accepted
#!/usr/bin/env python3
n, m = map(int, input().split())
a = [input() for _ in range(n)]
b = [input() for _ in range(m)]
for i in range(n - m + 1):
    for j in range(n - m + 1):
        if all(b[k] == a[i + k][j:j + m] for k in range(m)):
            print("Yes")
            exit()
print("No")
# Judge status: Accepted
import collections

n = int(input())
a = list(map(int, input().split()))
ax = []
for i in a:
    if (i % 4 == 0):
        t = 4
    elif (i % 2 == 0):
        t = 2
    else:
        t = 1
    ax.append(t)

ay = collections.Counter(ax)
if((ay[2] == 0 and ay[1] <= ay[4]+1) or(ay[2] != 0 and ay[1] <= ay[4])):
    print("Yes")
else:
    print("No")
# Judge status: Wrong Answer
a, b = map(int, input().split())

if a > 0 and b > 0 or a < 0 and b < 0:
    if a > b:
        print(a-b+2)
    else:
        print(b-a)
elif abs(a) == abs(b):
    print(1)
else:
    if a == 0 or b == 0:
        print(abs(abs(a)-abs(b)))
    else:
        print(abs(abs(a)-abs(b))+1)
# Judge status: Accepted
c=input()
print(chr(ord(c)+1))
# Judge status: Wrong Answer
N, K = map(int, input().split())
list = list(map(int, input().split()))
rlist=[]
i=0
l=len(list)
while(i<K):
  j=0
  while(j<l):
    k=0
    max=1
    while(k<l):
      if(k < j):
        if(j<=k+list[k]):
          max+=1
      elif(j < k):
        if(k-list[k]<=j):
          max+=1
      k+=1
    rlist.append(max)
    j+=1
  list=rlist
  rlist=[]
  i+=1
print(list)
# Judge status: Accepted
#!/usr/bin/env python3
# -*- coding: utf-8 -*-


def main():
    N = int(input())
    A = list(map(int, input().split()))
    for a in A:

        if a % 2 == 0:
            if a % 3 == 0 or a % 5 == 0:
                continue
            else:
                print('DENIED')
                exit(0)

    print('APPROVED')


if __name__ == "__main__":
    main()
# Judge status: Accepted
from collections import Counter
n = int(input())
a = map(int, input().split())
counter = Counter(a)
ans = 0
for i, j in counter.items():
    if j - i < 0:
        ans += j
    else:
        ans += min(j - i, j)
print(ans)
# Judge status: Accepted
N,A,B=map(int,input().split())
ans=0
if A>B or (N==1 and A!=B):
    ans=0
elif N==1 and A==B:
    ans=1
else:
    ans=(N-2)*(B-A)+1
print(ans)
# Judge status: Wrong Answer
k, n = (int(i) for i in input().split())
a = list(map(int, input().split()))

i=0
while i < n-1:
  if (a[i+1]-a[i]) >= k/2:
    print(str(k-a[i+1]+a[i]))
    break
  i += 1
else:
  print(str(a[n-1]-a[0]))
# Judge status: Wrong Answer
N, A, B = map(int, input().split())

if abs(A-B) % 2 == 0:
    print(abs(A-B)//2)
else:
    top = (B-(A+1))//2 + A
    low = (N-A - (N-B+1))//2+N-B
    print(top)
# Judge status: Accepted
def main():
    n,m=map(int,input().split())
    a=list(map(lambda x:int(x)*-1,input().split()))
    
    import heapq
    heapq.heapify(a)
    
    for i in range(m):
        x=heapq.heappop(a)
        heapq.heappush(a,(x+1)//2)
    
    print(sum(a)*-1)

if __name__=="__main__":
    main()
# Judge status: Accepted
n = int(input())
a = n%1000
if a == 0:
    print(0)
else:
    print(1000-a)
# Judge status: Wrong Answer
n=int(input())
li=list(map(int,input().split()))
ans=0
li.sort()
for i in range(0,n-2):
  for j in range(i+1,n-1):
    for k in range(j+1,n):
      if(li[i]+li[j]>li[k]):
        ans+=1
print(ans)
# Judge status: Wrong Answer
def resolve():
	n = int(input())
	s = input()
	sum_e = [0]*(n+1)
	sum_w = [0]*(n+1)
	for i in range(n):
		ev = 1 if s[i] == 'E' else 0
		wv = 1 if s[i] == 'W' else 0
		sum_e[i+1] = sum_e[i] + ev
		sum_w[i+1] = sum_w[i] + wv
	ans = float('inf')
	if n == 2:
		print(1 if len(Counter(list(s)).keys()) == 2 else 0)
		return
	for i in range(1, n):
		v = sum_w[i-1] + (sum_e[-1] - sum_e[i+1])
		ans = min(ans, v)
	print(ans)
resolve()
# Judge status: Accepted
from math import ceil
def mlt(): return map(int, input().split())


x, y, z = mlt()

print(ceil(x/y)*z)
# Judge status: Accepted
a,b=map(int,input().split())


if (a*b)%2==1:
    print("Odd")
else:
    print("Even")
# Judge status: Accepted
import sys
input = sys.stdin.readline
sys.setrecursionlimit(10 ** 7)

a, b = map(int, input().split())
_min, _max = min(a, b), max(a, b)
prime_factors = []
i = 2
while i ** 2 <= _min:
    ext = 0
    while _min % i == 0:
        ext += 1
        _min //= i
    if ext:
        prime_factors.append((i, ext))
    i += 1
if _min != 1:
    prime_factors.append((_min, 1))

ans = 1
for pf, _ in prime_factors:
    if _max % pf == 0:
        ans += 1
print(ans)
# Judge status: Accepted
# cook your dish here

x,k,d=map(int,input().split())
x=abs(x)
f = x//d;

ans = 0

if(k<=f):
    ans = abs(x) - abs(k*d)
    
else:
    e =  (k - f)%2
    if(e==0):
        ans = x - f*d;
    else:
        ans = x - (f+1)*d;
            
    
print(abs(ans))
# Judge status: Wrong Answer
a = int(input())
b = int(input())
c = int(input())
d = int(input())
e = int(input())
k = int(input())
d = [a,b,c,d,e]
for i in range(4):
    if d[i+1]-d[i] > k:
        print(":(")
        exit()
print("Yey!")
# Judge status: Accepted
x = int(input())

if x%11 == 0 :
    print((x//11)*2)
elif x%11 <= 6 :
    print((x//11)*2+1)
else :
    print((x//11)*2+2)
# Judge status: Wrong Answer
import sys
read = sys.stdin.read
readline = sys.stdin.readline
readlines = sys.stdin.readlines

def main():
    N,M = map(int, readline().split())

    if N % 2 == 1:
        for i in range(M):
            print(i + 1, N - i)
    else:
        for i in range(M):
            if i < M // 2:
                print(i + 1, N - i)
            else:
                print(i + 2, N - i - 1)


if __name__ == "__main__":
    main()
# Judge status: Wrong Answer
import math
a, b = map(int, input().split())
gcd = 1
prime = []
roota = math.floor(a**(1/2))
for i in range(1, roota + 1):
    if a % i == 0 and b % i == 0:
        prime.append(i)
for i in prime:
    gcd *= i
if b % a == 0:
    gcd = a
print(int(a * b / gcd))
# Judge status: Accepted
N = int(input())
c = 0

for A in range(1, N + 1):
    for B in range(1, N + 1):
        if A * B >= N:
            break
        else:
            c += 1
print(c)
# Judge status: Accepted
k=int(input())
count=1
num=7
for _ in range(k):
    if num%k == 0:
        print(count)
        break
    else:
        count += 1
        num = (num % k)*10 + 7
else:
    print(-1)
# Judge status: Wrong Answer
K = int(input())
A, B = map(int, input().split())
 
ans = 'NO'
for i in range(A, B+1):
  print(i)
  if i % K == 0:
    ans = 'OK'
    break
    
print(ans)