stablegradients/pie-gem5-pairs huggingface dataset:
// Slower C++ solution:
#include<bits/stdc++.h>

using namespace std;

long long int a[2000005];

int main()

{

    int i,n;

    scanf("%d",&n);

    multiset<long long int>st;

    multiset <long long int > :: iterator itr;

    for(i=0; i<n; i++)

    {

        scanf("%lld",&a[i]);

        a[i]-=i+1;

        //printf("%lld\n",a[i]);



    }

    long long int ans=0;

    sort(a,a+n);

    for(i=0; i<n; i++)

    {

        ans+=abs(a[i]-a[n/2]);

    }

    printf("%lld\n",ans);

    return 0;

}


// Faster C++ solution for the same problem (measured speedup: 5.204247640848361x):
#include<cstdio>

#include<algorithm>

#include<cmath>

using namespace std;

typedef long long ll;

const int maxn = 2e5 + 7;

int a[maxn];

int main(){

    int n;

    scanf("%d", &n);

    for(int i = 1; i <= n; ++i){

        scanf("%d", &a[i]);

        a[i] -= i;

    }

    sort(a+1, a+1+n);

    ll sum = 0;

    for(int i = 1; i <= n; ++i){

        sum += abs(a[i] - a[(n+1)/2]);

    }

    printf("%lld\n", sum);

}
// Slower C++ solution:
#include <bits/stdc++.h>



using namespace std;



typedef long long ll;

typedef long double ld;

typedef vector<int> vi;

typedef vector<vector<int> > vvi;

typedef pair<int, int> pii;



#define erep(i, x, n) for (auto i = x; i<=(ll)(n); i++)

#define rep(i, x, n) for(auto i = x; i<(ll)(n); i++)

#define all(v) ((v).begin()), ((v).end())

#define sz(v) ((int)((v).size()))

#define mod(n, m) ((n%m + m) % m)

#define reset(n, m) memset(n, m, sizeof n)

#define endl '\n'



const int N = 3e5 + 5;

int w[N], e[N];

int n;

vector<ll> vec;



ll check(ll b)

{

	ll res = 0;

	rep(i, 0, n)

		res += abs(vec[i] - (b + i + 1));

	return res;

}



int main()

{

	ios_base::sync_with_stdio(0);

	cin.tie(0);



	cin >> n;

	vec.resize(n);

	rep(i, 0, n)

		cin >> vec[i];



	ll st = -2e9, en = 2e9, mid, ret = INT_MIN;



	while (st <= en)

	{

		mid = (st + en) / 2;



		if (check(mid) > check(mid + 1))

			st = mid + 1;

		else

			en = mid - 1, ret = mid;

	}



	cout << check(ret) << endl;



	return 0;

}




// Faster C++ solution for the same problem (measured speedup: 5.31743290432589x):
#include<cstdio>

#include<algorithm>

#include<cmath>

using namespace std;

typedef long long ll;

const int maxn = 2e5 + 7;

int a[maxn];

int main(){

    int n;

    scanf("%d", &n);

    for(int i = 1; i <= n; ++i){

        scanf("%d", &a[i]);

        a[i] -= i;

    }

    sort(a+1, a+1+n);

    ll sum = 0;

    for(int i = 1; i <= n; ++i){

        sum += abs(a[i] - a[(n+1)/2]);

    }

    printf("%lld\n", sum);

}
// Slower C++ solution:
#include <bits/stdc++.h>

using namespace std;

#define rep(i,a,n) for (int i = a; i<n; i++)

#define per(i,a,n) for (int i = n-1; i>=a; i--)

#define pb push_back

#define mp make_pair

#define all(now) (now).begin(),(now).end()

#define fi first

#define se second

#define SZ(now) ((int)(now).size())

typedef vector<int> VI;

typedef long long ll;

typedef pair<int,int> PII;

const ll mod = 1000000007;

inline int read(int &n){char c=getchar();int x=0,f=1;while(c<'0'||c>'9'){if(c=='-')f=-1;c=getchar();}while(c>='0'&&c<='9'){x=x*10+(c-'0');c=getchar();}return n = x*f;}

ll powmod(ll a,ll b,ll mod) {ll res = 1; a%=mod; assert(b>=0); for(;b; b>>=1){if(b&1)res = res*a%mod; a = a*a%mod;}return res;}

ll gcd(ll a,ll b) { return b?gcd(b,a%b):a;}

// head

const int N = 2e5+7;

int T,n,m;

ll a[N];

int main()

{

    //ios::sync_with_stdio(false), cin.tie(0), cout.tie(0);

    while(~scanf("%d",&n))

    {

        rep(i,1,n+1){

            ll x;

            scanf("%lld", &x);

            a[i] = x-i;

        }

        sort(a + 1, a + 1 + n);

        ll b = a[n / 2+1];

        if(n&1==0) {

            b = (b + a[n / 2]) / 2;

        }



        // printf("b:%d\n", b);

        ll ans = 0;

        rep(i,1,n+1){

            ans += abs(a[i] - b);

        }

        printf("%lld\n", ans);

    }

    return 0;

}



/*



2 2 3 5 5

1 0 0 1 0



6 5 4  3  2  1

5 3 1 -1 -3 -5

5 3 1 1 3 5 = 18



1  1  1  1  2  3  4

0 -1 -2 -3 -3 -3 -3

3 2  1 0 0 0 0



*/

// Faster C++ solution for the same problem (measured speedup: 5.162231091749977x):
#include<cstdio>

#include<algorithm>

#include<cmath>

using namespace std;

typedef long long ll;

const int maxn = 2e5 + 7;

int a[maxn];

int main(){

    int n;

    scanf("%d", &n);

    for(int i = 1; i <= n; ++i){

        scanf("%d", &a[i]);

        a[i] -= i;

    }

    sort(a+1, a+1+n);

    ll sum = 0;

    for(int i = 1; i <= n; ++i){

        sum += abs(a[i] - a[(n+1)/2]);

    }

    printf("%lld\n", sum);

}
// Slower C++ solution:
#include <bits/stdc++.h>



using namespace std;



const int N = 200010;



int n, a[N];



int main() {

  cin >> n;

  for (int i = 1; i <= n; ++i) {

    scanf("%d", a + i); a[i] -= i;

  }

  sort(a + 1, a + n + 1);

  int x = a[1 + n >> 1];

  long long ans = 0;

  for (int i = 1; i <= n; ++i) {

    ans += (long long) abs(a[i] - x);

  }

  cout << ans << endl;

  return 0;

}




// Faster C++ solution for the same problem (measured speedup: 5.242323997944501x):
#include<cstdio>

#include<algorithm>

#include<cmath>

using namespace std;

typedef long long ll;

const int maxn = 2e5 + 7;

int a[maxn];

int main(){

    int n;

    scanf("%d", &n);

    for(int i = 1; i <= n; ++i){

        scanf("%d", &a[i]);

        a[i] -= i;

    }

    sort(a+1, a+1+n);

    ll sum = 0;

    for(int i = 1; i <= n; ++i){

        sum += abs(a[i] - a[(n+1)/2]);

    }

    printf("%lld\n", sum);

}
// Slower C++ solution:
#include <bits/stdc++.h>

using namespace std;

typedef long long ll;



vector<ll> v;



ll check(ll b) {

    ll ret = 0;

    for(int i = 0; i < v.size(); ++i) {

        ret += abs(v[i] - (b+1+i));

    }

    return ret;

}



ll ternarySearch(ll low, ll high) {

    ll ret = 10000000000000000LL;

    while((high - low) > 2) {

        ll mid1 = low + (high - low) / 3;

        ll mid2 = high - (high - low) / 3;

        ll cost1 = check(mid1);

        ll cost2 = check(mid2);

        if(cost1 < cost2) {

            high = mid2;

            //cerr << cost1 << " :: " << mid1 << endl;

            ret = min(cost1, ret);

        }

        else {

            low = mid1;

            //cerr << cost2 << " :: " << mid2 << endl;

            ret = min(cost2, ret);

    }}

    for(int i = low; i <= high; ++i) {

        //cerr << i << " " << check(i) << endl;

        ret = min(ret, check(i));

    }

    return ret;

}



int main() {

    int n;

    cin >> n;



    v.resize(n);

    for(int i= 0; i < n; ++i)

        scanf("%lld", &v[i]);



    cout << ternarySearch(-2000000009, 20000000009) << endl;

    return 0;

}

// Faster C++ solution for the same problem (measured speedup: 5.2632892062973x):
#include<cstdio>

#include<algorithm>

#include<cmath>

using namespace std;

typedef long long ll;

const int maxn = 2e5 + 7;

int a[maxn];

int main(){

    int n;

    scanf("%d", &n);

    for(int i = 1; i <= n; ++i){

        scanf("%d", &a[i]);

        a[i] -= i;

    }

    sort(a+1, a+1+n);

    ll sum = 0;

    for(int i = 1; i <= n; ++i){

        sum += abs(a[i] - a[(n+1)/2]);

    }

    printf("%lld\n", sum);

}
// Slower C++ solution:
#include <stdio.h>

#include <string.h>

#include <math.h>

#include <stdlib.h>

#include <ctype.h>



#include <algorithm>

#include <iostream>

#include <vector>

#include <map>

#include <set>

#include <string>

#include <sstream>

#include <stack>

#include <queue>

#include <bitset>



using namespace std;



#define deb(a)    cout<<__LINE__<<"# "<<#a<<" -> "<<a<<endl;

#define pb push_back

#define OO 2e9+10



#define ConPnt(a)   {for(auto it: a){cout<<it<<", ";}cout<<endl;}

#define MapPnt(a)   {for(auto it: a){cout<<it.first<<": "<<it.second<<", ";}cout<<endl;}



typedef long long ll;

typedef pair<int,int>pii;



template<class T> T abs(T x){

    if(x<0) return -x;

    return x;

}

template<class T>T sqr(T a){

    return a*a;

}



const double pi = acos(-1.0);

const double eps = 1e-8;





int main()

{

//    freopen("in.txt","r",stdin);

//    freopen("output.txt","w",stdout);



    ll ar[200010];

    int i;

    ll n,b,ans;

    while(1==scanf("%lld",&n))

    {

        ans = 0;

        for(i=0;i<n;i++)

        {

            scanf("%lld",&ar[i]);

            ar[i]=ar[i]-i;

        }

        sort(&ar[0],&ar[n]);

        b = ar[n/2];

        for(i=0;i<n;i++)

            ans+=abs(ar[i]-b);

        printf("%lld\n",ans);

    }



    return 0;

}


// Faster C++ solution for the same problem (measured speedup: 5.361281591609829x):
#include<cstdio>

#include<algorithm>

#include<cmath>

using namespace std;

typedef long long ll;

const int maxn = 2e5 + 7;

int a[maxn];

int main(){

    int n;

    scanf("%d", &n);

    for(int i = 1; i <= n; ++i){

        scanf("%d", &a[i]);

        a[i] -= i;

    }

    sort(a+1, a+1+n);

    ll sum = 0;

    for(int i = 1; i <= n; ++i){

        sum += abs(a[i] - a[(n+1)/2]);

    }

    printf("%lld\n", sum);

}
// Slower C++ solution:
#include <bits/stdc++.h>

using namespace std;

int main(){

	long long n;

	cin >> n;

	long long arr[n];

	for(long long i = 0; i < n; i++){

		cin >> arr[i];

	}

//	for(int i = -10; i <= 10; i++){

//		int sum = 0;

//		for(int j = 0; j < n; j++){

//			sum += abs(arr[j]- (i+j+1));

//		}

//		cout << i <<" "<<sum << endl;

//	}

	long long lo = -1e12, hi = 1e12, le, ri, take;

	while(lo <= hi){

		le = lo + (hi-lo)/3;

		ri = hi -  (hi-lo)/3;

		long long sumle = 0, sumri = 0;

		for(long long i = 0; i < n; i++){

			sumle += abs(arr[i]-le-1-i);

			sumri += abs(arr[i]-ri-1-i);

		}

		if(sumle < sumri){

			take = sumle;

			hi = ri-1;

		}else{

			take = sumri;

			lo = le+1;

		}

	}

	cout << take << endl;

}

// Faster C++ solution for the same problem (measured speedup: 5.226871262730076x):
#include<cstdio>

#include<algorithm>

#include<cmath>

using namespace std;

typedef long long ll;

const int maxn = 2e5 + 7;

int a[maxn];

int main(){

    int n;

    scanf("%d", &n);

    for(int i = 1; i <= n; ++i){

        scanf("%d", &a[i]);

        a[i] -= i;

    }

    sort(a+1, a+1+n);

    ll sum = 0;

    for(int i = 1; i <= n; ++i){

        sum += abs(a[i] - a[(n+1)/2]);

    }

    printf("%lld\n", sum);

}
// Slower C++ solution:
#include <bits/stdc++.h>



using namespace std;



const int maxN = 200000;



int N;

int A[maxN];



int main() {

	ios::sync_with_stdio(false);

	cin.tie(nullptr);

	cout.tie(nullptr);



	cin >> N;

	for (int i = 0; i < N; i++)

		cin >> A[i];



	for (int i = 0; i < N; i++)

		A[i] -= i + 1;



	sort(A, A + N);



	long long lft = 0, rht = accumulate(A, A + N, 0ll), ans = LLONG_MAX;

	for (int i = 0; i < N; i++) {

		ans = min(ans, rht - lft + (long long)A[i] * (i * 2 - N));

		lft += A[i];

		rht -= A[i];

	}



	cout << ans << '\n';



	return 0;

}


// Faster C++ solution for the same problem (measured speedup: 5.29203990703541x):
#include<cstdio>

#include<algorithm>

#include<cmath>

using namespace std;

typedef long long ll;

const int maxn = 2e5 + 7;

int a[maxn];

int main(){

    int n;

    scanf("%d", &n);

    for(int i = 1; i <= n; ++i){

        scanf("%d", &a[i]);

        a[i] -= i;

    }

    sort(a+1, a+1+n);

    ll sum = 0;

    for(int i = 1; i <= n; ++i){

        sum += abs(a[i] - a[(n+1)/2]);

    }

    printf("%lld\n", sum);

}
// Slower C++ solution:
#include <bits/stdc++.h>

using namespace std;



int a[200050];



int main() {

	int n; scanf("%d", &n);

	for(int i = 0; i < n; i++) scanf("%d", a + i);

	for(int i = 0; i < n; i++) a[i] -= i + 1;

	sort(a, a + n);

	long long sum = 0, ps = 0, res;

	int t = -a[0];

	for(int i = 0; i < n; i++) a[i] += t;

	for(int i = 0; i < n; i++) sum += a[i];

	res = sum;

	for(int i = 0; i < n; i++) {

		int v = i ? a[i] - a[i - 1] : a[i];

		sum -= (long long)v * (n - i);

		ps += (long long)v * i;

		res = min(res, sum + ps);

	}

	printf("%lld\n", res);

	return 0;

}


// Faster C++ solution for the same problem (measured speedup: 5.163215044847239x):
#include<cstdio>

#include<algorithm>

#include<cmath>

using namespace std;

typedef long long ll;

const int maxn = 2e5 + 7;

int a[maxn];

int main(){

    int n;

    scanf("%d", &n);

    for(int i = 1; i <= n; ++i){

        scanf("%d", &a[i]);

        a[i] -= i;

    }

    sort(a+1, a+1+n);

    ll sum = 0;

    for(int i = 1; i <= n; ++i){

        sum += abs(a[i] - a[(n+1)/2]);

    }

    printf("%lld\n", sum);

}
// Slower C++ solution:
#include <bits/stdc++.h>

using namespace std;



#define loop(i,n) for(int i = 0;i < int(n);i++)

#define rloop(i,n) for(int i = int(n);i >= 0;i--)

#define range(i,a,b) for(int i = int(a);i <= int(b);i++)

#define SZ(c) int(c.size())

#define ALL(c) c.begin(), c.end()

#define RALL(c) c.rbegin(), c.rend()

#define PI acos(-1)

#define pb push_back

#define mp make_pair

#define fr first

#define sc second

#define sfi1(v) scanf("%d",&v)

#define sfi2(v1,v2) scanf("%d %d",&v1,&v2)

#define sfi3(v1,v2,v3) scanf("%d %d %d",&v1,&v2,&v3)

#define sfll1(v) scanf("%I64d",&v);

#define sfll2(v1,v2) scanf("%I64d %I64d",&v1,&v2)

#define sfll3(v1,v2,v3) scanf("%I64d %I64d %I64d",&v1,&v2,&v3)

#define endl '\n'



typedef vector<int> vi;

typedef vector<pair<int,int> > vii;

typedef long long ll;

typedef pair<int, int> pii;

const int N=2e5+5;

int a[N];





int main()

{



#ifndef ONLINE_JUDGE

	//freopen("in.in", "r", stdin);

	//freopen("out.in", "w", stdout);

#endif

	ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);

	int n;

	cin>>n;

	for(int i=0;i<n;i++)

        cin>>a[i],a[i]-=(i+1);

    sort(a,a+n);

    long long ans=0;

    for(int i=0;i<n;i++)

        ans+=abs(a[i]-a[n/2]);

    cout<<ans<<endl;

    return 0;

}


// Faster C++ solution for the same problem (measured speedup: 5.2898646991497715x):
#include<cstdio>

#include<algorithm>

#include<cmath>

using namespace std;

typedef long long ll;

const int maxn = 2e5 + 7;

int a[maxn];

int main(){

    int n;

    scanf("%d", &n);

    for(int i = 1; i <= n; ++i){

        scanf("%d", &a[i]);

        a[i] -= i;

    }

    sort(a+1, a+1+n);

    ll sum = 0;

    for(int i = 1; i <= n; ++i){

        sum += abs(a[i] - a[(n+1)/2]);

    }

    printf("%lld\n", sum);

}
// Slower C++ solution:
#include <bits/stdc++.h>

using namespace std;

#define N 200020

int i,j,k,m,n,x,y,a[N];

long long ans;

int main() {

    for (scanf("%d", &n), i = 0; i < n; ++i)scanf("%d", &a[i]), a[i] -= i + 1;

    sort(a, a + n);

    for (i = 0; i < n; ++i)ans += abs(a[i] - a[n >> 1]);

    cout << ans;

}

// Faster C++ solution for the same problem (measured speedup: 5.173515895076147x):
#include<cstdio>

#include<algorithm>

#include<cmath>

using namespace std;

typedef long long ll;

const int maxn = 2e5 + 7;

int a[maxn];

int main(){

    int n;

    scanf("%d", &n);

    for(int i = 1; i <= n; ++i){

        scanf("%d", &a[i]);

        a[i] -= i;

    }

    sort(a+1, a+1+n);

    ll sum = 0;

    for(int i = 1; i <= n; ++i){

        sum += abs(a[i] - a[(n+1)/2]);

    }

    printf("%lld\n", sum);

}
// Slower C++ solution:
#include<bits/stdc++.h>

using namespace std;

typedef long long ll;

const int MAXN=200005;

ll a[MAXN];

int main(){

	int n;

	scanf("%d",&n);

	for(ll i=1;i<=n;i++){

		scanf("%lld",&a[i]);

		a[i]-=i;

	}

	sort(a+1,a+n+1);

	ll mid=a[(n+1)>>1];

	ll ans=0;

	for(int i=1;i<=n;i++){

		ans+=abs(a[i]-mid);

	}

	printf("%lld\n",ans);

	return 0;

} 

// Faster C++ solution for the same problem (measured speedup: 5.16110261141736x):
#include<cstdio>

#include<algorithm>

#include<cmath>

using namespace std;

typedef long long ll;

const int maxn = 2e5 + 7;

int a[maxn];

int main(){

    int n;

    scanf("%d", &n);

    for(int i = 1; i <= n; ++i){

        scanf("%d", &a[i]);

        a[i] -= i;

    }

    sort(a+1, a+1+n);

    ll sum = 0;

    for(int i = 1; i <= n; ++i){

        sum += abs(a[i] - a[(n+1)/2]);

    }

    printf("%lld\n", sum);

}
// Slower C++ solution:
#include<iostream>

#include<cstdio>

#include<cstdlib>

#include<cmath>

#include<cstring>

#include<algorithm>

using namespace std;



int n;

int a[200005];

long long ans;

int main()

{

	int i;

	cin>>n;

	for(i=1;i<=n;i++)

		cin>>a[i],a[i]-=i;

	sort(a+1,a+1+n);

	for(i=1;i<=n;i++)

		ans+=abs(a[i]-a[(n+1)/2]);

	cout<<ans;

	return 0;

	

	

} 




// Faster C++ solution for the same problem (measured speedup: 5.215777702513314x):
#include<cstdio>

#include<algorithm>

#include<cmath>

using namespace std;

typedef long long ll;

const int maxn = 2e5 + 7;

int a[maxn];

int main(){

    int n;

    scanf("%d", &n);

    for(int i = 1; i <= n; ++i){

        scanf("%d", &a[i]);

        a[i] -= i;

    }

    sort(a+1, a+1+n);

    ll sum = 0;

    for(int i = 1; i <= n; ++i){

        sum += abs(a[i] - a[(n+1)/2]);

    }

    printf("%lld\n", sum);

}
// Slower C++ solution:
#include<bits/stdc++.h>

#define ll long long

using namespace std;

const int N=200005;



int a[N],n,num;

ll ans=0;



int main(){

	scanf("%d",&n);

	for(int i=1;i<=n;i++) {

		scanf("%d",a+i);

		a[i]-=i;

	}

	sort(a+1,a+n+1);

	num=a[(n+1)>>1];

	for(int i=1;i<=n;i++) 

		ans+=(ll)abs(num-a[i]);

	cout<<ans<<endl;

	return 0;

}

// Faster C++ solution for the same problem (measured speedup: 5.215982378186737x):
#include<cstdio>

#include<cstring>

#include<cmath>

#include<algorithm>

#include<queue>

#include<stack>

#include<vector>

#include<set>

using namespace std;

int n,a[200005],k;

long long int ans;

int main(){

	scanf("%d",&n);

	for(int i=1;i<=n;i++){

		scanf("%d",&a[i]);

		a[i]-=i;

	}

	sort(a+1,a+1+n);k=a[n/2+1];

	for(int i=1;i<=n;i++) ans+=(abs)(a[i]-k);

    printf("%lld",ans);

	return 0;

}
// Slower C++ solution:
#include<bits/stdc++.h>

#define ll long long

using namespace std;

const int N=200005;



int a[N],n,num;

ll ans=0;



int main(){

	scanf("%d",&n);

	for(int i=1;i<=n;i++) {

		scanf("%d",a+i);

		a[i]-=i;

	}

	sort(a+1,a+n+1);

	num=a[(n+1)>>1];

	for(int i=1;i<=n;i++) 

		ans+=(ll)abs(num-a[i]);

	cout<<ans<<endl;

	return 0;

}

// Faster C++ solution for the same problem (measured speedup: 5.286490184229462x):
#define _CRT_SECURE_NO_WARNINGS

#include <cstdio>

#include <cctype>

#include <ctime>

#include <algorithm>

#include <cmath>



int nextch(void)

{

    static char bufdatum[BUFSIZ];

    static char *buf = bufdatum, *endbuf = bufdatum;

    if (endbuf == buf)

    {

        endbuf = (buf = bufdatum) + fread(bufdatum, 1, BUFSIZ, stdin);

        if (endbuf == buf)

            return EOF;

    }

    return *buf++;

}



void legit(void) {}



template<typename Car, typename ...Cdr>

void legit(Car &var, Cdr &...Rest)

{

    int peek;

    while (!isdigit(peek = nextch())

#ifdef LEGIT_NEGI

        && peek != '-'

#endif  // LEGIT_NEGI

        )

        ;

#ifdef LEGIT_NEGI

    bool negi;

    if (peek == '-')

        negi = true;

    else

        negi = false;

#endif  // LEGIT_NEGI

    var = 0;

    do

        var = (((var << 2) + var) << 1) + (peek ^ '0');

    while (isdigit(peek = nextch()));

#ifdef LEGIT_NEGI

    if (negi)

        var = -var;

#endif  // LEGIT_NEGI

    legit(Rest...);

}



void solve(void);



int main(void)

{

#ifdef redirect

    freopen("check/data.in", "r", stdin);

    freopen("check/prog.out", "w", stdout);

    freopen("check/log.out", "w", stderr);

#endif  // redirect

#ifdef chrono

    auto begtm = clock();

#endif  // chrono

    solve();

#ifdef chrono

    auto endtm = clock();

    printf("%f\n", static_cast<float>(endtm - begtm) / CLOCKS_PER_SEC);

#endif  // chrono

    return 0;

}



typedef long long laolin;



const size_t MaxN = static_cast<size_t>(2e5) + 7;



size_t n;

laolin arr[MaxN];

laolin proced[MaxN];

bool negi[MaxN];

size_t neginum;



laolin abs(laolin n)

{

    return n < 0 ? -n : n;

}



void solve(void)

{

    legit(n);

    neginum = 0;

    for (size_t i = 0; i < n; ++i)

    {

        legit(arr[i]);

        proced[i] = arr[i] - i;

        if (proced[i] <= 0)

        {

            negi[i] = true;

            ++neginum;

        }

        else

            negi[i] = false;

    }

    std::sort(proced, proced + n);

    laolin mid = proced[n & 1 ? n / 2 : n / 2 - 1];

    laolin sum = 0;

    for (size_t i = 0; i < n; ++i)

        sum += abs(proced[i] - mid);

    printf("%lld\n", sum);

}
// Slower C++ solution:
#include<cmath>

#include<iostream>

#include<algorithm>

using namespace std;

long long k,a[200001],i,n,s=0;

int main()

{

	cin>>n;

	for(i=1;i<=n;i++) cin>>a[i],a[i]-=i;

	sort(a+1,a+1+n);

	k=a[(n+1)/2];

	for(i=1;i<=n;i++) s+=abs(k-a[i]);

	cout<<s;

	return 0;

}

// Faster C++ solution for the same problem (measured speedup: 5.2775380123784945x):
#define _CRT_SECURE_NO_WARNINGS

#include <cstdio>

#include <cctype>

#include <ctime>

#include <algorithm>

#include <cmath>



int nextch(void)

{

    static char bufdatum[BUFSIZ];

    static char *buf = bufdatum, *endbuf = bufdatum;

    if (endbuf == buf)

    {

        endbuf = (buf = bufdatum) + fread(bufdatum, 1, BUFSIZ, stdin);

        if (endbuf == buf)

            return EOF;

    }

    return *buf++;

}



void legit(void) {}



template<typename Car, typename ...Cdr>

void legit(Car &var, Cdr &...Rest)

{

    int peek;

    while (!isdigit(peek = nextch())

#ifdef LEGIT_NEGI

        && peek != '-'

#endif  // LEGIT_NEGI

        )

        ;

#ifdef LEGIT_NEGI

    bool negi;

    if (peek == '-')

        negi = true;

    else

        negi = false;

#endif  // LEGIT_NEGI

    var = 0;

    do

        var = (((var << 2) + var) << 1) + (peek ^ '0');

    while (isdigit(peek = nextch()));

#ifdef LEGIT_NEGI

    if (negi)

        var = -var;

#endif  // LEGIT_NEGI

    legit(Rest...);

}



void solve(void);



int main(void)

{

#ifdef redirect

    freopen("check/data.in", "r", stdin);

    freopen("check/prog.out", "w", stdout);

    freopen("check/log.out", "w", stderr);

#endif  // redirect

#ifdef chrono

    auto begtm = clock();

#endif  // chrono

    solve();

#ifdef chrono

    auto endtm = clock();

    printf("%f\n", static_cast<float>(endtm - begtm) / CLOCKS_PER_SEC);

#endif  // chrono

    return 0;

}



typedef long long laolin;



const size_t MaxN = static_cast<size_t>(2e5) + 7;



size_t n;

laolin arr[MaxN];

laolin proced[MaxN];

bool negi[MaxN];

size_t neginum;



laolin abs(laolin n)

{

    return n < 0 ? -n : n;

}



void solve(void)

{

    legit(n);

    neginum = 0;

    for (size_t i = 0; i < n; ++i)

    {

        legit(arr[i]);

        proced[i] = arr[i] - i;

        if (proced[i] <= 0)

        {

            negi[i] = true;

            ++neginum;

        }

        else

            negi[i] = false;

    }

    std::sort(proced, proced + n);

    laolin mid = proced[n & 1 ? n / 2 : n / 2 - 1];

    laolin sum = 0;

    for (size_t i = 0; i < n; ++i)

        sum += abs(proced[i] - mid);

    printf("%lld\n", sum);

}
// Slower C++ solution:
#include<bits/stdc++.h>

#define ll long long

using namespace std;

const int N=200005;



int a[N],n,num;

ll ans=0;



int main(){

	scanf("%d",&n);

	for(int i=1;i<=n;i++) {

		scanf("%d",a+i);

		a[i]-=i;

	}

	sort(a+1,a+n+1);

	num=a[(n+1)>>1];

	for(int i=1;i<=n;i++) 

		ans+=(ll)abs(num-a[i]);

	cout<<ans<<endl;

	return 0;

}

// Faster C++ solution for the same problem (measured speedup: 5.311634984375348x):
#include<cstdio>

#include<cstring>

#include<algorithm>

#define ll long long

#define MN 200005

using namespace std;

inline int in(){

    int x=0;bool f=0;char c;

    for (;(c=getchar())<'0'||c>'9';f=c=='-');

    for (x=c-'0';(c=getchar())>='0'&&c<='9';x=(x<<3)+(x<<1)+c-'0');

    return f?-x:x;

}

int a[MN],n,x;

ll res;

int main()

{

	n=in();

	for (int i=1;i<=n;++i) a[i]=in()-i;

	sort(a+1,a+n+1);x=a[(n+1)>>1];

	for (int i=1;i<=n;++i) res+=1ll*abs(a[i]-x);

	printf("%lld",res);return 0;

}