Happy Sequence

Change a sequence with unit-cost edits so every interior term equals the sum of its two neighbours, minimizing total edits.

Medium6MathImplementationGreedyBrute forceInterviewNo attempts yetTime limit3sMemory limit512 MB

Problem

A sequence of integers a1,a2,,ana_1, a_2, \dots, a_n is called happy if every element except the first and the last one equals the sum of its two neighbours, that is, aj=aj1+aj+1a_j = a_{j-1} + a_{j+1} for every jj with 2jn12 \le j \le n-1.

You are given a sequence of integers. In one step you can choose one element of the sequence and increase or decrease it by one. Find the minimum number of steps needed to obtain a happy sequence.

Input

The first line contains a positive integer nn, the length of the sequence. (3n3000003 \le n \le 300\,000)

The second line contains nn integers a1,a2,,ana_1, a_2, \dots, a_n separated by spaces. (109aj109-10^9 \le a_j \le 10^9)

Output

Print the minimum number of steps.

Note

In the second example, 6 steps are enough to reach the happy sequence (2,2,0,2)(2, 2, 0, -2).