#P2800. 又上锁妖塔

又上锁妖塔

Description

Little A is playing "Sword Immortal" (Jianxian). He encounters a Demon-Sealing Tower and wants to climb it from the outside.

The tower has nn floors; the height of floor ii is hih_i. Little A starts on the ground. Climbing floor ii (that is, moving from floor i1i-1 to floor ii) takes time equal to that floor’s height hih_i. Little A can use "immortal arts" (xiān shù). Each time he uses it, he can jump up by one or two floors, and this process takes no time. However, after each jump, Little A will be exhausted and must climb at least one floor to rest before he can use the immortal arts to jump again.

Now Little A wants you to compute the minimal time to reach the top (floor nn).

Input Format

The first line contains an integer nn representing the number of floors in the Demon-Sealing Tower.

The second line contains nn integers hih_i representing the height of the ii-th floor from bottom to top.

Output Format

Output a single integer tt, representing the minimal time.

5
3 5 1 8 4
1

Hint

For all testdata, it is guaranteed that 1n1061 \le n \le 10^6, 1hi1001 \le h_i \le 100.

Translated by ChatGPT 5