#QHD0000036. Những bước nhảy của Nikola (Nikola)
Bài tập thuộc lộ trình
Mục lục đề ⌄
Những bước nhảy của Nikola (Nikola)
Nikola
Source: Kattis
Version: Phuoc Hung OJ Extended
Problem Statement
Nikola moves along squares in a row, numbered through . He starts at square and his first jump must land on square .
After each jump he may jump forward or backward. A forward jump must be exactly one square longer than the previous jump; a backward jump must have the same length as the previous jump. He may land only on squares in . Landing on square costs , while the initial position costs nothing.
Find the minimum total cost needed to reach square .
Input
The first line contains , the number of squares.
Each of the next lines contains an integer , the landing cost of square .
Output
Print the minimum total landing cost to reach square .
Subtasks
- Subtask 1 (20 points): ; .
- Subtask 2 (30 points): ; .
- Subtask 3 (50 points): ; .
Examples
Input
6
1
2
3
4
5
6
Output
12
Explanation
Nikola starts at square and must first jump to square . Later forward jumps increase in length by one, while backward jumps retain the previous length. One optimal route is : jumps of lengths forward, backward, forward, and forward. The landing costs are . No cheaper route exists.