LogiQuest

227. Min Cost Climbing Stairs

EasyDynamic Programming

Step i costs cost[i]. Starting on step 0 or 1, you may climb 1 or 2 steps at a time. Print the minimum cost to reach the top (just past the last step).

Input format

Line 1: n Line 2: n costs

Output format

The minimum cost.

Example 1

Input

3
10 15 20

Output

15

Example 2

Input

10
1 100 1 1 1 100 1 1 100 1

Output

6

Constraints

2 ≤ n ≤ 10⁵

Read input from standard input and print the answer to standard output. Your code is judged against 5 test cases, most of them hidden.

Loading the MyLoginn IDE…