Harryxun/sft_time huggingface dataset:
### BUGGY CODE ###

import sys, math
def input():
    return sys.stdin.readline()[:-1]
from itertools import permutations, combinations
from collections import defaultdict, Counter
from math import factorial
from fractions import gcd
div = 10**9 + 7

sys.setrecursionlimit(10**7)
N = int(input())
A = list(map(int, input().split()))
sA = list(set(A))

val = 1
def lcm(a, b):
    ret = gcd(a, b)
    ret = a*b//ret
    return ret

val = sA[0]
for a in sA[1:]:
    val = lcm(val, a)

B = [val//a for a in A]
sumB = sum(B)
sumB %= div

print(sumB)



### FIXED CODE ###

import sys
def input():
    return sys.stdin.readline()[:-1]
from fractions import gcd
div = 10**9 + 7

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

    val = 1
    def lcm(a, b):
        ret = gcd(a, b)
        ret = a*b//ret
        return ret

    val = sA[0]
    for a in sA[1:]:
        val = lcm(val, a)

    B = [val//a for a in A]
    sumB = sum(B)
    sumB %= div

    print(sumB)

if __name__ == '__main__':
    main()
### BUGGY CODE ###

s = tuple(input())
t = tuple(input())
n = len(s)
m = len(t)

dp = [['']*m for i in range(n)]
if s[0] == t[0]:
    dp[0][0] = s[0]

for i in range(1,m):
    if s[0] == t[i]:
        dp[0][i] = s[0]
    else:
        dp[0][i] = dp[0][i-1]
for i in range(1,n):
    if t[0] == s[i]:
        dp[i][0] = t[0]
    else:
        dp[i][0] = dp[i-1][0]

for i in range(1,n):
    for j in range(1,m):
        if s[i] == t[j]:
            dp[i][j] = dp[i-1][j-1] + s[i]
        else:
            if len(dp[i-1][j]) > len(dp[i][j-1]):
                dp[i][j] = dp[i-1][j]
            else:
                dp[i][j] = dp[i][j-1]
print(dp[-1][-1])

### FIXED CODE ###

s = tuple(input())
t = tuple(input())
n = len(s)
m = len(t)

dp = [[0]*(m+1) for i in range(n+1)]

for i in range(1,n+1):
    for j in range(1,m+1):
        if s[i-1] == t[j-1]:
            dp[i][j] = dp[i-1][j-1]  + 1
        else:
            dp[i][j] = max(dp[i-1][j],dp[i][j-1])

res = ''
while n != 0 and m != 0:
    if dp[n][m] == dp[n-1][m]:
        n -= 1
    elif dp[n][m] == dp[n][m-1]:
        m -= 1
    else:
        n -= 1
        m -= 1
        res = s[n] + res
print(res)
### BUGGY CODE ###

import sys
input = sys.stdin.readline
n=int(input())
ans=[]
for i in range(n):
    a=int(input())
    if ans.count(a)==0:
        ans.append(a)
    else:
        ans.remove(a)
print(len(ans))

### FIXED CODE ###

import collections
n=int(input())
count=0
a=[int(input()) for _ in range(n)]
a=collections.Counter(a)

for key,value in a.items():
    if value%2==1:
        count+=1
print(count)
### BUGGY CODE ###


def myAnswer(N:int,dic:dict) -> None:
   MAX = max(dic.values())
   dic2 = sorted(dic.items())
   for key,value in dic2:
      if(MAX == value):
         print(key)

def main():
   N = int(input())
   dic = {}
   for _ in range(N):
      s = input()
      if(s in dic.keys()):
         dic[s]+=1
      else:
         dic[s]=1
   myAnswer(N,dic)
if __name__ == '__main__':
   main()

### FIXED CODE ###


N = int(input())
C = dict()


for i in range(N):
    a = input()
    if(a not in C.keys()):
        C[a] = 1
    else:
        val = C[a]
        C[a] = val + 1

m=0
for i in C.values():
    if(i > m):
        m=i

ans = sorted(C.items())
for i  in ans:
    if(m==i[1]):
        print(i[0])
### BUGGY CODE ###

from collections import Counter

S = input()
S = list(map(int, S))

S = S[::-1]
pow10 = 10
for i in range(1, len(S)):
    S[i] = S[i - 1] + S[i] * pow10
    pow10 *= 10

S = [0] + [n % 2019 for n in S]

counter = Counter(S)
ans = 0
for count in counter.values():
    if count >= 2:
        ans += count * (count - 1) // 2

print(ans)


### FIXED CODE ###

S = input()
S = list(map(int, S))

t = 1
r = 0
d = [0] * 2019
d[0] += 1
for n in reversed(S):
    r = (r + n * t) % 2019
    t = t * 10 % 2019
    d[r] += 1

ans = 0
for m in d:
    ans += m * (m-1) // 2

print(ans)
### BUGGY CODE ###

from operator import itemgetter
s=list(input())
t=list(input())
n=len(s)
l=[s,t]
l=[list(x) for x in zip(*l)]
l.sort(key=itemgetter(1,0))
l=[list(x) for x in zip(*l)]
s=''.join(l[0])
t=''.join(l[1])
a=''
for i in range(n):
    if(s[i]==a):continue
    a=s[i]
    b=t[i]
    s=s.translate(str.maketrans({a:b,b:a}))
    
    
if(s==t):print("Yes")
else:print("No")


### FIXED CODE ###

s=input()
t=input()
n=len(s)



sl=list(s)

sl.sort()
sl=''.join(sl)

a=''
for i in range(n):
    if(sl[i]==a):continue
    a=sl[i]
    b=t[s.index(a)]
    s=s.translate(str.maketrans({a:b,b:a}))
    sl=sl.translate(str.maketrans({a:b,b:a}))
    

if(s==t):print("Yes")
else:print("No")
### BUGGY CODE ###

s=list(input())
q=int(input())
n=0
for i in range(q):
    li=input().split()
    if int(li[0])==1:
        s.reverse()
    elif int(li[0])==2:
        if (n%2==0 and int(li[1])==1) or (n%2==1 and int(li[1])==2):
            s.insert(0,li[2])
        else:
            s.append(li[2])
if n%2==0:
    print(''.join(s))
else:
    s.reverse()
    print(''.join(s))


### FIXED CODE ###

from collections import deque
s=input()
q=int(input())
n=0
que=deque(s)
for i in range(q):
    l=input()
    if l[0]=='1':
        n+=1
    else:
        if (l[2]=='1' and n%2==0) or (l[2]=='2' and n%2==1):
            que.appendleft(l[4])
        else:
            que.append(l[4])

ans=''.join(que)
if n%2==0:
    print(ans)
else:
    print(ans[::-1])
### BUGGY CODE ###

n = int(input())
count = 0
for a in range(1,n):
    for b in range(1,n):
        if a*b<n:
            count+=1
        else:
            break
print(count)

### FIXED CODE ###

n = int(input())
count = 0
for a in range(1,n):
    if n%a==0:
        b = n//a - 1
    else:
        b = n//a
    count+=b
print(count)
### BUGGY CODE ###

import bisect,collections,copy,heapq,itertools,math,numpy,string
import sys
sys.setrecursionlimit(10**7)

def S(): return sys.stdin.readline().rstrip()
def I(): return int(sys.stdin.readline().rstrip())
def LI(): return list(map(int,sys.stdin.readline().rstrip().split()))
def LS(): return list(sys.stdin.readline().rstrip().split())

def comb(n):
    return int(n*(n-1)/2)

def main():
    N = I()
    A_list = LI()
    A_ctr = collections.Counter(A_list)
    for i in range(1,N+1):
        ans = 0
        for k,v in A_ctr.items():
            if A_list[i-1]==k:
                ans += comb(v-1)
            else:
                ans += comb(v)
        else:
            print(ans)

main()


### FIXED CODE ###

import bisect,collections,copy,heapq,itertools,math,numpy,string
import sys
sys.setrecursionlimit(10**7)

def S(): return sys.stdin.readline().rstrip()
def I(): return int(sys.stdin.readline().rstrip())
def LI(): return list(map(int,sys.stdin.readline().rstrip().split()))
def LS(): return list(sys.stdin.readline().rstrip().split())

def comb(n):
    return int(n*(n-1)/2)

def main():
    N = I()
    A_list = LI()
    A_ctr = collections.Counter(A_list)
    base = 0
    for i in range(1,N+1):
        base += comb(A_ctr[i])
    for i in range(1,N+1):
        i_val = A_ctr[A_list[i-1]]
        before = comb(i_val)
        after = comb(i_val-1)
        print(int(base - before + after))
main()
### BUGGY CODE ###

N,K=map(int,input().split())
light=list(map(int,input().split()))
for k in range(K):
  imo=[0]*(N+1)
  for i in range(N):
    if i-light[i]>0:
      l=i-light[i]
    else:
      l=0
    if i+light[i]<N-1:
      r=i+light[i]+1
    else:
      r=N
    imo[l]+=1
    imo[r]-=1
  for i in range(1,N):
    imo[i]+=imo[i-1]
  if light==imo:
    break
  else:
    light=imo[:]
print(*light[:-1])

### FIXED CODE ###

N,K=map(int,input().split())
light=list(map(int,input().split()))
for k in range(K):
  imo=[0]*(N+1)
  for i in range(N):
    l=max(0,i-light[i])
    r=min(N-1,i+light[i])+1
    imo[l]+=1
    imo[r]-=1
  for i in range(1,N):
    imo[i]+=imo[i-1]
  if light==imo:
    break
  else:
    light=imo[:]
print(*light[:-1])
### BUGGY CODE ###

import bisect

n = int(input())
s = input()
a_loc = []
b_loc = []
c_acc = [0]
c_cnt = 0
for i, c in enumerate(s):
    if c == 'D':
        a_loc.append(i)
    elif c == 'M':
        b_loc.append(i)
    elif c == 'C':
        c_cnt += 1
    c_acc.append(c_cnt)

# print(a_loc)
# print(c_acc)

q = int(input())
for k in map(int, input().split()):
    ans = 0
    for b in b_loc:
        i = bisect.bisect_left(a_loc, max(0, b - k + 2))
        # print(b, i, a_loc[i])
        cn = c_acc[b]
        for a in a_loc[i:]:
            if a >= b:
                break
            ans += c_acc[min(a + k, n)] - cn
    print(ans)


### FIXED CODE ###

from itertools import accumulate

n = int(input())
s = input()
acc_cnt_a = [0] * (n + 1)
acc_cnt_b = [0] * (n + 1)
acc_cnt_ab = [0] * (n + 1)
c_loc = []
cnt_a = 0
for i, c in enumerate(s):
    if c == 'D':
        acc_cnt_a[i] += 1
        cnt_a += 1
    elif c == 'M':
        acc_cnt_b[i] += 1
        acc_cnt_ab[i] += cnt_a
    elif c == 'C':
        c_loc.append(i + 1)
acc_cnt_a = [0] + list(accumulate(acc_cnt_a))
acc_cnt_b = [0] + list(accumulate(acc_cnt_b))
acc_cnt_ab = [0] + list(accumulate(acc_cnt_ab))

q = int(input())
buf = []
for k in map(int, input().split()):
    ans = 0
    for r in c_loc:
        l = r - k
        if l > 0:
            rejected_a = acc_cnt_a[l]
            cnt_internal_b = acc_cnt_b[r] - acc_cnt_b[l]
            cnt_internal_ab = acc_cnt_ab[r] - acc_cnt_ab[l]
            ans += cnt_internal_ab - rejected_a * cnt_internal_b
        else:
            ans += acc_cnt_ab[r]
    buf.append(ans)
print('\n'.join(map(str, buf)))
### BUGGY CODE ###

from collections import deque
S = input()
Q = int(input())
query = [list(input().split()) for _ in range(Q)]
d = deque(S)
for x in query:
    if int(x[0]) == 1:
        d.reverse()
    elif int(x[0]) == 2:
        if int(x[1]) == 1:
            d.appendleft(x[2])
        elif int(x[1]) == 2:
            d.append(x[2])
print(*d, sep='')

### FIXED CODE ###

from collections import deque
S = input()
Q = int(input())
query = [list(input().split()) for _ in range(Q)]
reversecount = 0
d = deque(S)
for x in query:
    if int(x[0]) == 1:
        reversecount += 1
    else:
        if (int(x[1]) == 1 and (reversecount % 2 == 0)) or (int(x[1]) == 2 and (reversecount % 2 == 1)):
            d.appendleft(x[2])
        else:
            d.append(x[2])
if reversecount % 2 == 1:
    d.reverse()
print(*d, sep='')
### BUGGY CODE ###

N, M = map(int, input().split())
Counted = []
num1 = 0
num2 = 0
subnum2 = [0 for l in range(N)]
for j in range(M):
  p, S = input().split()
  p_ = int(p)
  if S == "AC" and not p_ in Counted:
    num1 += 1
    num2 += subnum2[p_ - 1]
    Counted.append(p_)
  elif S == "WA" and not p_ in Counted:
    subnum2[p_ - 1] += 1
print("{} {}".format(num1, num2))

### FIXED CODE ###

N, M = map(int, input().split())
Counted = [0 for _ in range(N)]
num1 = 0
num2 = 0
subnum2 = [0 for l in range(N)]
for j in range(M):
  p, S = input().split()
  p_ = int(p)
  if S == "AC" and Counted[p_ -1] == 0:
    num1 += 1
    num2 += subnum2[p_ - 1]
    Counted[p_ -1] = 1
  elif S == "WA" and Counted[p_-1] == 0:
    subnum2[p_ - 1] += 1
print("{} {}".format(num1, num2))
### BUGGY CODE ###

import heapq
import copy
n= int(input())
a = input()
list1 = list(map(int,a.split()))
list1_1 = copy.deepcopy(list1)
heapq.heapify(list1)
list2 = []
for i in range(n):
    list2.append(list1_1.index(heapq.heappop(list1))+1)

print(" ".join(map(str,list2)))

### FIXED CODE ###


n= int(input())
a = input()
list1 = list(map(int,a.split()))
list2 = [0]*n
for i in range(n):
    list2[list1[i]-1] = i+1

print(" ".join(map(str,list2)))
### BUGGY CODE ###

import numpy as np

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

magic = []
for i in range(N):
    magic.append(tuple(map(int, input().split())))

INF = 10**15 
dp = np.full((H+1), INF, dtype=np.int64)
dp[0] = 0

for i, (a, b) in enumerate(magic):
    for h in range(H):
        dp[min(H, h+a)] = min(dp[min(H, h+a)], dp[h]+b)

print(dp[-1])

### FIXED CODE ###

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

magic = [list(map(int, input().split())) for _ in range(N)]

dp = [0 for _ in range(10**5)]

for i in range(H):
    dp[i] = min(dp[i-a]+b for a, b in magic)

print(dp[H-1])
### BUGGY CODE ###

r = []
N = int(input())
for i in range(0, N):
    r.append(int(input()))

min_i = N-2
max_i = N-1

for i in range(N-1)[::-1]:
    if r[i] < r[i+1]:
        for j in range(i+1, N):
            if r[j] - r[i] > r[max_i] - r[min_i]:
                max_i = j
                min_i = i
    if r[max_i] - r[min_i] < 0:
        if r[i+1] - r[i] > r[max_i] - r[min_i]:
            max_i = i+1
            min_i = i

                
print(r[max_i] - r[min_i])

### FIXED CODE ###

N = int(input())
r = [int(input()) for i in range(N)]
 
min = r[0]
max = -9999999999999999
 
for i in range(1, N):
    if r[i] - min > max:
        max = r[i] - min
    if r[i] < min:
        min = r[i]
 
print(max)
### BUGGY CODE ###

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

ans = 1

for i in a:
    ans *= i

if ans > 10**18:
    print(-1)
else:
    print(ans)

### FIXED CODE ###

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

ans = 1

for i in a:
    if i == 0:
        ans = 0

if ans != 0:
    for i in a:
        ans *= i
        if ans > 10**18:
            ans = -1
            break

print(ans)
### BUGGY CODE ###

s = input()
q = int(input())

for i in range(q):
    t = input()
    if len(t) == 1:
        s = s[::-1]
    else:
        if t[2] == "1":
            s = t[4] + s
        else:
            s = s + t[4]

print(s)



### FIXED CODE ###

from collections import deque
s = deque(input())
q = int(input())
rev = 0

for i in range(q):
    t = input()
    if rev == 0:
        if len(t) == 1:
            rev = 1
        else:
            if t[2] == "1":
                s.appendleft(t[4])
            else:
                s.append(t[4])
    else:
        if len(t) == 1:
            rev = 0
        else:
            if t[2] == "1":
                s.append(t[4])
            else:
                s.appendleft(t[4])

if rev == 1:
    s.reverse()
print(*s, sep="")
### BUGGY CODE ###

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

cnt = 0
while c > 0 or b > 0:
    if c > 0:
        c -= 1
        cnt += 1
    elif b > 0:
        b -= 1
        cnt += 1
        continue

    if b > 0:
        b -= 1
        cnt += 1
        continue
    elif a > 0:
        a -= 1
        continue
    else:
        break

print(cnt)

### FIXED CODE ###

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

cnt = 0
if a + b + 1>= c:
    ans = b + c
else:
    ans = b + a + b + 1

print(ans)
### BUGGY CODE ###

from collections import Counter
N, K = list(map(int, input().split()))
C = Counter()
S = set()
for _ in range(N):
    a, b = list(map(int, input().split()))
    C += {a: b}
    S.add(a)
# print(C)
L = list(S)
L.sort()
i = 0
ct = C[L[0]]
while ct < K:
    i += 1
    ct += C[L[i]]
print(L[i])


### FIXED CODE ###

N, K = list(map(int, input().split()))
C = [0]*(10**5+1)
S=set()
for _ in range(N):
    a, b = list(map(int, input().split()))
    C[a] += b
    S.add(a)

L = list(S)
L.sort()
i = 0
ct = C[L[0]]
while ct < K:
    i += 1
    ct += C[L[i]]
print(L[i])
### BUGGY CODE ###

import numpy as np
N = int(input())
dp = np.zeros((N+1, 3), dtype=int)
for i in range(1, N+1):
    lst = np.array(list(map(int, input().split(' '))))
    dp[i][0] = max(dp[i-1][[1,2]] + lst[[1,2]])
    dp[i][1] = max(dp[i-1][[0,2]] + lst[[0,2]])
    dp[i][2] = max(dp[i-1][[0,1]] + lst[[0,1]])

print(max(dp[-1]))

### FIXED CODE ###

import numpy as np
N = int(input())
dp = np.zeros((N+1, 3), dtype=int)
for i in range(1, N+1):
    a, b, c = list(map(int, input().split(' ')))
    dp[i][0] = max(dp[i-1][1], dp[i-1][2]) + a
    dp[i][1] = max(dp[i-1][0], dp[i-1][2]) + b
    dp[i][2] = max(dp[i-1][0], dp[i-1][1]) + c
print(np.max(dp[-1]))
### BUGGY CODE ###

#ABC134 C

N = int(input())
A = []
for i in range(N):
    a = int(input())
    A.append(a)

for i in range(N):
    if A[i] != max(A):
        print(max(A))
    else:
        p = A[i]
        A[i] = 0
        print(max(A))
        A[i] = p

### FIXED CODE ###

#ABC134 C (再考察)

N = int(input())
A = []
for i in range(N):
    a = int(input())
    A.append(a)
    
AA = sorted(A,reverse = True)
for i in range(N):
    if A[i] != AA[0]:
        print(AA[0])
    else:
        print(AA[1])
### BUGGY CODE ###

import sys
sys.setrecursionlimit(10000000)
def input():
    return sys.stdin.readline()[:-1]

f_inf = float("inf") # sys.maxsize

N, M, P = map(int, input().split())
ABC_d = {}
for m in range(M):
    A, B, C = map(int, input().split())
    if A in ABC_d:
        ABC_d[A].append((B, C - P))
    else:
        ABC_d[A] = [(B, C - P)]

cost = [-f_inf] * N
cost[0] = 0

max_num_sum = (N * (N + 1)) // 2
max_even = N // 2
max_odd = N - max_even

def solve(pos, cnt, num_sum):
    global cost

    if not(pos in ABC_d): return
    if cnt > N or num_sum > max_num_sum:
        cost[pos-1] = f_inf;

    for B, C in ABC_d[pos]:
        if cost[B - 1] == f_inf or cost[B - 1] >= cost[pos - 1] + C:
            pass
        elif cost[B - 1] < cost[pos - 1] + C:
            cost[B - 1] = cost[pos - 1] + C
            solve(B, cnt + 1, num_sum + B)

# def solve(pos, odd_cnt, even_cnt, num_sum):
#     global cost

#     if not(pos in ABC_d): return

#     if odd_cnt > max_odd or even_cnt > max_even or num_sum > max_num_sum:
#         cost[pos-1] = f_inf;

#     for B, C in ABC_d[pos]:
#         if cost[B - 1] == f_inf or cost[B - 1] >= cost[pos - 1] + C:
#             pass
#         elif cost[B - 1] < cost[pos - 1] + C:
#             odd_cnt2 = odd_cnt
#             even_cnt2 = even_cnt
#             if B%2: odd_cnt2 += 1
#             else: even_cnt2 += 1
#             cost[B - 1] = cost[pos - 1] + C
#             solve(B, odd_cnt2, even_cnt2, num_sum + B)


solve(1, 1, 1)
# solve(1, 1, 0, 1)

if (cost[-1] == f_inf):
    print (-1)
else:
    print (max(0, int(cost[-1])))


### FIXED CODE ###

import sys
sys.setrecursionlimit(10000000)

f_inf = sys.maxsize

N, M, P = map(int, input().split())
ABC_d = {}
for m in range(M):
    A, B, C = map(int, input().split())
    if A in ABC_d:
        ABC_d[A].append([B, C - P])
    else:
        ABC_d[A] = [[B, C - P]]

cost = [-f_inf] * N
cost[0] = 0

def solve(pos, cnt):
    global cost

    if not(pos in ABC_d): return
    if cnt > N: cost[pos-1] = f_inf;

    for B, C in ABC_d[pos]:
        if cost[B - 1] == f_inf or cost[B - 1] >= cost[pos - 1] + C:
            pass
        elif cost[pos-1] == f_inf:
            cost[B-1] = f_inf
            solve(B, cnt + 1)
        elif cost[B - 1] < cost[pos - 1] + C:
            cost[B - 1] = cost[pos - 1] + C
            solve(B, cnt + 1)

solve(1, 1)

if (cost[-1] == sys.maxsize):
    print (-1)
else:
    print (max(0, int(cost[-1])))
### BUGGY CODE ###

import sys
input = sys.stdin.readline
h,w=map(int,input().split())
a=[]
for i in range(h):
    a.append(list(map(int,input().split())))
b=[]
for i in range(h):
    b.append(list(map(int,input().split())))
dp=[[set([]) for i in range(w)] for j in range(h)]
dp[0][0].add(a[0][0]-b[0][0])
dp[0][0].add(b[0][0]-a[0][0])
for i in range(h):
    for j in range(w):
        if i==j==0:
            continue
        if i==0:
            for k in dp[i][j-1]:
                dp[i][j].add(abs(k+a[i][j]-b[i][j]))
                dp[i][j].add(abs(k+b[i][j]-a[i][j]))
        elif j==0:
            for k in dp[i-1][j]:
                dp[i][j].add(abs(k+a[i][j]-b[i][j]))
                dp[i][j].add(abs(k+b[i][j]-a[i][j]))
        else:
            for k in (dp[i][j-1]|dp[i-1][j]):
                if k<=7000:
                    dp[i][j].add(abs(k+a[i][j]-b[i][j]))
                    dp[i][j].add(abs(k+b[i][j]-a[i][j]))             
#dp[h-1][w-1]
ans=10**10
for i in dp[h-1][w-1]:
    ans=min(ans,abs(i))
print(ans)


### FIXED CODE ###

import sys
input = sys.stdin.readline
H,W=map(int,input().split())
a = [[] for _ in range(H)]
for i in range(H):
    a[i] = list(map(int, input().split()))
b = [[] for _ in range(H)]
for i in range(H):
    b[i] = list(map(int, input().split()))

for i in range(H):
    for j in range(W):
        a[i][j] =abs(a[i][j]-b[i][j])

dp = [[set() for _ in range(W)] for _ in range(H)]
dp[0][0].add(a[0][0])
for i in range(1,H):
    t = a[i][0]
    tmp = set()
    for k in dp[i-1][0]:
        tmp.add(k+t)
        tmp.add(abs(k-t))
    dp[i][0] = tmp
for j in range(1,W):
    t = a[0][j]
    tmp = set()
    for k in dp[0][j-1]:
        tmp.add(k+t)
        tmp.add(abs(k-t))
    dp[0][j] = tmp
for i in range(1,H):
    for j in range(1,W):
        t = a[i][j]
        tmp = set()
        for k in (dp[i-1][j] | dp[i][j-1]):
            tmp.add(k+t)
            tmp.add(abs(k-t))
        dp[i][j] = tmp
        dp[i-1][j-1] = set()

ls = list(dp[H-1][W-1])
print(min(ls))
### BUGGY CODE ###

import math
t = 1
for tc in range(t):
    n = int(input())
    ans = 0
    i = 1
    while i < n:
        j = 1
        while i*j < n :
            c = n - i*j
            if c > 0:
                ans += 1
            j += 1
        i += 1
    print(ans)
        

    
    


### FIXED CODE ###

import math
t = 1
for tc in range(t):
    n = int(input())
    ans = 0
    for i in range(1,n+1):
        j = 1
        ans += (n-1) // i
        # while i*j + 1 <= n:
        #     ans += 1
        #     j += 1
    print(ans)
### BUGGY CODE ###

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

    sort_A = sorted(A, reverse=True)

    for _ in range(M):
        sort_A[0] = sort_A[0] // 2
        sort_A.sort(reverse=True)

    print(sum(sort_A))

main()

### FIXED CODE ###

import heapq
def func(n):
    return -n

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

    heapq.heapify(A)

    for _ in range(M):
        tmp = -heapq.heappop(A) // 2
        heapq.heappush(A,-tmp)

    print(-sum(A))

main()
### BUGGY CODE ###

# -*- coding: utf-8 -*-

from operator import itemgetter

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

# A日後、報酬B
a = []
b = []
for i in range(n):
    ai, bi = map(int, input().split())
    a.append(ai)
    b.append(bi)

sum = 0
used = [False] * n
for i in range(1, m+1):
    # A <= iでBが最大となるjを探す(使用済み除く)
    max_b = 0
    use_j = None
    for j in range(n):
        # print('i:{}, j:{}'.format(i, j))
        if a[j] <= i:
            if not used[j]:
                if b[j] > max_b:
                    max_b = b[j]
                    use_j = j
    if not use_j == None:
        used[use_j] = True
        sum += max_b

print(sum)


### FIXED CODE ###

# -*- coding: utf-8 -*-

from heapq import heappush, heappop

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

# A日後、報酬B
workList = {}
for i in range(n):
    a, b = map(int, input().split())
    if a not in workList:
        workList[a] = [-b]
    else:
        workList[a].append(-b)
# print(workList)

hq = []
sum = 0
for i in range(1, m + 1):
    if i in workList:
        for w in workList[i]:
            heappush(hq, w)

    val = None
    if len(hq) > 0:
        val = heappop(hq)
    if val is not None:
        sum += -val

print(sum)