#QHD0000001. Ếch 1 (Frog 1)
Ếch 1 (Frog 1)
Frog 1
Source: AtCoder
Version: Phuoc Hung OJ Extended
Problem Statement
There are stones with heights . A frog starts at stone 1 and may jump to stone or . A jump from to costs . Find the minimum total cost to reach stone .
Input
Line 1 contains . Line 2 contains integers .
Output
Print the minimum total cost.
Subtasks
- Subtask 1 — 20 points: 2 <= N <= 20.
- Subtask 2 — 30 points: 2 <= N <= 2000.
- Subtask 3 — 50 points: 2 <= N <= 100000; 1 <= h_i <= 10000.
Examples
Input
4
10 30 40 20
Output
30
Explanation
An optimal route is , with cost .