Sequence
Time limit1sMemory limit1024 MB
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 is good if and for each we have either or for some and with . For instance, the sequences and are both good, but the sequence is not good.
Given integers , the weight of an integer sequence with for each is
For instance, given the weights , , , the weight of is and the weight of is .
For , let be the smallest possible weight of a good sequence that contains the value .
Input
The first line contains the integer , the number of weights. Each of the next lines contains one integer weight .
Output
Print lines. The -th line contains , for .
Constraints
and for each .