stablegradients/pie-gem5-bysrc huggingface dataset:
// Original C++ solution (slower):
#include<bits/stdc++.h>

using namespace std;

const int N=200005;

int a[N],n,num;

long long  ans=0;

int main(){

    cin>>n;

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

		{

			cin>>a[i];

			a[i]-=i;

		}

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

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

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

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

    cout<<ans<<endl;

    return 0;

}

// Optimized solution to the same problem (faster):
//------(▼皿▼#) fxxk vjudge-------

#include <algorithm>

#include <cstdio>



const int Maxv = 200010; 



int num[Maxv], n; 

long long ans; 



int main() {

    scanf("%d", &n); 

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

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

        num[i] -= i + 1; 

    }

    

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

    int tmp = num[(n >> 1)]; 



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

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



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



    return 0; 

}

// Fastest known solution for this problem:
// Original C++ solution (slower):
#include<bits/stdc++.h>

using namespace std;

typedef int Int;

#define int long long

#define INF 0x3f3f3f3f

#define maxn 200005

int a[maxn];

map<int,int>vis;

Int main()

{

    ios::sync_with_stdio(false);

    cin.tie(0);

    int n;

    cin>>n;

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

    {

        cin>>a[i];

        a[i]-=i;

        //cout<<a[i]<<' ';

        vis[a[i]]++;

    }

    //cout<<endl;

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

    int sum=0;

    int tmp=1;

    int val=0;

    if(n%2)

    {

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

    }

    else

    {

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

    }

   // cout<<val<<endl;

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

    {

        sum+=abs(a[i]-val);

    }

    cout<<sum<<endl;   

     return 0;

}

// Optimized solution to the same problem (faster):
//------(▼皿▼#) fxxk vjudge-------

#include <algorithm>

#include <cstdio>



const int Maxv = 200010; 



int num[Maxv], n; 

long long ans; 



int main() {

    scanf("%d", &n); 

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

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

        num[i] -= i + 1; 

    }

    

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

    int tmp = num[(n >> 1)]; 



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

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



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



    return 0; 

}

// Fastest known solution for this problem:
// Original C++ solution (slower):
#include<iostream>

#include<vector>

#include<algorithm>

using namespace std;

int main(){

	long long int a,b,i,d,res=0;

	

	cin>>a;

	vector<int> c(a);

	for(i=0;i<a;i++){

		cin>>c[i];

		c[i]-=i-100;

	}

	sort(c.begin(),c.end());

	b=c[a/2];

	for(i=0;i<a;i++)res+=abs(c[i]-b);

	cout<<res;

}

// Optimized solution to the same problem (faster):
//------(▼皿▼#) fxxk vjudge-------

#include <algorithm>

#include <cstdio>



const int Maxv = 200010; 



int num[Maxv], n; 

long long ans; 



int main() {

    scanf("%d", &n); 

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

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

        num[i] -= i + 1; 

    }

    

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

    int tmp = num[(n >> 1)]; 



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

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



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



    return 0; 

}

// Fastest known solution for this problem:
// Original C++ solution (slower):
////#include <bits/stdc++.h>

//#include <iostream>

//#include <algorithm>

//using namespace std;

//

//long long n,ans;

//int main() {

//    while(cin >> n) {

////          cout << __gcd(n,(long long)2) << endl;

//        if(__gcd((long long)2,n) == 1)

//            cout << (long long)2 * n << endl;

//        else {

//            cout << n << endl;

//

//        }

//    }

//    return 0;

//}

//#include <bits/stdc++.h>

//#include <iostream>

//#include <algorithm>

//using namespace std;

//

////long long n,ans;

//int n,x;

//int main() {

//    while(cin >> n) {

//            int Max = -99;

//            int Min = 2e9;

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

//                    cin >> x;

//                 Max = max(x,Max);

//                 Min = min(x,Min);

//            }

//            cout << Max - Min << endl;

//    }

//    return 0;

//}









#include <iostream>

#include <stdio.h>

#include <map>

#include <algorithm>

using namespace std;

const int Maxn = 2e5 + 100;

int n,x;

int a[Maxn];

map<int,int>m;

int main() {

    while(cin >> n) {

        m.clear();

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

            cin >> a[i];

        long long  ans = 0;

        int b = 0;

        int q = 1;

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

            a[i] -= q++;

            m[a[i]]++;

        }

        sort(a,a + n);

        int cnt = 0;

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

            if(a[i] == 0) continue;

            if(m[a[i]] && m[-a[i]])

                cnt++,m[a[i]]--,m[-a[i]]--;

        }

        int Max = 0;

        int data;

        if(cnt == n) b = 0;

        else {

            b = a[n / 2];

//            for(map<int,int>::iterator it = m.begin(); it != m.end(); it++)  {

////                if(it -> first == 0) continue;

//                if(Max < it -> second) {

//                    Max = it -> second;

//                    data = it -> first;

//                }

            }

//            b = data;

//        }

//        cout << b <<endl;

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

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

        }

        cout << ans << endl;

    }

    return 0;

}

 

// Optimized solution to the same problem (faster):
#include<cstdio>

#include<cmath>

#include<algorithm>

#include<cstring>

using namespace std;

long long n;

long long a[200005];

long long sum=0;

long long ans;

int main()

{

	scanf("%lld",&n);

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

	{

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

		a[i]-=i;

	}

	long long temp;

	if(n%2==1) temp=(n+1)/2;

	else temp=n/2; 

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

	ans=a[temp];

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

	{

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

	}

	printf("%lld",sum);

}

// Fastest known solution for this problem:
// Original C++ solution (slower):
#include <iostream>

#include <algorithm>



const int maxn = 2e5+7;



int main(int argc, char *argv[]) {  

	long long n, a[maxn];

	std::cin >> n;

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

		std::cin >> a[i];

		a[i] -= (i+1);

	}

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

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

	long long ans = 0;

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

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

	}

	std::cout << ans;

}

// Optimized solution to the same problem (faster):
#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);

}


// Fastest known solution for this problem:
// Original C++ solution (slower):
#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;

}


// Optimized solution to the same problem (faster):
#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);

}


// Fastest known solution for this problem:
// Original C++ solution (slower):
#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;

}




// Optimized solution to the same problem (faster):
#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);

}


// Fastest known solution for this problem:
// Original C++ solution (slower):
#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



*/

// Optimized solution to the same problem (faster):
#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);

}


// Fastest known solution for this problem:
// Original C++ solution (slower):
#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;

}




// Optimized solution to the same problem (faster):
#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);

}


// Fastest known solution for this problem:
// Original C++ solution (slower):
#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;

}

// Optimized solution to the same problem (faster):
#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);

}


// Fastest known solution for this problem:
// Original C++ solution (slower):
#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;

}


// Optimized solution to the same problem (faster):
#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);

}


// Fastest known solution for this problem:
// Original C++ solution (slower):
#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;

}

// Optimized solution to the same problem (faster):
#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);

}


// Fastest known solution for this problem:
// Original C++ solution (slower):
#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;

}


// Optimized solution to the same problem (faster):
#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);

}


// Fastest known solution for this problem:
// Original C++ solution (slower):
#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;

}


// Optimized solution to the same problem (faster):
#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);

}


// Fastest known solution for this problem:
// Original C++ solution (slower):
#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;

}


// Optimized solution to the same problem (faster):
#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);

}


// Fastest known solution for this problem:
// Original C++ solution (slower):
#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;

}

// Optimized solution to the same problem (faster):
#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);

}


// Fastest known solution for this problem:
// Original C++ solution (slower):
#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;

} 

// Optimized solution to the same problem (faster):
#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);

}


// Fastest known solution for this problem:
// Original C++ solution (slower):
#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;

	

	

} 




// Optimized solution to the same problem (faster):
#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);

}


// Fastest known solution for this problem: