Score : 1600 points
There are A slimes lining up in a row. Initially, the sizes of the slimes are all 1.
Snuke can repeatedly perform the following operation.
Snuke wants to get to the situation where there are exactly N slimes, and the size of the i-th (1 ≤ i ≤ N) slime from the left is a_i. Find the minimum number of operations required to achieve his goal.
Note that A is not directly given as input. Assume A = a_1 + a_2 + ... + a_N.
Input is given from Standard Input in the following format:
N a_1 a_2 ... a_N
Print the minimum number of operations required to achieve Snuke's goal.
2 3 3
2
One way to achieve Snuke's goal is as follows. Here, the selected slimes are marked in bold.
4 2 1 2 2
2
One way to achieve Snuke's goal is as follows.
1 1
0
10 3 1 4 1 5 9 2 6 5 3
10