Sequence

시간 제한1초메모리 제한1024 MB

요약
각 값 v에 대해 v를 포함하는 좋은 수열의 최소 가중치를 구한다. 좋은 수열은 1로 시작하고 각 항이 이전 항에 1을 더한 값이거나 앞선 두 항의 곱이다.
난이도

어려움10점 중 8점

유형
동적 계획법, 정수론, 수학, 구현
정답자
아직 제출이 없습니다

문제

A sequence of positive integers (x_1,…,x_m)(x\_1,\ldots,x\_m) is good if x_1=1x\_1 = 1 and for each 1<j≤m1 < j \leq m we have either x_j=x_j−1+1x\_j=x\_{j-1}+1 or x_j=x_k⋅x_lx\_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. For nn given integers w_1,…,w_nw\_1,\ldots,w\_n define the weight of an integer sequence (x_1,…,x_m)(x\_1,\ldots,x\_m) satisfying 1≤x_j≤n1\leq x\_j \leq n for each 1≤j≤m1\leq j\leq m as \[ w_{x_1} +\cdots +w_{x_m}\,.\] For instance, given the weights w_1=10,w_2=42,w_3=1w\_1=10, w\_2=42,w\_3= 1, the weight of the sequence (1,1)(1,1) is 2020 and the weight of the sequence (1,3)(1,3) is 1111. For 1≤v≤n1\leq v\leq n, define s_vs\_v as the smallest possible weight of a good sequence containing the value vv.

Your task is to determine the values s_1,…,s_ns\_1,\ldots ,s\_n.

입력

The first line of input consists of the integer nn, the number of weights. The next nn lines contain the integer weights w_1,…,w_nw\_1, \ldots, w\_n.

출력

Print nn lines containing s_1s\_1, …\ldots, s_ns\_n in order.

제한

We always have 1≤n≤30,0001\leq n \leq 30\\,000 and 1≤w_i≤1061\leq w\_i \leq 10^6 for each 1≤i≤n1\leq i \leq n.

예제1

  1. 예제 1

    입력
    3
    10
    42
    1
    
    예상 출력
    10
    52
    53