Тавсифи масъала
On an Archive Server in Earth's orbit, there are modules placed in a row. Each module contains an unknown integer value: .
Husanboy wants to learn all these values, but due to the security system, he cannot read the module contents directly. The server only provides the following paid service:
If Husanboy chooses and (), the server tells him the sum of the values in the interval : . In return, Husanboy pays "credits".
Husanboy may make as many queries as he wants. His goal is to reconstruct all values exactly, while minimizing the total cost.
Input Format
The first line contains one positive integer .
The next lines describe the query costs. On line there are non-negative integers, in the following order:
Constraints
for all
Output Format
Print one integer --- the minimum total cost Husanboy must pay to determine all elements of array .
Scoring
| Subtask | Constraints | Points |
|---|---|---|
| 1 | 19 | |
| 2 | 29 | |
| 3 | No additional constraints | 52 |
Мисолҳо
3 5 5 1 5 2 5
8
The minimum total cost is .
- Pay to learn .