Problem AH
Nikola
Against his own will, Nikola has become the main character
in a game. The game is played on a row of
-
If the jump is in the forward direction, it must be one square longer than the preceding jump.
-
If the jump is in the backward direction, it must be exactly the same length as the preceding jump.
For example, after the first jump (when on square 2), Nikola
can jump back to square 1 or forwards to square 4. For
instance, if
Every time he enters a square, Nikola must pay an entry fee. Nikola’s goal is to get from square
Input
The first line contains the integer
Output
Output the smallest total cost for Nikola to get to square
Sample Input 1 | Sample Output 1 |
---|---|
6 1 2 3 4 5 6 |
12 |
Sample Input 2 | Sample Output 2 |
---|---|
8 2 3 4 3 1 6 1 4 |
14 |