Problem:
Score : 300 points

Problem Statement

Snuke has an integer sequence A of length N.

He will freely choose an integer b.
Here, he will get sad if A_i and b+i are far from each other.
More specifically, the sadness of Snuke is calculated as follows:

abs(A_1 - (b+1)) + abs(A_2 - (b+2)) + ... + abs(A_N - (b+N))

Here, abs(x) is a function that returns the absolute value of x.

Find the minimum possible sadness of Snuke.

Constraints

1 \leq N \leq 2 \times 10^5

1 \leq A_i \leq 10^9

All values in input are integers.

Input

Input is given from Standard Input in the following format:

N
A_1 A_2 ... A_N

Output

Print the minimum possible sadness of Snuke.

Sample Input 1

5
2 2 3 5 5

Sample Output 1

2

If we choose b=0, the sadness of Snuke would be abs(2-(0+1))+abs(2-(0+2))+abs(3-(0+3))+abs(5-(0+4))+abs(5-(0+5))=2.
Any choice of b does not make the sadness of Snuke less than 2, so the answer is 2.

Sample Input 2

9
1 2 3 4 5 6 7 8 9

Sample Output 2

0

Sample Input 3

6
6 5 4 3 2 1

Sample Output 3

18

Sample Input 4

7
1 1 1 1 2 3 4

Sample Output 4

6

Solution in C++14 (GCC 5.4.1) (judge verdict: Wrong Answer)

//#pragma once
#include <stdio.h>
#include <stdlib.h>
#include <string>
#include <iostream>
#include <queue>
#include <algorithm>
#include <sstream>
#include <vector>
#include <math.h>
#include <set>
#include <map>
#include <numeric>
#include <bitset>
#include <iomanip>
#include <cctype>
#include <cstdlib>      // srand,rand


using namespace std;
#define ll long long

#define modd 1000000007
#define INF 1000000000000000000ll


typedef pair<long long, long long> pl;



typedef string::const_iterator State;
class ParseError {};








class UnionFind {
public:
	vector <ll> par;
	vector <ll> siz;

	// Constructor
	UnionFind(ll sz_) : par(sz_), siz(sz_, 1LL) {
		for (ll i = 0; i < sz_; ++i) par[i] = i;
	}
	void init(ll sz_) {
		par.resize(sz_);
		siz.assign(sz_, 1LL);  // resize だとなぜか初期化されなかった
		for (ll i = 0; i < sz_; ++i) par[i] = i; // 初期では親は自分自身
	}

	// Member Function
	// Find
	ll root(ll x) { // 根の検索
		while (par[x] != x) {
			x = par[x] = par[par[x]]; // x の親の親を x の親とする
		}
		return x;
	}

	// Union(Unite, Merge)
	bool merge(ll x, ll y) {
		x = root(x);
		y = root(y);
		if (x == y) return false;

		// merge technique（データ構造をマージするテク．小を大にくっつける）
		if (siz[x] < siz[y]) swap(x, y);
		siz[x] += siz[y];
		par[y] = x;
		return true;
	}



	bool issame(ll x, ll y) { // 連結判定
		return root(x) == root(y);
	}

	ll size(ll x) { // 素集合のサイズ
		return siz[root(x)];
	}


};

/*
struct SegmentTree {
private:
	ll n;
	vector<ll> node;

public:
	// 元配列 v をセグメント木で表現する
	SegmentTree(vector<ll> v) {
		// 最下段のノード数は元配列のサイズ以上になる最小の 2 冪 -> これを n とおく
		// セグメント木全体で必要なノード数は 2n-1 個である
		ll sz = v.size();
		n = 1; while (n < sz) n *= 2;
		node.resize(2 * n - 1, INF);

		// 最下段に値を入れたあとに、下の段から順番に値を入れる
		// 値を入れるには、自分の子の 2 値を参照すれば良い
		for (ll i = 0; i < sz; i++) node[i + n - 1] = v[i];
		for (ll i = n - 2; i >= 0; i--) node[i] = min(node[2 * i + 1], node[2 * i + 2]);
	}


	void update(ll x, ll val) {
		// 最下段のノードにアクセスする
		x += (n - 1);

		// 最下段のノードを更新したら、あとは親に上って更新していく
		node[x] = val;
		while (x > 0) {
			x = (x - 1) / 2;
			node[x] = min(node[2 * x + 1], node[2 * x + 2]);
		}
	}

};
*/


ll N, M, K, a, b, c, d, e, H, W, L, T;
ll x, y;
ll A[400400] = {};
ll B[400400] = {};
ll C[400400] = {};
ll D[1000006] = {};
ll E[1000006] = {};
bool f, ff;
string S[200000];
string SS;
set <long long>sll;
pl bufpl;
vector <long long>vl[300005];
vector <long long>vll;
vector <pl>vpl;
vector <string> vs;
set<ll> llset;
multiset<ll> llmset;
queue<ll> ql;
multiset<pl> plmset;


struct ST
{
	ll first;
	ll second;
	ll kaisuu;


	/*bool operator<(const ST& another) const
	{
		return first < another.first;//比較
	};*/

};
queue<ST> qpl;



/*vector <ST> vst;
ST st[200005];
ST bufst;
bitset<5000> bits;*/

/*
long long modinv(long long aa, long long mm) {
	long long bb = mm, uu = 1, vv = 0;
	while (bb) {
		long long tt = aa / bb;
		aa -= tt * bb; swap(aa, bb);
		uu -= tt * vv; swap(uu, vv);
	}
	uu %= mm;
	if (uu < 0) uu += mm;
	return uu;
}


*/


ll zettai(ll aa) {

	if (aa < 0) {
		aa *= -1;
	}
	return aa;

}





/*
struct edge {
	ll from;
	ll to;
	ll cost;
};



ll V, E, d[300000];
edge es[300000];
bool fa[5000][5000];
bool ffa[5000];

bool has_negative_loop(ll s) {
	fill(d, d + V, 50000000000000000);
	d[s] = 0;
	for (ll i = 0; i <=2* V+1; i++) {
		for (ll j = 0; j < E; j++) {
			edge e = es[j];
			if (d[(int)e.to] > d[(int)e.from] + e.cost) {
				d[(int)e.to] = d[(int)e.from] + e.cost;
				if (i >= V+1 && fa[(int)e.to][V-1]==true &&fa[0][(int)e.from] == true) {
					return true;
				}
			}
		}
	}
	return false;
}
*/

/*struct cww { cww() { ios::sync_with_stdio(false); cin.tie(0); } }star;


bool is_prime[1000000 + 1];
vector<int> P;
void Eratosthenes(const int N)
{
	for (int i = 0; i <= N; i++)
	{
		is_prime[i] = true;//初期化
	}
	for (int i = 2; i <= N; i++)
	{
		if (is_prime[i])
		{
			for (int j = 2 * i; j <= N; j += i)
			{
				is_prime[j] = false;
			}
			P.emplace_back(i);
		}
	}
}*/

ll t;

ll RepeatSquaring(ll N, ll P, ll MO) {
	if (P == 0) return 1;
	if (P % 2 == 0) {
		ll t = RepeatSquaring(N, P / 2, MO);
		return t * t % MO;
	}
	return N * RepeatSquaring(N, P - 1, MO);
}

ll gyakugen(ll numb, ll MO) {
	return RepeatSquaring(numb, MO - 2, MO);
}

/*
ll Com(ll NN, ll KK) {
	e = D[NN];
	e *= C[KK];
	e %= modd;
	e *= C[NN - KK];
	e %= modd;
	return e;

}

*/

bool ita[200000] = {};
ll saitan[200000] = {};
pl bpl;

int main() {

	cin >> N;

a=0;
	for (int i = 0; i < N; i++) {
		cin >> A[i];
A[i]-=(i+1);
a+=A[i];
	}

a/=N;
d=a+1;
x=a-1;
b=0;
e=0;
y=0;
for(int i=0;i<N;i++){
b+=zettai (A[i]-a);
e+=zettai(A[i]-d);
y+=zettai(A[i]-x);
}
b=min(b,y);
	cout <<min(b, e) << endl;

	//cout << fixed << setprecision(10) << ansa << endl;
	return 0;



}