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

n = int(input())
a = [(A, i) for i, A in enumerate(map(int, input().split()))]
a.sort(reverse=True)

dp = [[-1]*(n+1) for _ in range(n+1)]
dp[0][0] = 0

for num, (A, pos) in enumerate(a):
    for i in range(num+1):
        j = num - i
        dp[i+1][j] = max(dp[i+1][j], dp[i][j] + A*abs(pos-i))  # 左からi番目の時
        dp[i][j+1] = max(dp[i][j+1], dp[i][j] + A*abs((n-1-j)-pos))  # 右からj番目の時


ans = 0
for i in range(n+1):
    j = n-i
    ans = max(ans, dp[i][j])

print(ans)

### FIXED CODE ###

def main():
  N = int(input())
  INF = float('inf')
  A = [(i+1, a) for i, a in enumerate(map(int, input().split()))]
  A = sorted(A, key=lambda x: x[1], reverse = True)

  dp = [[-INF] * (N+1) for _ in range(N+1)]
  dp[0][0] = 0

  for s in range(1, N+1):
    for l in range(s+1):
      r = s - l
      dp[l][r] = max(dp[l-1][r] + A[s-1][1] * abs(A[s-1][0]-l), dp[l][r-1] + A[s-1][1] * abs(N-r+1-A[s-1][0]))
    
  ans = 0
  for m in range(N):
    if(dp[m][N-m] > ans):
      ans = dp[m][N-m]
    
  print(ans)

main()
### BUGGY CODE ###

a,b,c,k =map(int,input().split())
for i in range(k):
	d = c
	c = b+a
	b = a+d
	a = b+c-2*a
r =a-b
if abs(a-b)>10^18:
	print('Unfair')
else:
	print(a-b)


### FIXED CODE ###

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

if k%2==1:
    print(b-a)
else:
    print(a-b)
### BUGGY CODE ###

import heapq
n,m = map(int,input().split())
a = list(map(int,input().split()))
bc = []
for _ in range(m):
    b,c = map(int,input().split())
    bc.append((b,c))
heapq.heapify(a)
now = heapq.heappop(a)
for i, s in enumerate(bc):
    b, c = s
    for j in range(b):
        if now > c:
            break
        heapq.heappush(a,c)
        now = heapq.heappop(a)
heapq.heappush(a,now)
print(sum(a))


### FIXED CODE ###

import collections
import heapq

n,m = map(int,input().split())
a = list(map(int,input().split()))
bc = []
for _ in range(m):
    b,c = map(int,input().split())
    bc.append((b,c))
cnt = collections.Counter(a).most_common()
heapq.heapify(cnt)


for i, set_bc in enumerate(bc):
    now0,now1 = heapq.heappop(cnt)
    b,c = set_bc
    if now0 >= c:
        heapq.heappush(cnt,(now0,now1))
        now1 = 0
        continue
    tmpb = 0
    for j in range(b):
        if now0 < c:
            if now1 >= b:
                now1 -= b
                tmpb += b
                heapq.heappush(cnt,(c,tmpb))
                break
            tmpb += now1
            b -= now1
            now0,now1 = heapq.heappop(cnt)
        else:
            heapq.heappush(cnt,(c,tmpb))
            break
    if now1 != 0:
        heapq.heappush(cnt,(now0,now1))
        now1 = 0
if now1 != 0:
    heapq.heappush(cnt,(now0,now1))
ans = 0

for i in range(len(cnt)):
    val, num = heapq.heappop(cnt)
    ans += val * num
print(ans)
### BUGGY CODE ###

# -*- coding: utf-8 -*-
INF = 10**10
n,m = map(int, input().split())
d = [[INF for _ in range(n)] for _ in range(n)]
el = []

for _ in range(m):
    a,b,c = map(int,input().split())
    d[a-1][b-1] = c
    d[b-1][a-1] = c
    el.append([a-1,b-1,c])

for k in range(n):
    for i in range(n):
        for j in range(n):
            if i==j:
                d[i][j] = 0

            d[i][j] = min(d[i][j], d[i][k]+d[k][j])

ret = 0
for ei in range(m):
    a = el[ei][0]
    b = el[ei][1]
    c = el[ei][2]
    flag = False
    for s in range(n):
        for t in range(n):
            if d[s][a]+c+d[b][t]==d[s][t]:
                flag = True
                break
        if flag:
            break
    if not flag:
        ret += 1
print(ret)


### FIXED CODE ###

# -*- coding: utf-8 -*-
INF = 10**10
n,m = map(int, input().split())
d = [[INF for _ in range(n)] for _ in range(n)]
el = []

for _ in range(m):
    a,b,c = map(int,input().split())
    d[a-1][b-1] = c
    d[b-1][a-1] = c
    el.append([a-1,b-1,c])

for k in range(n):
    for i in range(n):
        for j in range(n):
            if i==j:
                d[i][j] = 0

            d[i][j] = min(d[i][j], d[i][k]+d[k][j])

ret = 0
for ei in range(m):
    a = el[ei][0]
    b = el[ei][1]
    c = el[ei][2]
    flag = False
    for s in range(n):
        if d[s][a]+c==d[s][b]:
            flag = True
            break
    if not flag:
        ret += 1
print(ret)
### BUGGY CODE ###

S = input()

N = len(S)

answer = 0

for start in range(N-4):
    for end in range(start+4,N+1):
        if int(S[start:end]) % 2019 == 0:
            answer += 1

print(answer)

### FIXED CODE ###

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

pops = 0
digi = 1
cnt = [0] * 2019
cnt[0] = 1

while S:
    s = S.pop()

    pops = (pops + s * digi) % 2019
    digi = (10 * digi) % 2019

    cnt[pops] += 1

ans = 0

for i in range(2019):
    ans += cnt[i] * (cnt[i] - 1) // 2

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

n = int(input())
lol=[int(n) for n in input().split()]
ans = 0
x=max(lol)
ans += x
lol.remove(x)
n = n-2
if(n%2==0):
    for i in range(int(n/2)):
        ans+=(max(lol)*2)
        lol.remove(max(lol))
    print(ans)
else:
    for i in range(int((n-1)/2)):
        ans+=(max(lol)*2)
        lol.remove(max(lol))
    ans +=max(lol)
    print(ans)
    
    
    


### FIXED CODE ###

n = int(input())
x=n
lol=[int(n) for n in input().split()]

ans = 0
lol.sort()
lol.reverse()
z=lol.copy()
ans +=lol[0]
lol.remove(max(lol))
n=n-2

if(n%2==0):
    for i in range(int(n/2)):
        ans+=(2*lol[i])
    print(ans)
else:
    for i in range(int((n-1)/2)):
        ans+=(2*lol[i])
    ans+=(z[int(x/2)])
    print(ans)
### BUGGY CODE ###

N = int(input())


def query(i):
    print(i, flush=True)
    s = input()
    if s == 'Vacant':
        exit()
    return s


root = query(0)


def is_ok(ind):
    # 左ならTrue
    response = query(ind)
    if ind % 2 == 1:
        return root == response
    else:
        return root != response


def bin_search_meguru():
    """
    初期値のng,okを受け取り,is_okを満たす最小(最大)のokを返す
    まずis_okを定義すべし
    ng, okは,とり得る最小の値-1,とり得る最大の値+1
    """

    # 適当にいじる
    ng = -1  # ind=0が条件を満たすこともあるため
    ok = N  # ind=len(a)-1が条件を満たさないこともあるため

    # いじらない
    # okとngのどちらが大きいかわからないことを考慮
    while (abs(ok - ng) > 1):
        mid = (ok + ng) // 2
        if is_ok(mid):
            ok = mid
        else:
            ng = mid
    return False


bin_search_meguru()


### FIXED CODE ###

N = int(input())


def query(i):
    print(i)
    s = input()
    if s == 'Vacant':
        exit()
    return s


root = query(0)


def is_ok(ind):
    # 左ならTrue
    response = query(ind)
    if ind % 2 == 1:
        return root == response
    else:
        return root != response


def bin_search_meguru():
    """
    初期値のng,okを受け取り,is_okを満たす最小(最大)のokを返す
    まずis_okを定義すべし
    ng, okは,とり得る最小の値-1,とり得る最大の値+1
    """

    # 適当にいじる
    ng = -1  # ind=0が条件を満たすこともあるため
    ok = N  # ind=len(a)-1が条件を満たさないこともあるため

    # いじらない
    # okとngのどちらが大きいかわからないことを考慮
    while (abs(ok - ng) > 1):
        mid = (ok + ng) // 2
        if is_ok(mid):
            ok = mid
        else:
            ng = mid
    return False


bin_search_meguru()
### BUGGY CODE ###

n,k = [int(x) for x in input().split()]
h = [int(x) for x in input().split()]

dp = [float("inf")]*(n+k)
dp[0] = 0
for i in range(n):
    for j in range(i+1,i+k+1):
        dp[j] = min(dp[j],dp[i]+abs(h[i]-h[min(j,n-1)]))
print(dp[n-1])

### FIXED CODE ###

n,k = [int(x) for x in input().split()]
h = [int(x) for x in input().split()]
dp = [float("inf")]*n
dp[0] = 0
for i in range(1,n):
    for j in range(1,k+1):
        if i>=j:
            dp[i] = min(dp[i],dp[i-j]+abs(h[i]-h[i-j]))

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

n = int(input())
a = input().split()

flag = True
if n % 2 == 0:
    for i in range(int(n/2)):
        if a.count(str(i*2 + 1)) == 2:
            pass
        else:
            flag = False
    ans = 2**(n/2) % (10**9 + 7)

else:  # n % 2 == 1
    if a.count('0') == 1:
        pass
    else:
        flag = False
    for i in range(int((n-1)/2)):
        if a.count(str((i+1)*2)) == 2:
            pass
        else:
            flag = False
    ans = 2**((n-1)/2) % (10**9 + 7)

if flag:
    print(int(ans))
else:
    print(0)


### FIXED CODE ###


from collections import Counter

n = int(input())
a = list(map(int, input().split()))
m = n // 2
ca = Counter(a)

if n % 2 == 1 and ca[0] == 1 and all(ca[(i+1)*2] == 2 for i in range(m)):
    ans = (2 ** m) % (10 ** 9 + 7)
    print(ans)
elif n % 2 == 0 and all(ca[i*2 + 1] == 2 for i in range(m)):
    ans = (2 ** m) % (10 ** 9 + 7)
    print(ans)
else:
    print(0)
### BUGGY CODE ###

N, K = map(int, input().split())
A = [int(c) for c in input().split()]

numbers = set(A)
numbers = [A.count(n) for n in numbers]
numbers.sort()
if len(numbers) <= K:
    print(0)
else:
    print(sum(numbers[:len(numbers) - K]))


### FIXED CODE ###

from collections import defaultdict

N, K = map(int, input().split())
A = list(map(int, input().split()))
D = defaultdict(lambda: 0)
for a in A:
    D[a] += 1
V = list(D.values())
V.sort(reverse=True)
print(sum(V[K:]))
### BUGGY CODE ###

S=input()
Q=int(input())

guuki=0
ANS=S
for i in range(Q):
    A=list(input().split())
    if A[0]=="1":
        guuki+=1
    elif int(A[1])*guuki%2==1 or (A[1]=="2" and guuki%2==0):
        ANS=ANS+A[2]
    else:
        ANS=A[2]+ANS
if guuki%2==1:
    ANS=ANS[::-1]
print(ANS)

### FIXED CODE ###

S=input()
Q=int(input())

guuki=0
ANS=S
ANS_back=""
ANS_front=""
for i in range(Q):
    A=list(input().split())
    if A[0]=="1":
        guuki+=1
    elif int(A[1])*guuki%2==1 or (A[1]=="2" and guuki%2==0):
        ANS_back+=A[2]
    else:
        ANS_front+=A[2]
if guuki%2==1:
    ANS=ANS[::-1]
    ANS_back,ANS_front=ANS_front,ANS_back
print(ANS_front[::-1]+ANS+ANS_back)
### BUGGY CODE ###

n, m = map(int, input().split())
a = list(map(int, input().split()))
for _ in range(m):
    b, c = map(int, input().split())
    a.extend([c] * b)
a.sort(reverse=True)
print(sum(a[:n]))


### FIXED CODE ###

n, m = map(int, input().split())
A = list(map(int, input().split()))
d = {}
for a in A:
    d[a] = 1 if a not in d else d[a] + 1
for _ in range(m):
    b, c = map(int, input().split())
    d[c] = b if c not in d else d[c] + b
ans = 0
cnt = 0
L = sorted(d, reverse=True)
for k in L:
    if d[k] + cnt < n:
        ans += k * d[k]
        cnt += d[k]
    else:
        ans += k * (n - cnt)
        break
print(ans)
### BUGGY CODE ###

MAXLEN = 2000

def match(ch1, ch2):
    return ch1 == ch2 or ch1 == '?' or ch2 == '?'

def solve():
    a = raw_input()
    b = raw_input()
    c = raw_input()
    lA = len(a); lB = len(b); lC = len(c)
    ab = [True for i in range(10*MAXLEN)]
    ac = [True for i in range(10*MAXLEN)]
    bc = [True for i in range(10*MAXLEN)]
    for i in range(lA):
        for j in range(lB):
            if not match(a[i], b[j]):
                ab[i - j + 5 * MAXLEN] = False
    for i in range(lA):
        for j in range(lC):
            if not match(a[i], c[j]):
                ac[i - j + 5 * MAXLEN] = False
    for i in range(lB):
        for j in range(lC):
            if not match(b[i], c[j]):
                bc[i - j + 5 * MAXLEN] = False
    ret = lA + lB + lC
    for i in range(-2*MAXLEN, 2*MAXLEN+1):
        for j in range(-2*MAXLEN, 2*MAXLEN+1):
            if ab[i + 5*MAXLEN] and ac[j + 5*MAXLEN] and bc[j - i + 5*MAXLEN]:
                L = min(0, i, j)
                R = max(lA, lB + i, lC + j)
                ret = min(ret, R - L)
    print ret

if __name__ == '__main__':
    solve()


### FIXED CODE ###

def match(ch1, ch2):
    return ch1 == ch2 or ch1 == '?' or ch2 == '?'

def solve():
    MAXLEN = 2000
    a = raw_input()
    b = raw_input()
    c = raw_input()
    lA = len(a); lB = len(b); lC = len(c)
    MAXLEN = max(lA, lB, lC)
    ab = [True for i in range(10*MAXLEN)]
    ac = [True for i in range(10*MAXLEN)]
    bc = [True for i in range(10*MAXLEN)]
    for i in range(lA):
        for j in range(lB):
            if not match(a[i], b[j]):
                ab[i - j + 5 * MAXLEN] = False
    for i in range(lA):
        for j in range(lC):
            if not match(a[i], c[j]):
                ac[i - j + 5 * MAXLEN] = False
    for i in range(lB):
        for j in range(lC):
            if not match(b[i], c[j]):
                bc[i - j + 5 * MAXLEN] = False
    ret = lA + lB + lC
    for i in range(-2*MAXLEN, 2*MAXLEN+1):
        for j in range(-2*MAXLEN, 2*MAXLEN+1):
            if i < -MAXLEN and j > 0:
                continue
            if i > MAXLEN and j < 0:
                continue
            if j < -MAXLEN and i > 0:
                continue
            if j > MAXLEN and i < 0:
                continue
            if ab[i + 5*MAXLEN] and ac[j + 5*MAXLEN] and bc[j - i + 5*MAXLEN]:
                L = min(0, i, j)
                R = max(lA, lB + i, lC + j)
                ret = min(ret, R - L)
    print ret

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

n,k = map(int,input().split())
p = list(map(int, input().split()))
l = [[] for i in range(n)]#期待値
m = [[] for i in range(n - k + 1)]  #k個の合計

for i in range(n):
    for j in range(p[i]):
        j += 1
        l[i].append(j/ p[i])
#        logging.debug("l[i]={},i={},j={}".format(l[i],i,j))
    l[i] = sum(l[i])

#logging.debug("l = {}".format(l))#
m[0] = sum(l[0:k])

for i in range(1, n - k + 1):
    #logging.debug("m[i-1] = {} ,l[i-1] = {} ,l[i+k] = {}".format(m[i - 1], l[i - 1], l[i + k - 1]))  #
    m[i] = m[i - 1] - l[i - 1] + l[i + k - 1]

#logging.debug(m)#
print(max(m))

### FIXED CODE ###

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

#logging.debug("デバッグスタート") #
l = [[] for i in range(n)]#期待値
m = [[] for i in range(n - k + 1)]  #k個の合計

for i in range(n):
    l[i] = (1 + p[i]) / 2

#logging.debug("l = {}".format(l))#
m[0] = sum(l[0:k])
ans = m[0]

for i in range(1, n - k + 1):
    #logging.debug("m[i-1] = {} ,l[i-1] = {} ,l[i+k] = {}".format(m[i - 1], l[i - 1], l[i + k - 1]))  #
    m[i] = m[i - 1] - l[i - 1] + l[i + k - 1]
    if m[i] > ans:
        ans = m[i]

#logging.debug(m)#
print(ans)
### BUGGY CODE ###

import bisect
N= int(input())
dp = [-1]*N
cnt =0
for i in range(N):
    a = int(input())
    idx = bisect.bisect_left(dp[N-i-1:],a)
    dp[(N-i-1)+idx-1]=a
print(len(dp[bisect.bisect_left(dp,0):]))


### FIXED CODE ###

import bisect
N= int(input())
dp = [-1]*N
cnt =0
for _ in range(N):
    a = int(input())
    idx = bisect.bisect_left(dp,a)
    dp[idx-1]=a
print(len(dp[bisect.bisect_left(dp,0):]))
### BUGGY CODE ###

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

ans = 0
i = 0

for i in range(N):
    tmp = 0
    while i<N-1:
        if H[i]>=H[i+1]:
            tmp += 1
            i += 1
        else:
            break
    ans = max(tmp,ans)
    i += 1
    
print(ans)

### FIXED CODE ###

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

ans = 0
i = 0

for k in range(N):
    tmp = 0
    while i<N-1:
        if H[i]>=H[i+1]:
            tmp += 1
            i += 1
        else:
            break
    ans = max(tmp,ans)
    if i >= N-1:
        break
    i += 1
    
    
print(ans)
### BUGGY CODE ###

from collections import deque

h,w = map(int,input().split())
m = [input() for _ in range(h)]
vm  = [[-1] * w for _ in range(h) ]

q = deque()

for i in range(h):
    for j in range(w):
        if m[i][j] == '#':
            q.append((i,j))
            vm[i][j]=0

while q:
    y,x = q.popleft()
    d = vm[y][x]

    for i,j in ([1, 0], [-1, 0], [0, 1], [0, -1]):
        yi , xj = y + i , x + j
        if yi >= 0 and xj >= 0 and yi < h and xj < w and vm[yi][xj] == -1 :
            vm[yi][xj] = d +  1
            q.append([yi,xj])
            

print(d)


### FIXED CODE ###

from collections import deque

h,w = map(int,input().split())
m = [input() for _ in range(h)]
vm  = [[-1] * w for _ in range(h) ]

q = deque()

for i in range(h):
    for j in range(w):
        if m[i][j] == '#':
            q.append((i,j))
            vm[i][j]=0

while q:
    y,x = q.popleft()
    d = vm[y][x]

    for i,j in ([1, 0], [-1, 0], [0, 1], [0, -1]):
        yi , xj = y + i , x + j
        if yi >= 0 and xj >= 0 and yi < h and xj < w and vm[yi][xj] == -1 :
            vm[yi][xj] = d +  1
            q.append([yi,xj])
            

print(d)
### BUGGY CODE ###

N,Q = map(int,input().split())
S = input()

ansLis = []
for i in range(N+1):
    ansLis.append(S[:i].count("AC"))
# print(ansLis)

ans = []
for _ in range(Q):
    l,r = map(int,input().split())
    num = ansLis[r] - ansLis[l]
    # if S[l-2] == "A" and S[l-1] == "C":
    #     num = max(0, num-1)
    ans.append(num)

print(*ans,sep="\n")

### FIXED CODE ###

N,Q = map(int,input().split())
S = input()

ansLis = [0]
tmp = 0
flgA = False
for i in range(N):
    if flgA and S[i]=="C":
        tmp += 1
    ansLis.append(tmp)
    flgA = (S[i] == "A")
# print(ansLis)

ans = []
for _ in range(Q):
    l,r = map(int,input().split())
    num = ansLis[r] - ansLis[l]
    # if S[l-2] == "A" and S[l-1] == "C":
    #     num = max(0, num-1)
    ans.append(num)

print(*ans,sep="\n")
### BUGGY CODE ###

n = int(input())
a_input = [0]*n
b_input = [0]*n
for i in range(n):
    a_input[i],b_input[i]=map(int,input().split())

ans=0
for i in range(n-1,-1,-1):
    if a_input[i]%b_input[i]==0:
        continue
    tmp = b_input[i]-a_input[i]%b_input[i]
    ans += tmp
    for j in range(i+1):
        a_input[j]+=tmp
print(ans)


### FIXED CODE ###

n = int(input())
a_input = [0]*n
b_input = [0]*n
for i in range(n):
    a_input[i],b_input[i]=map(int,input().split())

a_input=a_input[::-1]
b_input=b_input[::-1]

ans=0
for i in range(n):
    a = a_input[i]+ans
    b = b_input[i]
    tmp = a%b
    if tmp==0:
        continue
    ans+=(a//b+1)*b-a
print(ans)
### BUGGY CODE ###

import sys, re
from math import ceil, floor, sqrt, pi#, gcd
from copy import deepcopy
from collections import Counter, deque
from heapq import heapify, heappop, heappush
from itertools import accumulate, product, combinations, combinations_with_replacement
from bisect import bisect, bisect_left
from functools import reduce
input = sys.stdin.readline 
def i_input(): return int(input())
def i_map(): return map(int, input().split())
def i_list(): return list(i_map())
def i_row(N): return [i_input() for _ in range(N)]
def i_rpw_list(N): return [i_list() for _ in range(N)]
def s_input(): return input()
def s_map(): return input().split()
def s_list(): return list(s_map())
def s_row(N): return [s_input for _ in range(N)]
def s_row_list(N): return [s_list() for _ in range(N)]
def Yes(): print('Yes')
def No(): print('No')
def YES(): print('YES')
def NO(): print('NO')
def lcm(a, b): return a * b // gcd(a, b)
sys.setrecursionlimit(10 ** 6)
INF = float('inf')
MOD = 10 ** 9 + 7

def dfs(current, parent, edges, ans_list):
    for child in edges[current]:
        if child == parent:
            continue
        ans_list[child] += ans_list[current]
        dfs(child, current, edges, ans_list)

def main():
    n, q = i_map()

    edges = [[] for _ in range(n)]
    for i in range(n-1):
        a, b = i_map()
        edges[a-1].append(b-1)
        edges[b-1].append(a-1)

    ans_list = [0] * n
    for i in range(q):
        p, x = i_map()
        ans_list[p-1] += x

    dfs(0, -1, edges, ans_list)

    print(*ans_list)

if __name__ == '__main__':
    main()

### FIXED CODE ###

import sys, re
from math import ceil, floor, sqrt, pi#, gcd
from copy import deepcopy
from collections import Counter, deque
from heapq import heapify, heappop, heappush
from itertools import accumulate, product, combinations, combinations_with_replacement
from bisect import bisect, bisect_left
from functools import reduce
input = sys.stdin.readline 
def i_input(): return int(input())
def i_map(): return map(int, input().split())
def i_list(): return list(i_map())
def i_row(N): return [i_input() for _ in range(N)]
def i_rpw_list(N): return [i_list() for _ in range(N)]
def s_input(): return input()
def s_map(): return input().split()
def s_list(): return list(s_map())
def s_row(N): return [s_input for _ in range(N)]
def s_row_list(N): return [s_list() for _ in range(N)]
def Yes(): print('Yes')
def No(): print('No')
def YES(): print('YES')
def NO(): print('NO')
def lcm(a, b): return a * b // gcd(a, b)
sys.setrecursionlimit(10 ** 7)
INF = float('inf')
MOD = 10 ** 9 + 7

def dfs(current, parent, edges, ans_list):
    for child in edges[current]:
        if child == parent:
            continue
        ans_list[child] += ans_list[current]
        dfs(child, current, edges, ans_list)

def main():
    n, q = i_map()

    edges = [[] for _ in range(n)]
    for i in range(n-1):
        a, b = i_map()
        edges[a-1].append(b-1)
        edges[b-1].append(a-1)

    ans_list = [0] * n
    for i in range(q):
        p, x = i_map()
        ans_list[p-1] += x

    dfs(0, -1, edges, ans_list)

    print(*ans_list)

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

def divisors_count(n):
    i = 1
    c = 0
    while i*i <= n:
        if n % i == 0:
            c += 1
            if i != n // i:
                c += 1
        i += 1
    return c

N = int(input())
ans = 0
for i in range(1, N+1):
    ans += i * divisors_count(i)
print(ans)

### FIXED CODE ###

N = int(input())
ans = 0

for i in range(1, N+1):
    j = N // i
    ans += int(j * (j+1) * i / 2)
print(ans)
### BUGGY CODE ###

N= int(input())
A=[]
B=[]
for x in range(0,N):
    A.append(int(input()))
    B.append(A[x])
for x in range(0,N):
    A[x]=0
    print(max(A))
    A[x]=B[x]

### FIXED CODE ###

N= int(input())
A=[]
for x in range(0,N):
    A.append(int(input()))
B=sorted(A)
for x in range(0,N):
    if A[x]==B[N-1]:
        print(B[N-2])
    else:
        print(B[N-1])
### BUGGY CODE ###

import numpy as np
N,M=(int(x) for x in input().split())
a=list(map(int,input().split()))
A=np.array(a)
for m in range(M):
    A[np.argmax(A)]=A[np.argmax(A)]/2
ans=0
for n in range(N):
    ans+=round(A[n])
print(ans)


### FIXED CODE ###

import heapq
N,M=(int(x) for x in input().split())
a=list(map(int,input().split()))
a=list(map(lambda x: x*(-1),a))
heapq.heapify(a)
for _ in range(M):
    dai=heapq.heappop(a)
    heapq.heappush(a,(-1)*(dai*(-1)//2))
print((-1)*sum(a))