Under construction

Still being built. Things may change

Sequence

Time limit1sMemory limit1024 MB

Summary
Given a weight for each value from 1 to n, find for every v the minimum total weight of a good sequence that contains v.
Level

Hard8 of 10

Topics
Dynamic programming, Shortest path, Math
Solved
No attempts yet

Problem

A sequence of positive integers (x1,…,xm)(x_1,\ldots,x_m) is good if x1=1x_1 = 1 and for each 1<j≤m1 < j \leq m we have either xj=xj−1+1x_j = x_{j-1}+1 or xj=xk⋅xlx_j = x_k \cdot x_l for some kk and ll with 0<k≤l<j0 < k \leq l < j. For instance, the sequences (1,1)(1,1) and (1,2)(1,2) are both good, but the sequence (1,3)(1,3) is not good.

Given nn integers w1,…,wnw_1,\ldots,w_n, the weight of an integer sequence (x1,…,xm)(x_1,\ldots,x_m) with 1≤xj≤n1 \leq x_j \leq n for each 1≤j≤m1 \leq j \leq m is

wx1+⋯+wxm.w_{x_1} + \cdots + w_{x_m}.

For instance, given the weights w1=10w_1=10, w2=42w_2=42, w3=1w_3=1, the weight of (1,1)(1,1) is 2020 and the weight of (1,3)(1,3) is 1111.

For 1≤v≤n1 \leq v \leq n, let svs_v be the smallest possible weight of a good sequence that contains the value vv.

Input

The first line contains the integer nn, the number of weights. Each of the next nn lines contains one integer weight w1,…,wnw_1, \ldots, w_n.

Output

Print nn lines. The vv-th line contains svs_v, for v=1,…,nv = 1, \ldots, n.

Constraints

1≤n≤30 0001 \leq n \leq 30\,000 and 1≤wi≤1061 \leq w_i \leq 10^6 for each 1≤i≤n1 \leq i \leq n.

Examples1

  1. Example 1

    Input
    3
    10
    42
    1
    
    Expected output
    10
    52
    53