题目描述
Problem Description
Kagamiz is extremely overweight. As a result, he has been trying various things that seem good for his health lately.
Kagamiz wants to go to the rooftop for sunbathing, but due to his weight, he broke the ladder necessary to reach the rooftop.
Having no other choice, he must find an alternative way to reach the rooftop, but all he finds indoors are concrete blocks haphazardly stacked. Therefore, the clever Kagamiz plans to stack the concrete blocks in a staircase pattern to reach the rooftop.
Let's summarize the situation. The rooftop is located at height $ N+1 $. There are exactly $\frac{N(N+1)}{2}$ ($ =1+2+...+N $) concrete blocks, each of height $ 1 $, haphazardly stacked in $ N $ locations.
The blocks are lined up in a straight line. Since Kagamiz can only climb a height difference of $ 1 $, he wants to create a staircase from the farthest to the nearest side of the rooftop, with $ 1 $ step, $ 2 $ steps, ..., $ N $ steps.
Let's define one operation as moving the top block from one block stack to the top of another block stack.
For example, let's say $ N=4 $ and the blocks are initially stacked as "3 steps, 1 step, 5 steps, 1 step" from the farthest to the nearest side. One possible set of operations to create the staircase is shown in the figure below.

Your task is, given the initial state of the $ N $ block stacks, to count the minimum number of operations needed for Kagamiz to build the staircase to reach the rooftop.
Input Format
$ N $ $ A_1 $ $ A_2 $ : $ A_N $
Output Format
Output the minimum number of operations required in one line.
Sample Input and Output
Sample Input #1
3
3
2
1
Sample Output #1
2
Sample Input #2
4
3
1
5
1
Sample Output #2
4
Sample Input #3
5
7
8
0
0
0
Sample Output #3
12
Notes/Hints
Task
You are given a sequence of non-negative integers $ A $ with $ N $ elements. The sum of the elements in $ A $ is $\frac{N(N+1)}{2}$ ($ =1+2+...+N $).
In one operation, you can decrease the value of any element in $ A $ by $ 1 $ and increase the value of any other element in $ A $ by $ 1 $.
Find the minimum number of operations required to make $ A_i = i $ for $ i = 1, ..., N $.
Constraints
All input data satisfies the following constraints:
- $ 1 ≦ N ≦ 100 $.
Sample Explanation 1
It is sufficient to perform the operation of reducing $ A_1 $ and increasing $ A_3 $ twice.
输入格式
见题面 Input 部分
输出格式
见题面 Output 部分