Baltic Olympiad in Informatics: 2007 Day 2, Problem 3
We are given a sequence reduce(i)
,
which replaces elements reduce
operations, we obtain a
sequence of length
Constraints
Subtask 1 [30%]
Subtask 2 [20%]
Subtask 3 [50%]
No additional constraints.
Input Specification
The first line of input contains an integer
Output Specification
Output the minimal cost of reducing the sequence to a single element.
Sample Input
Copy
3
1
2
3
Sample Output
Copy
5
Explanation for Sample Output
The optimal way to reduce the array to one element has a cost of
- [1, 2, 3] → [2, 3]
- [2, 3] → [3]
Comments