Problem list
Log in
#coci00470 · COCI 2017/2018 Contest 4

Krov

Diamond IV 1.0 s 256 MB

1.5 $s / 128$ $MB / 140$ points

You are given a histogram consisting of ​$N$ columns of heights ​$X$​_{1}{​}, ​$X$​{2}{​}, ... ​$X$​{N}_{​}, respectively. The

histogram needs to be transformed into a roof using a series of operations. A roof is a

histogram that has the following properties: ● A single column is called the top of the roof. Let it be the column at position ​$i$​. ● The height of the column at position ​$j$​ (1 ≤ ​$j$​ ≤ ​$N$​) is ​$h$​_{j}{​} = ​$h$​{i}{​} - |​$i - j$​|. ● All heights ​$h$​{j}_{​} are positive integers.

An operation can be increasing or decreasing the heights of a column of the histogram by 1.

It is your task to determine the minimal number of operations needed in order to transform

the given histogram into a roof.

Input

The first line of input contains the number ​$N$ ​(1 ≤​$N \le 10$​^{5}^{​}), the number of columns in the

histogram. The following line contains ​$N$​ numbers ​$X$​_{i}{​} (1 ≤ ​$X$​{i}_{​} ≤ 10​^{9}^{​}), the initial column heights.

Output

You must output the minimal number of operations from the task.

Constraints

In test cases worth 60% of total points, it will hold ​$N$​ ≤ 5000.

Example 1

Input
4
1 1 2 3
Output
3

Example 2

Input
5
4 5 7 2 2
Output
4

Example 3

Input
6
4 5 6 5 4 3
Output
0
Source
COCI 2017/2018 Contest 4
Appears in
Not part of a ladder, contest or set yet.
Accepted 0 Submissions 0 Acceptance 0% Solvers 0

Discussion

Threads about this problem. Spoilers are collapsed; wrap hints in ||double bars||.

No discussion yet. Start a thread if something here needs explaining.

Recent submissions Open with filters
Code