#include <bits/stdc++.h>
#define endl '\n'
#define LL_MAX 0x7FFFFFFFFFFFFFFF
#define INF ((LL)1e12)
#define LL long long
#define PII pair<int,int>
#define all(V) (V).begin(),(V).end()
using namespace std;
const int MAXN = 3000;

int seq[MAXN+5];
LL dp[MAXN+5][MAXN+5];
map<int, int> cur;

int main() {
	ios_base::sync_with_stdio(0); cin.tie(0);
	int N;
	cin >> N;
	for (int i = 0; i < N; i++) {
		cin >> seq[i];
		seq[i] -= i;
	}
//	for (int i = 0; i < N; i++) cout << seq[i] << " "; cout << "\n";

	for (int i = 0; i < N; i++) {
		for (int j = 0; j < N; j++) {
			dp[i][j] = INF;
		}
	}

	dp[0][0] = 0;
	for (int i = 1; i < N; i++) {
		LL minv = INF;
		bool self = false;
		if (cur.find(seq[i - 1]) == cur.end()) {
			cur.insert({seq[i - 1], i - 1});
//			cout << "INSERT\n";
		}

		auto it = cur.begin();
		while (true) {
//			if (it != cur.end()) cout << i << " iter " << it->first << '\n';
			if (!self && (it == cur.end() || it->first > seq[i])) {
				self = true;
				if (minv == INF) {
					dp[i][i] = 0;
					for (int j = 0; j < i; j++) {
						if (seq[j] > seq[i]) {
							dp[i][i] += seq[j] - seq[i];
						}
					}
				}
				else {
					dp[i][i] = minv;
				}
			}

			if (it == cur.end()) break;
			minv = min(minv, dp[i - 1][it->second]);
			dp[i][it->second] = minv + abs(it->first - seq[i]);
//			cout << "Iterate " << i << " " << it->second << " " << minv << "\n";
			++it;
		}
	}

//	for (int i = 0; i < N; i++) {
//		for (int j = 0; j < N; j++) {
//			cout << dp[i][j] << " ";
//		}
//		cout << "\n";
//	}

	LL ans = INF;
	for (int i = 0; i < N; i++) {
		ans = min(ans, dp[N - 1][i]);
	}

	cout << ans << "\n";
	/**** Note MAXN ****/
}


#include <bits/stdc++.h>
#define endl '\n'
#define LL_MAX 0x7FFFFFFFFFFFFFFF
#define INF ((LL)1e12)
#define LL long long
#define PII pair<int,int>
#define all(V) (V).begin(),(V).end()
using namespace std;
const int MAXN = 3000;

int seq[MAXN+5];
LL dp[MAXN+5][MAXN+5];
map<int, int> cur;

int main() {
	ios_base::sync_with_stdio(0); cin.tie(0);
	int N;
	cin >> N;
	for (int i = 0; i < N; i++) {
		cin >> seq[i];
		seq[i] -= i;
	}
	for (int i = 0; i < N; i++) cout << seq[i] << " "; cout << "\n";

	for (int i = 0; i < N; i++) {
		for (int j = 0; j < N; j++) {
			dp[i][j] = INF;
		}
	}

	dp[0][0] = 0;
	for (int i = 1; i < N; i++) {
		LL minv = INF;
		bool self = false;
		if (cur.find(seq[i - 1]) == cur.end()) {
			cur.insert({seq[i - 1], i - 1});
//			cout << "INSERT\n";
		}

		auto it = cur.begin();
		while (true) {
//			if (it != cur.end()) cout << i << " iter " << it->first << '\n';
			if (!self && (it == cur.end() || it->first > seq[i])) {
				self = true;
				if (minv == INF) {
					dp[i][i] = 0;
					for (int j = 0; j < i; j++) {
						if (seq[j] > seq[i]) {
							dp[i][i] += seq[j] - seq[i];
						}
					}
				}
				else {
					dp[i][i] = minv;
				}
			}

			if (it == cur.end()) break;
			minv = min(minv, dp[i - 1][it->second]);
			dp[i][it->second] = minv + abs(it->first - seq[i]);
//			cout << "Iterate " << i << " " << it->second << " " << minv << "\n";
			++it;
		}
	}

//	for (int i = 0; i < N; i++) {
//		for (int j = 0; j < N; j++) {
//			cout << dp[i][j] << " ";
//		}
//		cout << "\n";
//	}

	LL ans = INF;
	for (int i = 0; i < N; i++) {
		ans = min(ans, dp[N - 1][i]);
	}

	cout << ans << "\n";
	/**** Note MAXN ****/
}


#include <bits/stdc++.h>
#define endl '\n'
#define LL_MAX 0x7FFFFFFFFFFFFFFF
#define INF ((LL)1e15)
#define LL long long
#define PII pair<int,int>
#define all(V) (V).begin(),(V).end()
using namespace std;
const int MAXN = 3000;

int seq[MAXN+5];
LL dp[MAXN+5][MAXN+5];
map<int, int> cur;

int main() {
	ios_base::sync_with_stdio(0); cin.tie(0);
	int N;
	cin >> N;
	for (int i = 0; i < N; i++) {
		cin >> seq[i];
		seq[i] -= i;
		if (cur.find(seq[i]) == cur.end()) {
			cur.insert({seq[i], i});
		}
	}
//	for (int i = 0; i < N; i++) cout << seq[i] << " "; cout << "\n";

	for (int i = 0; i < N; i++) {
		for (int j = 0; j < N; j++) {
			dp[i][j] = INF;
		}
	}
	for (int i = 0; i < N; i++) dp[0][i] = abs(seq[i] - seq[0]);

	for (int i = 1; i < N; i++) {
		LL minv = INF;
		bool self = false;
		auto it = cur.begin();
		while (it != cur.end()) {
			minv = min(minv, dp[i - 1][it->second]);
			dp[i][it->second] = minv + abs(it->first - seq[i]);
//			cout << "Iterate " << i << " " << it->second << " " << minv << "\n";
			++it;
		}
	}

//	for (int i = 0; i < N; i++) {
//		for (int j = 0; j < N; j++) {
//			cout << dp[i][j] << " ";
//		}
//		cout << "\n";
//	}

	LL ans = INF;
	for (int i = 0; i < N; i++) {
		ans = min(ans, dp[N - 1][i]);
	}

	cout << ans << "\n";
	/**** Note MAXN ****/
}


#include <bits/stdc++.h>
#define endl '\n'
#define LL_MAX 0x7FFFFFFFFFFFFFFF
#define INF ((LL)1e12)
#define LL long long
#define PII pair<int,int>
#define all(V) (V).begin(),(V).end()
using namespace std;
const int MAXN = 3000;

int seq[MAXN+5];
LL dp[MAXN+5][MAXN+5];
map<int, int> cur;

int main() {
	ios_base::sync_with_stdio(0); cin.tie(0);
	int N;
	cin >> N;
	for (int i = 0; i < N; i++) {
		cin >> seq[i];
		seq[i] -= i;
		if (cur.find(seq[i]) == cur.end()) {
			cur.insert({seq[i], i});
		}
	}
//	for (int i = 0; i < N; i++) cout << seq[i] << " "; cout << "\n";

	for (int i = 0; i < N; i++) {
		for (int j = 0; j < N; j++) {
			dp[i][j] = INF;
		}
	}
	for (int i = 0; i < N; i++) dp[0][i] = abs(seq[i] - seq[0]);

	for (int i = 1; i < N; i++) {
		LL minv = INF;
		bool self = false;
		auto it = cur.begin();
		while (it != cur.end()) {
			minv = min(minv, dp[i - 1][it->second]);
			dp[i][it->second] = minv + abs(it->first - seq[i]);
//			cout << "Iterate " << i << " " << it->second << " " << minv << "\n";
			++it;
		}
	}

//	for (int i = 0; i < N; i++) {
//		for (int j = 0; j < N; j++) {
//			cout << dp[i][j] << " ";
//		}
//		cout << "\n";
//	}

	LL ans = INF;
	for (int i = 0; i < N; i++) {
		ans = min(ans, dp[N - 1][i]);
	}

	cout << ans << "\n";
	/**** Note MAXN ****/
}


#include <iostream>
#include <algorithm>
using namespace std;

long long dp[5005];
long long v[5005],w[5005];

int main()
{
    long long n,i,j,j2,k,nr;
    cin>>n;
    for(i=1;i<=n;i++)
    {
        cin>>v[i]; v[i]-=i;
        w[i]=v[i];
    }
    sort(w+1,w+n+1);
    //dp[1]=abs(w[1]-v[1]);
    //for(j=2;j<=n;j++) dp[j]=min( abs(v[1]-w[j]), dp[j-1]);
    for(i=2;i<=n;i++)
    {
        dp[1]=abs(v[i]-w[1])+dp[1];
        for(j=2;j<=n;j++) dp[j]=min( dp[j-1], dp[j]+ abs(v[i]-w[j]) );
    }
    cout<<dp[n];
    return 0;
}


#include <iostream>
#include <algorithm>
using namespace std;

long long dp[5005];
long long v[5005],w[5005];

int main()
{
    long long n,i,j,j2,k,nr;
    cin>>n;
    for(i=1;i<=n;i++)
    {
        cin>>v[i]; v[i]-=i;
        w[i]=v[i];
    }
    sort(w+1,w+n+1);
    dp[1]=abs(w[1]-v[1]);
    for(j=2;j<=n;j++) dp[j]=min( abs(v[1]-w[j]), dp[j-1]);
    for(i=2;i<=n;i++)
    {
        dp[1]=abs(v[i]-w[1])+dp[1];
        for(j=2;j<=n;j++) dp[j]=min( dp[j-1], dp[j]+ abs(v[i]-w[j]) );
    }
    cout<<dp[n];
    return 0;
}


#include <iostream>
#include <algorithm>
using namespace std;

long long dp[5005];
long long v[5005],w[5005];

int main()
{
    long long n,i,j,j2,k,nr;
    cin>>n;
    for(i=1;i<=n;i++)
    {
        cin>>v[i]; v[i]-=i;
        w[i]=v[i];
    }
    sort(w+1,w+n+1);
    dp[1]=abs(w[1]-v[1]);
    for(j=2;j<=n;j++) dp[j]=min( abs(v[1]-w[j]), dp[j-1]);
    for(i=2;i<=n;i++)
    {
        dp[1]=abs(v[i]-w[1]);//+dp[1];
        for(j=2;j<=n;j++) dp[j]=min( dp[j-1], dp[j]+ abs(v[i]-w[j]) );
    }
    cout<<dp[n];
    return 0;
}


#include <stdio.h>
#include <algorithm>

using namespace std;

long long n,i,j,min1,rez,dp[3001][3001],x[3001],y[3001];
const long long INFLL=1000000000000000010ll;
int main()
{
	scanf("%d", &n);
	for (i=1; i<=n; i++)
    {
		scanf("%d",&x[i]);
		x[i]-= i;
		y[i]=x[i];
	}

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

	for (i=1; i<=n; i++)
		dp[1][i] = abs(x[1]- y[i]);

	for (i=2; i<=n; i++)
    {
		long long minn= INFLL;
		for(j=1; j<=n; j++)
		{
		    minn=min(minn,dp[i-1][j]);
			dp[i][j]=minn+abs(x[i]-y[j]);
		}
	}
	long long ans = INFLL;
	for (i=1; i<=n; i++)
		ans=min(ans,dp[n][i]);

	printf("%lld\n",ans);
	return 0;
}


#include <algorithm>
#include <cmathg
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <iostream>
#include <queue>
#include <utility>
#include <vector>
#define fs first
#define sc second
#define mp make_pair
#define Min(a, b) ((a) < (b) ? (a) : (b))
#define Max(a, b) ((a) > (b) ? (a) : (b))
#define ab(x) ((x) > 0 ? (x) : (-(x)))
#define Size(p) ((p) ? (p->size) : (0))
#define Dis(p) ((p) ? (p->dis) : (-1))
using namespace std;
typedef long long ll;
typedef long double ld;
typedef pair<int, int> pir;
void read(int &tmp) {
    char ch = getchar();
    tmp = 0;
    int sgn = 1;
    while (ch != EOF && (ch < '0' || ch > '9') && ch != '-') ch = getchar();
    if (ch == '-') sgn = -1, ch = getchar();
    while (ch != EOF && ch >= '0' && ch <= '9')
        tmp = tmp * 10 + ch - 48, ch = getchar();
    tmp *= sgn;
}
const int maxn = 1010000;
int n;
int a[maxn];
ll ans;
struct node {
    int key, dis, size;
    node *l, *r;
    void initial(int x) {
        key = x;
        dis = 0;
        size = 1;
        l = r = 0;
    }
} pool[maxn], *S = pool;
typedef pair<node *, int> PI;
PI Q[maxn];
int tot;
node *merge(node *x, node *y, bool ty)  // 0 smallest 1 biggest
{
    if (!x) return y;
    if (!y) return x;
    if (ty != x->key > y->key) {
        node *t = x;
        x = y;
        y = t;
    }
    x->r = merge(x->r, y, ty);
    x->size = Size(x->l) + Size(x->r) + 1;
    if (Dis(x->l) < Dis(x->r)) {
        node *t = x->l;
        x->l = x->r;
        x->r = t;
    }
    x->dis = Dis(x->r) + 1;
    return x;
}
PI Merge(PI x, PI y) {
    PI ans;
    ans.fs = merge(x.fs, y.fs, 1);
    ans.sc = x.sc + y.sc;
    while (Size(ans.fs) > ((ans.sc + 1) >> 1)) {
        ans.fs = merge((ans.fs)->l, (ans.fs)->r, 1);
    }
    return ans;
}
int main() {
    scanf("%d", &n);
    for (int i = 1; i <= n; i++) scanf("%d", &a[i]), a[i] -= i;
    ans = 0ll;
    for (int i = 1; i <= n; i++) {
        PI now;
        node *p = S++;
        p->initial(a[i]);
        now.fs = p;
        now.sc = 1;
        while (tot && (Q[tot].fs->key) > (now.fs->key)) {
            now = Merge(Q[tot--], now);
        }
        Q[++tot] = now;
    }
    int cur = 1;
    for (int i = 1; i <= tot; i++) {
        int ret = Q[i].fs->key;
        for (int j = 0; j < Q[i].sc; j++) ans += (ll)ab(ret - a[j + cur]);
        cur += Q[i].sc;
    }
    cout << ans << endl;
    return 0;
}


#include <algorithm>
#include <cstdio>
#include <cstring>
#include <iostream>
#include <queue>
#include <vector>
typedef long long LL;
int n, q, a, b;
LL minH, low, up, Lx, Rx;
using namespace std;
priority_queue<LL, vector<LL>, less<LL> > A;
priority_queue<LL, vector<LL>, greater<LL> > B;
int main() {
    scanf("%d", &n);
    q = 2e9;
    a = 1;
    b = 1e9;
    for (int i = 1; i <= n; i++) {
        int d;
        scanf("%d", &d);
        LL pos = d + 1e9;
        if (i == 1) {
            A.push(pos);
            B.push(pos);
        } else {
            low += a;
            up += b;
            Lx = low + A.top();
            Rx = up + B.top();
            if (pos < low + 1) minH += 1 + low - pos, pos = low + 1;
            if (pos < Lx) {
                A.pop();
                B.push(Lx - up);
                minH += Lx - pos;
                A.push(pos - low);
                A.push(pos - low);
            } else if (pos <= Rx) {
                A.push(pos - low);
                B.push(pos - up);
            } else {
                B.pop();
                A.push(Rx - low);
                minH += pos - Rx;
                B.push(pos - up);
                B.push(pos - up);
            }
        }
    }
    Lx = A.top() + low, Rx = B.top() + up;
    int slope = 1;
    if (Lx > q) {
        while (A.top() + low > q) {
            LL pos = A.top() + low;
            A.pop();
            if (A.empty() || A.top() + low <= q) {
                minH += slope * (pos - q);
                break;
            }
            minH += (LL)slope * (pos - low - A.top()), slope++;
        }
    } else if (Rx < low + 1) {
        while (B.top() + up < low + 1) {
            LL pos = B.top() + up;
            B.pop();
            if (B.empty() || B.top() + up >= low + 1) {
                minH += slope * (low - pos + 1);
                break;
            }
            minH += slope * (B.top() + up - pos), slope++;
        }
    }
    cout << minH << endl;
}


#include <algorithm>
#include <cstdio>
#include <cstring>
#include <iostream>
#include <queue>
#include <vector>
typedef long long LL;
int n;
LL q, a, b;
LL minH, low, up, Lx, Rx;
using namespace std;
priority_queue<LL, vector<LL>, less<LL> > A;
priority_queue<LL, vector<LL>, greater<LL> > B;
int main() {
    scanf("%d", &n);
    q = 2e9;
    a = 1;
    b = 2e9;
    for (int i = 1; i <= n; i++) {
        int d;
        scanf("%d", &d);
        LL pos = d + 1e9;
        if (i == 1) {
            A.push(pos);
            B.push(pos);
        } else {
            low += a;
            up += b;
            Lx = low + A.top();
            Rx = up + B.top();
            if (pos < low + 1) minH += 1 + low - pos, pos = low + 1;
            if (pos < Lx) {
                A.pop();
                B.push(Lx - up);
                minH += Lx - pos;
                A.push(pos - low);
                A.push(pos - low);
            } else if (pos <= Rx) {
                A.push(pos - low);
                B.push(pos - up);
            } else {
                B.pop();
                A.push(Rx - low);
                minH += pos - Rx;
                B.push(pos - up);
                B.push(pos - up);
            }
        }
    }
    Lx = A.top() + low, Rx = B.top() + up;
    int slope = 1;
    if (Lx > q) {
        while (A.top() + low > q) {
            LL pos = A.top() + low;
            A.pop();
            if (A.empty() || A.top() + low <= q) {
                minH += slope * (pos - q);
                break;
            }
            minH += (LL)slope * (pos - low - A.top()), slope++;
        }
    } else if (Rx < low + 1) {
        while (B.top() + up < low + 1) {
            LL pos = B.top() + up;
            B.pop();
            if (B.empty() || B.top() + up >= low + 1) {
                minH += slope * (low - pos + 1);
                break;
            }
            minH += slope * (B.top() + up - pos), slope++;
        }
    }
    cout << minH << endl;
}


#include <algorithm>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <iostream>
#include <queue>
#include <utility>
#include <vector>
#define fs first
#define sc second
#define mp make_pair
#define Min(a, b) ((a) < (b) ? (a) : (b))
#define Max(a, b) ((a) > (b) ? (a) : (b))
#define ab(x) ((x) > 0 ? (x) : (-(x)))
#define Size(p) ((p) ? (p->size) : (0))
#define Dis(p) ((p) ? (p->dis) : (-1))
using namespace std;
typedef long long ll;
typedef long double ld;
typedef pair<int, int> pir;
void read(int &tmp) {
    char ch = getchar();
    tmp = 0;
    int sgn = 1;
    while (ch != EOF && (ch < '0' || ch > '9') && ch != '-') ch = getchar();
    if (ch == '-') sgn = -1, ch = getchar();
    while (ch != EOF && ch >= '0' && ch <= '9')
        tmp = tmp * 10 + ch - 48, ch = getchar();
    tmp *= sgn;
}
const int maxn = 1010000;
int n;
int a[maxn];
ll ans;
struct node {
    int key, dis, size;
    node *l, *r;
    void initial(int x) {
        key = x;
        dis = 0;
        size = 1;
        l = r = 0;
    }
} pool[maxn], *S = pool;
typedef pair<node *, int> PI;
PI Q[maxn];
int tot;
node *merge(node *x, node *y, bool ty)  // 0 smallest 1 biggest
{
    if (!x) return y;
    if (!y) return x;
    if (ty != x->key > y->key) {
        node *t = x;
        x = y;
        y = t;
    }
    x->r = merge(x->r, y, ty);
    x->size = Size(x->l) + Size(x->r) + 1;
    if (Dis(x->l) < Dis(x->r)) {
        node *t = x->l;
        x->l = x->r;
        x->r = t;
    }
    x->dis = Dis(x->r) + 1;
    return x;
}
PI Merge(PI x, PI y) {
    PI ans;
    ans.fs = merge(x.fs, y.fs, 1);
    ans.sc = x.sc + y.sc;
    while (Size(ans.fs) > ((ans.sc + 1) >> 1)) {
        ans.fs = merge((ans.fs)->l, (ans.fs)->r, 1);
    }
    return ans;
}
int main() {
    scanf("%d", &n);
    for (int i = 1; i <= n; i++) scanf("%d", &a[i]), a[i] -= i;
    ans = 0ll;
    for (int i = 1; i <= n; i++) {
        PI now;
        node *p = S++;
        p->initial(a[i]);
        now.fs = p;
        now.sc = 1;
        while (tot && (Q[tot].fs->key) > (now.fs->key)) {
            now = Merge(Q[tot--], now);
        }
        Q[++tot] = now;
    }
    int cur = 1;
    for (int i = 1; i <= tot; i++) {
        int ret = Q[i].fs->key;
        for (int j = 0; j < Q[i].sc; j++) ans += (ll)ab(ret - a[j + cur]);
        cur += Q[i].sc;
    }
    cout << ans << endl;
    return 0;
}


#include <algorithm>
#include <cstdio>
#include <cstring>
#include <iostream>
#include <queue>
#include <vector>
typedef long long LL;
int n;
ll q, a, b;
LL minH, low, up, Lx, Rx;
using namespace std;
priority_queue<LL, vector<LL>, less<LL> > A;
priority_queue<LL, vector<LL>, greater<LL> > B;
int main() {
    scanf("%d", &n);
    q = 2e9;
    a = 1;
    b = 2e9;
    for (int i = 1; i <= n; i++) {
        int d;
        scanf("%d", &d);
        LL pos = d + 1e9;
        if (i == 1) {
            A.push(pos);
            B.push(pos);
        } else {
            low += a;
            up += b;
            Lx = low + A.top();
            Rx = up + B.top();
            if (pos < low + 1) minH += 1 + low - pos, pos = low + 1;
            if (pos < Lx) {
                A.pop();
                B.push(Lx - up);
                minH += Lx - pos;
                A.push(pos - low);
                A.push(pos - low);
            } else if (pos <= Rx) {
                A.push(pos - low);
                B.push(pos - up);
            } else {
                B.pop();
                A.push(Rx - low);
                minH += pos - Rx;
                B.push(pos - up);
                B.push(pos - up);
            }
        }
    }
    Lx = A.top() + low, Rx = B.top() + up;
    int slope = 1;
    if (Lx > q) {
        while (A.top() + low > q) {
            LL pos = A.top() + low;
            A.pop();
            if (A.empty() || A.top() + low <= q) {
                minH += slope * (pos - q);
                break;
            }
            minH += (LL)slope * (pos - low - A.top()), slope++;
        }
    } else if (Rx < low + 1) {
        while (B.top() + up < low + 1) {
            LL pos = B.top() + up;
            B.pop();
            if (B.empty() || B.top() + up >= low + 1) {
                minH += slope * (low - pos + 1);
                break;
            }
            minH += slope * (B.top() + up - pos), slope++;
        }
    }
    cout << minH << endl;
}


#include<iostream>
#include<cstdio>
#include<algorithm>
#include<cmath>
#include<cstring>
using namespace std;
long long a[3100],dp[3100][3100],n;
int main()
{
	memset(dp,0x3f3f3f3f,sizeof(dp));
	cin>>n;
	for(int i=1;i<=n;i++)
	{
		cin>>a[i];
		a[i]-=i;
	}
	dp[0][1]=0;
	for(int i=1;i<=n;i++)
	{
		long long minn=0x3f3f3f3f3f3f;
		for(int j=1;j<=n;j++)
		{
			minn=min(minn,dp[i-1][j]);
			dp[i][j]=minn+abs(a[i]-a[j]);
		}
	}
	long long minn=0x3f3f3f3f3f3f;
	for(int i=1;i<=n;i++)
	{
		minn=min(minn,dp[n][i]);
	}
	cout<<minn;
	return 0;
}


#include<bits/stdc++.h>
#define ll long long
using namespace std;
ll n,x,ans;
priority_queue<ll>q;
int main()
{
	cin>>n;
    for(int i=1;i<=n;i++)
    {
        cin>>x;

        x-=i;
        q.push(x);
        if(q.top()>x)
        {
            ans+=q.top()-x;
            q.pop();
            q.push(x);
        }
    }

    cout<<ans<<endl;
    return 0;
}


#include <bits/stdc++.h>
#define ri register int
using namespace std;
int n,ans;
priority_queue <int> q;
template <typename T> inline void read(T &x) {
	T c=getchar();
	for (; c<48||57<c; ) c=getchar();
	for (x=0; 48<=c&&c<=57; c=getchar()) x=(x<<3)+(x<<1)+(c^48);
}
template <typename T> inline void print(T x) {
	if (x>9) print(x/10);
	putchar(x%10|48);
}
signed main() {
	read(n);
	for (ri i=1,a; i<=n; ++i) {
		read(a),a-=i,q.push(a);
		if (a<q.top()) ans+=q.top()-a,q.pop(),q.push(a);
	}
	print(ans);
	return 0;
}


#include <cstdio>
#include <iostream>
#include <algorithm>
using namespace std;

const int N = 5000 + 7;

int n;
long long a[N], b[N];
long long f[2][N], g[2][N];

int main() {
	scanf("%d", &n);
	for (int i = 1; i <= n; ++i)
		scanf("%lld", a + i),
		b[i] = a[i];
	sort(b + 1, b + n + 1);
	for (int i = 1, k = 1; i <= n; ++i, k ^= 1) {
		g[k][0] = 1ll << 60;
		for (int j = 1; j <= n; ++j)
			f[k][j] = abs(a[i] - b[j]) + g[k ^ 1][j],
			g[k][j] = min(f[k][j], g[k][j - 1]);
	}
	printf("%lld", g[n & 1][n]);
	return 0;
}


//感谢hyl大佬与ypj老师的思路与指点
#include<iostream>
#include<cstdio>
#include<set>
#include<ctime>
#include<map>
#include<cstdlib>
#include<algorithm>
#include<queue>
#include<stack>
#include<string>
#include<cstring>
#include<cmath>
using namespace std;
long long dp[3005][3005],a[3005],b[3005];//dp[i][j]表示a前i个变为b的前j个时的最小操作次数.
int main()
{
	long long n,i,j,minn,ans=2e18;
    cin>>n;
    for(i=1;i<=n;i++)
    {
    	cin>>a[i];
    	a[i]-=i;//将a[i]减去一个上升的序列。使修改b[i]后a[i]严格上升。
    	b[i]=a[i];//用b[i]备份a[i]，准备离散化。
	}
	sort(b+1,b+n+1);//sort排一遍使b[i]严格不下降。
	for(i=1;i<=n;i++)
	{
		dp[1][i]=abs(a[1]-b[i]);//初始化,将a[1]变b[i]的操作次数记录下来.
	}
	for(i=2;i<=n;i++)//开始dp
	{
		minn=2e18;
		for(j=1;j<=n;j++)
		{
			minn=min(minn,dp[i-1][j]);
			dp[i][j]=minn+abs(a[i]-b[j]);
		}
	}
	for(i=1;i<=n;i++)
	{
		ans=min(ans,dp[n][i]);
	}
	cout<<ans;
	return 0;
}


#include<bits/stdc++.h>
#define reg register
#define ll long long
#define y1 liuifan_y1
#define inf 0x3f3f3f3f
#define iinf 0x3f3f3f3f3f3f3f3f
#define data liuyifan_data
#define next liuyifan_next
#define ture true
#define flase false
#define lowbit(x) x&(-x)
using namespace std;
ll n,x,ans;
priority_queue<ll>q;//STL堆(默认为大根堆)
int main()
{
    scanf("%d",&n);
    for(reg int i=1;i<=n-1;i++)
    {
        scanf("%lld",&x);
        x-=i;//预处理，将a[i]变成a[i]-i
        q.push(x);
        if(q.top()>x)
        {
            ans+=q.top()-x;//top:顶端
            q.pop();//pop:弹出
            q.push(x);//push:压入
        }
    }
    printf("%lld\n",ans);
    return 0;
}


#include<cstdio>
#include<iostream>
#include<cmath>
#include<algorithm>
#include<cstring>
#include<queue>
#include<map>
#include<bitset>
#include<vector>
using namespace std;
//#define int long long
#define re register int
inline int read(){
    int x=0,ff=1;char c=getchar();
    while(c<'0'||c>'9'){if(c=='-')ff=-1;c=getchar();}
    while(c>='0'&&c<='9'){x=(x<<1)+(x<<3)+(c^48);c=getchar();}
    return x*ff;
}
int n,a[3005],c[3005],f[2][3005],mx[2][3005];
signed main(){
//	freopen("tree.in","r",stdin);freopen("tree.out","w",stdout);
	n=read();
	for(re i=1;i<=n;i++)a[i]=read(),a[i]-=i,c[i]=a[i];
	sort(a+1,a+n+1);mx[0][0]=2e9;mx[1][0]=2e9;
	for(re i=1;i<=n;i++){
		for(re j=1;j<=n;j++){
			f[i%2][j]=mx[(i%2)^1][j]+abs(a[j]-c[i]);
			mx[i%2][j]=min(mx[i%2][j-1],f[i%2][j]);
		}
	}
	cout<<mx[n%2][n]<<endl;
	return 0;
}


#include <bits/stdc++.h>
//#pragma GCC optimize(2)
//#pragma GCC optimize(3,"Ofast","inline")
using namespace std;
int main()
{
  priority_queue<long long>que;
  long long a,n,ans=0;
  cin>>n;
  while(n--)
  {
    cin>>a;
    que.push(a);
    if(a<que.top())
    {
      ans=ans+que.top()-a;
      que.pop();
      que.push(a);
    }
  }
  cout<<ans<<endl;
  return 0;
}


#include<bits/stdc++.h>
#define ll long long
using namespace std;
ll a,n,a1[3010],a2[3010],dp[3010][3010],ans=1e20;
int main(){
//	freopen(".in","r",stdin);
//	freopen(".out","w",stdout);
	scanf("%lld",&n);
	for(ll i=1;i<=n;i++){
		scanf("%lld",&a);
		a1[i]=a-i;
		a2[i]=a1[i];
	}
	sort(a2+1,a2+1+n);
	for(ll i=1;i<=n;i++){
		a=1e20;
		for(ll j=1;j<=n;j++){
			a=min(a,dp[i-1][j]);
			dp[i][j]=a+abs(a1[i]-a2[j]);
			if(i==n){
				ans=min(ans,dp[i][j]);
			}
		}
	}
	printf("%lld",ans);
//	fclose(stdin);
//	fclose(stdout);
	return 0;
}
/*

*/


#include<cstdio>
#include<iostream>
#include<cmath>
#include<algorithm>
#include<cstring>
#include<queue>
#include<map>
#include<bitset>
#include<vector>
using namespace std;
//#define int long long
#define re register int
inline int read(){
    int x=0,ff=1;char c=getchar();
    while(c<'0'||c>'9'){if(c=='-')ff=-1;c=getchar();}
    while(c>='0'&&c<='9'){x=(x<<1)+(x<<3)+(c^48);c=getchar();}
    return x*ff;
}
int n,a[3005],c[3005];
long long f[2][3005],mx[2][3005];
signed main(){
//	freopen("tree.in","r",stdin);freopen("tree.out","w",stdout);
	n=read();
	for(re i=1;i<=n;i++)a[i]=read(),a[i]-=i,c[i]=a[i];
	sort(a+1,a+n+1);mx[0][0]=2e9;mx[1][0]=2e9;
	for(re i=1;i<=n;i++){
		for(re j=1;j<=n;j++){
			f[i%2][j]=mx[(i%2)^1][j]+abs(a[j]-c[i]);
			mx[i%2][j]=min(mx[i%2][j-1],f[i%2][j]);
		}
	}
	cout<<mx[n%2][n]<<endl;
	return 0;
}


#include<bits/stdc++.h>
using namespace std;
long long n,x,ans;
priority_queue<long long>q;
int main()
{
    cin>>n;
    for(int i=1;i<n;i++)
	{
        scanf("%lld",&x);
        x-=i;
        q.push(x);
        if(q.top()>x)
		{
            ans+=q.top()-x;
            q.pop();
            q.push(x);
        }
    }
    cout<<ans;
    return 0;
}


#include <iostream>
#include <cstdio>
#include <algorithm>
#include <cmath>
#include <string.h>
#include <queue>
#include <vector>
#include <set>
#include <cctype>
#include <cstdlib>
#include <time.h>
#include <map>
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;
#define mp make_pair
inline ll read(){
	ll x = 0; char ch = getchar(); bool positive = 1;
	for (; !isdigit(ch); ch = getchar())	if (ch == '-')	positive = 0;
	for (; isdigit(ch); ch = getchar())	x = x * 10 + ch - '0';
	return positive ? x : -x;
}
inline void write(ll a){
    if(a<0){
    	a=-a; putchar('-');
	}
    if(a>=10)write(a/10);
    putchar('0'+a%10);
}
int rnd(int mod){
	unsigned long long ans=0;
	for(int i=0;i<5;i++)ans=ans<<15^rand();
	return ans%(mod-1)+1;
}
const int maxn=1e5+10;
const int inf=0x3f3f3f3f;
int n;
typedef pair<int,int>pll;
ll dp[3010][3010];
ll a[maxn];
ll b[maxn];
int main() {
	memset(dp,0,sizeof(dp));
	n=read();
	for(int i=1;i<=n;i++){
		a[i]=read();
		//sum+=a[i];
		a[i]-=i;
		//num.push_back(a[i]);
		b[i]=a[i];
	}
	sort(b+1,b+n+1);
	for(int i=1;i<=n;i++) {
		dp[i][1]=dp[i-1][1]+abs(a[i]-b[1]);
		for(int j=2;j<=n;j++) {
			dp[i][j]=min(dp[i][j-1],dp[i-1][j]+abs(a[i]-b[j]));
		}
	}
	cout<<dp[n][n]<<endl;
	return 0;
}


#include<iostream>
#include<cstring>
#include<cstdio>
#include<cmath>
#include<algorithm>
using namespace std;
#define int long long
const int INF=1e14;
const int N=2122;
int n,a[N],dp[N][N],mn[N][N],b[N];
int read(){
	int sum=0,f=1;char ch=getchar();
	while(ch<'0'||ch>'9'){if(ch=='-')f=-1;ch=getchar();}
	while(ch>='0'&&ch<='9'){sum=sum*10+ch-'0';ch=getchar();}
	return sum*f;
}
signed main(){
	n=read();
	for(int i=1;i<=n;i++)a[i]=read()-i,b[i]=a[i];;
	sort(b+1,b+1+n);
	for(int i=1;i<=n;i++){
		mn[i][0]=INF;
		for(int j=1;j<=n;j++){
			dp[i][j]=abs(a[i]-b[j])+mn[i-1][j];
			mn[i][j]=min(mn[i][j-1],dp[i][j]);
		}
	}
	printf("%lld",mn[n][n]);
	return 0;
}


#include<iostream>
#include<iomanip>
#include<cstdio>
#include<cstring>
#include<algorithm>
#include<cmath>
#include<queue>
#define ll long long
using namespace std;
ll n,a[3100],dp[3100][3100],s[3100],minx;
int main()
{
	scanf("%lld",&n);
	for(ll i=1;i<=n;i++)
	{
		scanf("%lld",&s[i]);
		s[i]-=i;
		a[i]=s[i];
	}
	sort(s+1,s+n+1);
	for(ll i=1;i<=n;i++)
		for(ll j=1;j<=n;j++)
			dp[i][j]=1e18;
	dp[0][1]=0;
	for(ll i=1;i<=n;i++)
	{
		minx=1e18;
		for(ll j=1;j<=n;j++)
		{
			minx=min(minx,dp[i-1][j]);
			dp[i][j]=minx+abs(a[i]-s[j]);
		}
	}
	minx=1e18;
	for(ll i=1;i<=n;i++)minx=min(minx,dp[n][i]);
	printf("%lld",minx);
	return 0;
}


#include<cstdio>
#include<queue>
using namespace std;
priority_queue<long long>q;
int main(){
	int n;
	long long ans=0;
	scanf("%d",&n);
    for(int i = 1; i <= n; i++) {
        long long num;
        scanf("%lld",&num);
		num-=i;
        q.push(num);
        if(num < q.top()) {
            ans += q.top() - num;
            q.pop();
            q.push(num);
        }
    }
    printf("%lld\n", ans);
}


#include<bits/stdc++.h>
#define ll long long
#define N 3010
using namespace std;

ll n,ans;
priority_queue<ll>pq;

int main()
{
    ll i,j,t;
    cin>>n;
    for(i=1;i<=n;i++)
    {
	scanf("%lld",&t);t-=i;
	pq.push(t);
	if(pq.top()>t)
	{
	    ans+=pq.top()-t;
	    pq.pop();
	    pq.push(t);
	}
    }
    cout<<ans;
}


#include<iostream>
#include<cstdio>
#include<cmath>
#include<cstring>
#include<algorithm>
using namespace std;
long long n,p[3003],a[3003],opt[3003][3002],minn;
int main()
{
	cin>>n;
	for(int i=1;i<=n;i++)
	{
		cin>>a[i];
		a[i]-=i;
		p[i]=a[i];
	}
	sort(p+1,p+1+n);
	for(int i=1;i<=n;i++)
	{
		minn=1e9;
		for(int j=1;j<=n;j++)
		{
			minn=min(minn,opt[i-1][j]);
			opt[i][j]=minn+abs(a[i]-p[j]);
		}
	}
	long long ans=1e9;
	for(int i=1;i<=n;i++)
	ans=min(ans,opt[n][i]);
	cout<<ans;
	return 0;
}


#include<bits/stdc++.h>
using namespace std;
long long n,m,dp[3010][3010],a[3010],re[3010];
int main ( )
{
	scanf("%lld",&n);
	for(long long i=1;i<=n;i++)
	{
		scanf("%lld",&a[i]);
		a[i]-=i;
		re[i]=a[i];
	}
	sort(a+1,a+n+1);
	memset(dp,0x3f3f3f3f,sizeof(dp));
	dp[0][1]=0;
	for(long long i=1;i<=n;i++)
	{
		long long mina=999999999;
		for(long long j=1;j<=n;j++)
		{
			mina=min(mina,dp[i-1][j]);
			dp[i][j]=mina+abs(re[i]-a[j]);
		}
	}
	long long minn=0x3f3f3f3f3f3f;
	for(long long i=1;i<=n;i++)
	minn=min(minn,dp[n][i]);
	cout<<minn;
	return 0 ;
}


#include <bits/stdc++.h>
#define int long long
using namespace std;
const int N=3e3+5;
int n,tot,ans;
int a[N],b[N],f[N][N];
signed main(){
	scanf("%lld",&n);
	for (register int i=1; i<=n; ++i) scanf("%lld",&a[i]),a[i]-=i,b[i]=a[i];
	sort(b+1,b+n+1);
	tot=unique(b+1,b+n+1)-b-1;
	memset(f,60,sizeof(f));
	for (register int i=1; i<=tot; ++i) f[1][i]=abs(a[1]-b[i]);
	for (register int i=2; i<=n; ++i)
	for (register int j=1; j<=tot; ++j)
	f[i][j]=min(f[i][j-1],f[i-1][j]+abs(a[i]-b[j]));
	printf("%lld\n",f[n][tot]);
return 0;
}


#include<bits/stdc++.h>
using namespace std;

#define I inline
#define ri register int
#define ll long long
#define int long long
#define ull unsigned long long
#define min(a,b) ((a)<(b)?(a):(b))
#define max(a,b) ((a)>(b)?(a):(b))
#define rep(i,a,b) for(ri i=(a);i<=(b);++i)
#define dow(i,a,b) for(ri i=(a);i>=(b);--i)
#define go(i,u) for(ri i=lnk[u];i;i=nxt[i])
#define pii pair<int,int>
#define mp make_pair
#define fi first
#define se second
#define vec vector
#define que queue
#define pb push_back
#define lowbit(x) (x&(-x))
#define mem(f,x) memset(f,x,sizeof(f))

I int gi(){
	int x=0,f=0;char ch=getchar();
	while(!isdigit(ch)){f|=ch=='-',ch=getchar();}
	while(isdigit(ch)){x=x*10+ch-48,ch=getchar();}
	return f?-x:x;
}

I void pi(int x){
	if(x<0)putchar('-'),x=-x;
	if(x>9)pi(x/10);
	putchar(x%10+48);
}
I void pib(int x){pi(x);putchar(' ');}
I void pin(int x){pi(x);putchar('\n');}

const int N = 3e3+5,inf = 1e18+5;

int f[N][N],g[N][N],a[N],n,b[N];

signed main(){

	n=gi();
	rep(i,1,n)a[i]=gi()-i,b[i]=a[i];
	sort(b+1,b+n+1);
	mem(f,0x3f);mem(g,0x3f);
	rep(i,1,n)f[0][i]=g[0][i]=0;
	rep(i,1,n){
		rep(j,1,n){
			f[i][j]=min(f[i][j],g[i-1][j]+abs(a[i]-b[j]));
			g[i][j]=min(g[i][j-1],f[i][j]);
		}
	}
	int ans=inf;
	rep(i,1,n)ans=min(ans,f[n][i]);
	pin(ans);
	return 0;
}


#include<bits/stdc++.h>
using namespace std;
int main()
{
	long long a,b,c,d,x;
	long long dp[1001][1001]={};
	long long n[1001]={},m[1001]={},minn=1e18,poi=1e18;
	cin>>x;
	for(a=1;a<=x;a++)
		{
			cin>>n[a];
			m[a]=n[a];
		}
	for(a=1;a<=x;a++)
		{
			n[a]-=a;
		}
	sort(n+1,n+x+1);
	for(a=1;a<=x;a++)
		{
			minn=1e18;
			for(b=1;b<=x;b++)
			{
				minn=min(minn,dp[a][b]);
				dp[a][b]=minn+abs(n[a]-m[b]);
			}
		}
	for(a=1;a<=x;a++)
		poi=min(dp[x][a]);
	cout<<poi;
	return 0;
}


#include <bits/stdc++.h>
using namespace std;
const int maxn = 3005;
int a[maxn]{0}, b[maxn]{0}, f[maxn][maxn]{0};
int main(void) {
    int n;
    while (cin >> n) {
        memset(a,0,sizeof a);
        memset(b,0,sizeof b);
        memset(f,0,sizeof f);
        for (int i = 1; i <= n; ++i) {
            cin >> a[i];
            a[i] -= i, b[i] = a[i];
        }
        sort(b + 1, b + 1 + n);
        int m = unique(b + 1, b + 1 + n) - b - 1;
        for (int i = 1; i <= n; ++i) {
            int t = 0x3f3f3f3f;
            for (int j = 1; j <= m; ++j) {
                t = min(t, f[i - 1][j]);
                f[i][j] = t + abs(a[i] - b[j]);
            }
        }
        int ans = 0x3f3f3f3f;
        for (int i = 1; i <= n; ++i) ans = min(ans, f[n][i]);
        printf("%d\n", ans);
    }
    return 0;
}


#include <cstdio>
#include <queue>

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

int n;
std::priority_queue<int> Q;

int main(){
	n=read(); long long y=0;
	for(int i=1;i<=n;++i){
		int x=read()-i; Q.push(x);
		if(x<Q.top()) y+=Q.top()-x,Q.pop(),Q.push(x);
	}
	printf("%lld\n",y); return 0;
}


#include<iostream>
#include<cstdio>
#include<algorithm>
#include<cmath>
#define int long long

using namespace std;

const int N = 3005;

int f[N][N];
int a[N];
int b[N];
int n;

int work(){
	for(int i=1;i<=n;i++) b[i] = a[i];
	sort(b+1,b+1+n);
	for(int i=1;i<=n;i++){
		int minn = 0x3f3f3f3f;
		for(int j=1;j<=n;j++){
			minn = min(minn,f[i-1][j]);
			f[i][j] = minn+abs(a[i]-b[j]);
		}
	}
	int res = 0x3f3f3f3f;
	for(int i=1;i<=n;i++) res = min(res,f[n][i]);
	return res;
}

 main(){
	cin>>n;
	for(int i=1;i<=n;i++) cin>>a[i],a[i]-=i;
	int t1 = work();
	cout<<t1;
	return 0;
}


#include<bits/stdc++.h>
using namespace std;
#define rg register
#define rep(i,a,b) for (rg int i=a;i<=b;i++)
#define per(i,a,b) for (rg int i=b;i>=a;i--)
#define pb push_back
#define lowbit(x) (x&(-x))
#define mk make_pair
#define VI vector<int>
#define il inline
#define ll long long
#define db double
#define ld long double
#define inf 0x3f3f3f3f3f3f
#define getc() (p1==p2&&(p2=(p1=buf)+fread(buf,1,1<<15,stdin),p1==p2)?EOF:*p1++)
char buf[1<<15],*p1 = buf,*p2 = buf;
inline ll read(){
    #define num ch-'0'
    char ch;bool flag=0;ll res;
    while(!isdigit(ch=getc()))
    (ch=='-')&&(flag=true);
    for(res=num;isdigit(ch=getc());res=res*10ll+num);
    (flag)&&(res=-res);
    #undef num
    return res;
}
inline void write(ll x){
	if (x < 0) x = ~x + 1ll, putchar('-');
	if (x > 9) write(x / 10ll);
	putchar(x % 10ll + '0');
}
#define mid ((l + r)>>1)
#define ls (x<<1)
#define rs ((x<<1)|1)
#undef mid
#undef ls
#undef rs
#define maxn 3030
ll dp[maxn][maxn];
ll a[maxn],b[maxn];
void solve()
{
	int n = read();
	rep(i,1,n) b[i] = a[i] = read() - i;
	sort(b+1,b+1+n);
	rep(i,1,n)
	{
		ll mn = inf;
		rep(j,1,n)
		{
			dp[i][j] = (mn=min(mn,dp[i-1][j])) + abs(a[i]-b[j]);
		}
	}
	ll ans = inf;
	rep(i,1,n) ans = min(ans,dp[n][i]);
	cout<<ans;
}
int main()
{
	#ifndef ONLINE_JUDGE
	freopen("data.txt","r",stdin);
	#endif
//	int T = read();
//	while(T--)
	solve();
}


#include<bits/stdc++.h>
using namespace std;
priority_queue<int> q;
int n,x;long long ans;
signed main(){
	cin>>n;
	while(n--){
		cin>>x;q.push(x);
		if(x<q.top()){
			ans+=q.top()-x;
			q.pop();q.push(x);
		}
	}
	printf("%lld\n",ans);
	return 0;
}


#include<cstdio>
#include<iostream>
#include<algorithm>
#include<cstring>
#include<vector>
#include<queue>
#include<cmath>
using namespace std;
const int MAXN=100000+7;
priority_queue<int> q;
int ans,a[MAXN];
int main(){
	int n,x; scanf("%d",&n);
	for(int i=1;i<=n;i++) scanf("%d",&a[i]);
	x=a[1]; q.push(x);
	for(int i=1;i<n;i++){
		x=a[i+1]; x-=i;
		q.push(x);
		if(q.top()>x){
			ans+=q.top()-x;
			q.pop(); q.push(x);
		}
	}
	int res=ans; //ans=0;
	//
	/*
	while(!q.empty()) q.pop();
	for(int i=1;i<=(n>>1);i++) swap(a[i],a[n-i+1]);
	x=a[1]; q.push(x);
	for(int i=1;i<n;i++){
		x=a[i+1];
		q.push(x);
		if(q.top()>x){
			ans+=q.top()-x;
			q.pop(); q.push(x);
		}
	}
	*/
	printf("%d\n",min(ans,res));
	return 0;
}


#include<bits/stdc++.h>

using namespace std;

#define int long long

const int kMaxN = 3000 + 5;

int n , ans , a[kMaxN];

priority_queue <int> Q;

inline int read(){
	int s = 0 , w = 1;
	char ch = getchar();
	while((ch < '0') || (ch > '9')){
		if(ch == '-'){
			w = -1;
		}
		ch = getchar();
    }
   	while((ch >= '0') && (ch <= '9')){
   		s = (s << 3) + (s << 1) + ch - '0';
		ch = getchar();
	}
   	return s * w;
}

inline void write(int x){
    if(x < 0){
        putchar('-');
        x = -x;
    }
    if(x > 9){
    	write(x / 10);
	}
    putchar(x % 10 + '0');
    return ;
}

signed main(){

    n = read();

    for(int i = 1 ; i <= n ; i++ ){
        a[i] = read();
        Q.push(a[i]);
        if(a[i] < Q.top()){
        	ans += Q.top() - a[i];
        	Q.pop();
        	Q.push(a[i]);
		}
    }

    cout << ans << endl;

    return 0;
}


#include <bits/stdc++.h>
using namespace std;
int n,x;
long long ans;
priority_queue<int> q;
int main(){
    scanf("%d",&n);
    for(int i=1;i<=n;i++){
        scanf("%d",&x);
        x-=i;
        q.push(x);
        if(q.top()>x){
            ans+=q.top()-x;
            q.pop();
            q.push(x);
        }
    }
    printf("%lld\n",ans);
    return 0;
}


#include<bits/stdc++.h>
using namespace std;
long long dp[1001][1001]={};
int main()
{
	long long a,b,c,d,x;

	long long n[1001]={},m[1001]={},minn=1e18,poi=1e18;
	cin>>x;
	for(a=1;a<=x;a++)
		{
			cin>>n[a];
			m[a]=n[a];
		}
	for(a=1;a<=x;a++)
		{
			n[a]-=a;
		}
	sort(n+1,n+x+1);
	for(a=1;a<=x;a++)
		{
			minn=1e18;
			for(b=1;b<=x;b++)
			{
				minn=min(minn,dp[a][b]);
				dp[a][b]=minn+abs(n[a]-m[b]);
			}
		}
	for(a=1;a<=x;a++)
		poi=min(dp[x][a],poi);
	cout<<poi;
	return 0;
}


/*#pragma comment(linker, "/stack:200000000")
#pragma GCC optimize("Ofast")
#pragma target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")*/
#include<iostream>
#include<cstdio>
#include<cmath>
#include<map>
#include<queue>
#include<string>
#include<cstring>
#include<vector>
#include<set>
#include<algorithm>
#include<cctype>
#define ll long long
#define inf 1000000005
#define mod1 1000000007
#define mod2 998244353
#define put putchar('\n')
#define F(i,a,b) for (int i=(a);i<=(b);i++)
#define D(i,a,b) for (int i=(a);i>=(b);i--)
#define R(i,a,b) for (int i=(a);i<(b);i++)
#define go(i,t) for (int i=head[t];i;i=Next[i])
#define sqr(x) ((x)*(x))
#define pb push_back
#define be begin()
#define en end()
#define ret return puts("-1"),0;
#define N 500055
#define int ll
using namespace std;
inline char gc(){
    static char buf[100000],*p1=buf,*p2=buf;
    return p1==p2&&(p2=(p1=buf)+fread(buf,1,100000,stdin),p1==p2)?EOF:*p1++;
}
#define gc getchar
inline int read(){char c=getchar();int tot=1;while ((c<'0'|| c>'9')&&c!='-') c=getchar();if (c=='-'){tot=-1;c=getchar();}
int sum=0;while (c>='0'&&c<='9'){sum=sum*10+c-'0';c=getchar();}return sum*tot;}
inline void wr(int x){if (x<0) {putchar('-');wr(-x);return;}if(x>=10)wr(x/10);putchar(x%10+'0');}
inline void wrn(int x){wr(x);put;}inline void wri(int x){wr(x);putchar(' ');}
inline void wrn(int x,int y){wri(x);wrn(y);}inline void wrn(int a,int b,int c){wri(a);wrn(b,c);}
int n,m,ans;
int a[3010],b[3010];
int dp[101][101];
signed main(){
	n=read();
	for(int i=1;i<=n;i++)
	{
		a[i]=read();
		a[i]-=i;
		b[i]=a[i];
	}
	sort(b+1,b+n+1);
	for(int i=1;i<=n;i++)
	{
		dp[i][1]=dp[i-1][1]+abs(a[i]-b[1]);
		for(int j=2;j<=n;j++)
			dp[i][j]=min(dp[i][j-1],dp[i-1][j]+abs(a[i]-b[j]));
	}
	cout<<dp[n][n]<<endl;
	return 0;
}


#include<bits/stdc++.h>
using namespace std;
priority_queue<long long>q;
long long n,x,ans;
int main()
{
    cin>>n;
    for(long long  i=1;i<=n-1;i++)
	{
        cin>>x;
        x=x-i;
        q.push(x);
        if(q.top()>x)
		ans+=q.top()-x,q.pop(),q.push(x);

    }
    cout<<ans;
    return 0;
}


#include<iostream>
#include<cstdio>
#include<algorithm>
#include<cmath>
#include<cstring>
using namespace std;
int a[3100],read[3100],l,dp[3100][3100],n;
int main()
{
	memset(dp,0x3f3f3f3f,sizeof(dp));
	cin>>n;
	for(int i=1;i<=n;i++)
	{
		cin>>read[i];
		read[i]-=i;
		a[i]=read[i];
	}
	sort(read+1,read+n+1);
	l=unique(read+1,read+n+1)-read-1;
	dp[0][1]=0;
	for(int i=1;i<=n;i++)
	{
		int minn=0x3f3f3f3f3f;
		for(int j=1;j<=l;j++)
		{
			minn=min(minn,dp[i-1][j]);
			dp[i][j]=minn+abs(a[i]-read[j]);
		}
	}
	int minn=0x3f3f3f3f3f;
	for(int i=1;i<=l;i++)
	{
		minn=min(minn,dp[n][i]);
	}
	cout<<minn;
	return 0;
}


#include <iostream>
#include <cstdio>
#include <cctype>
#include <queue>
#define il inline
#define vd void
#define rg register
#define ll long long
#define rep(i,x,y) for(rg int i=x;i<=y;++i)
#define drp(i,x,y) for(rg int i=x;i>=y;--i)
using namespace std;
const int Len=2333333;
char buf[Len],*p1=buf,*p2=buf,duf[Len],*q1=duf;
il char gc(); il int rd(); il vd pc(char c); il vd rt(ll x); il vd flush();
int n,x;
ll ans;
priority_queue <int> q;
int main(){
	n=rd();
	rep(i,1,n){
		x=rd()-i,q.push(x);
		if(!q.empty()&&q.top()>x) ans+=q.top()-x,q.pop(),q.push(x);
	}
	rt(ans);
	return flush(),0;
}

il char gc(){return p1==p2&&(p2=(p1=buf)+fread(buf,1,Len,stdin),p1==p2)?-1:*p1++;}
il int rd(){char c;
	while(!isdigit(c=gc())&&c!='-');
	int f=c=='-'?c=gc(),1:0,x=c^48;
	while(isdigit(c=gc())) x=((x+(x<<2))<<1)+(c^48);
	return f?-x:x;
}
il vd pc(char c){q1==duf+Len&&fwrite(q1=duf,1,Len,stdout),*q1++=c;}
il vd rt(ll x){x<0?pc('-'),x=-x:0,pc((x>=10?rt(x/10),x%10:x)+48);}
il vd flush(){fwrite(duf,1,q1-duf,stdout);}


#include <iostream>
#include <cstdio>
#include <algorithm>
#include <cmath>
using namespace std;

const int MAXN=3001;
long long n,ans=1e18,a[MAXN],b[MAXN],dp[MAXN][MAXN];

int main()
{
	scanf("%lld",&n);

	for(long long i=1;i<=n;i++)
	{
		scanf("%lld",&a[i]);
		b[i]=a[i]-i;
	}

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

	for(long long i=1;i<=n;i++)
		for(long long j=1;j<=n;j++)
			dp[i][j]=1e18;
	dp[0][1]=0;

	for(long long i=1;i<=n;i++)
	{
		long long tmp=1e18;
		for(long long j=1;j<=n;j++)
		{
			tmp=min(tmp,dp[i-1][j]);
			dp[i][j]=tmp+abs(a[i]-b[j]);
		}
	}

	for(long long i=1;i<=n;i++)
		ans=min(ans,dp[n][i]);

	printf("%lld",ans);
	return 0;
}


#include <cstring>
#include <iostream>
#include <stdio.h>
#include <algorithm>
#include <cmath>
#include <vector>
#include <queue>
#include <stack>
#include <map>
#include <math.h>
#include <set>
#include <time.h>
using namespace std;
const int INF=0x3f3f3f3f;
const long long LLINF=0x3f3f3f3f3f3f3f3f;
int a[3030],b[3030];
long long dp[3030][3030];
int main()
{
    int n;
    scanf("%d",&n);
    for(int i=1;i<=n;++i)
    {
        scanf("%d",a+i);
        a[i]-=i;
        b[i]=a[i];
    }
    sort(a+1,a+n+1);
    for(int i=1;i<=n;++i)
    {
        long long temp=dp[i-1][1];
        for(int j=1;j<=n;++j)
        {
            temp=min(temp,dp[i-1][j]);
            dp[i][j]=abs(b[i]-a[j])+temp;
        }
    }
    long long ans=INF;
    for(int i=1;i<=n;++i)
        ans=min(ans,dp[n][i]);
    printf("%I64d\n",ans);
    return 0;
}


#include <cstring>
#include <iostream>
#include <stdio.h>
#include <algorithm>
#include <cmath>
#include <vector>
#include <queue>
#include <stack>
#include <map>
#include <math.h>
#include <set>
#include <time.h>
using namespace std;
const int INF=0x3f3f3f3f;
const long long LLINF=0x3f3f3f3f3f3f3f3f;
int a[3030],b[3030];
long long dp[3030][3030];
int main()
{
    int n;
    scanf("%d",&n);
    for(int i=1;i<=n;++i)
    {
        scanf("%d",a+i);
        a[i]-=i;
        b[i]=a[i];
    }
    sort(a+1,a+n+1);
    for(int i=1;i<=n;++i)
    {
        long long temp=dp[i-1][1];
        for(int j=1;j<=n;++j)
        {
            temp=min(temp,dp[i-1][j]);
            dp[i][j]=abs(b[i]-a[j])+temp;
        }
    }
    long long ans=LLINF;
    for(int i=1;i<=n;++i)
        ans=min(ans,dp[n][i]);
    printf("%I64d\n",ans);
    return 0;
}


#include <cstring>
#include <iostream>
#include <stdio.h>
#include <algorithm>
#include <cmath>
#include <vector>
#include <queue>
#include <stack>
#include <map>
#include <math.h>
#include <set>
#include <time.h>
using namespace std;
const int INF=0x3f3f3f3f;
int a[3030],b[3030];
int dp[3030][3030];
int main()
{
    int n;
    scanf("%d",&n);
    for(int i=1;i<=n;++i)
    {
        scanf("%d",a+i);
        a[i]-=i;
        b[i]=a[i];
    }
    sort(a+1,a+n+1);
    for(int i=1;i<=n;++i)
    {
        int temp=dp[i-1][1];
        for(int j=1;j<=n;++j)
        {
            temp=min(temp,dp[i-1][j]);
            dp[i][j]=abs(b[i]-a[j])+temp;
        }
    }
    int ans=INF;
    for(int i=1;i<=n;++i)
        ans=min(ans,dp[n][i]);
    printf("%d\n",ans);
    return 0;
}


#include <cstring>
#include <iostream>
#include <stdio.h>
#include <algorithm>
#include <cmath>
#include <vector>
#include <queue>
#include <stack>
#include <map>
#include <math.h>
#include <set>
#include <time.h>
using namespace std;
const int INF=0x3f3f3f3f;
int a[3030],b[3030];
int dp[3030][3030];
int main()
{
    int n;
    scanf("%d",&n);
    for(int i=1;i<=n;++i)
    {
        scanf("%d",a+i);
        b[i]=a[i];
    }
    sort(a+1,a+n+1);
    for(int i=1;i<=n;++i)
    {
        int temp=dp[i-1][1];
        for(int j=1;j<=n;++j)
        {
            temp=min(temp,dp[i-1][j]);
            dp[i][j]=abs(b[i]-a[j+1])+temp;
        }
    }
    int ans=INF;
    for(int i=1;i<=n;++i)
        ans=min(ans,dp[n][i]);
    printf("%d\n",ans);
    return 0;
}


#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const int INF = 1e9 + 7;
const int SZ = 3000 + 100;
int n;
ll dp[SZ][SZ],sum[SZ];
int a[SZ],b[SZ];

int main()
{
	scanf("%d",&n);
	for(int i = 1;i <= n;i ++ )
	{
		 scanf("%d",&a[i]);
		 a[i] -= i;
		 b[i] = a[i];
	}
	sort(a + 1,a + n + 1);
	sum[0] = INF;
	int tot = unique(a + 1,a + n + 1) - (a + 1);
	for(int i = 1;i <= tot;i ++ )
	{
		dp[1][i] = abs(b[1] - a[i]);
		sum[i] = min(dp[1][i],sum[i - 1]);
	}
	for(int i = 2;i <= n;i ++ )
	{
		for(int j = 1;j <= tot;j ++ )
		{
			dp[i][j] = sum[j] + abs(b[i] - a[j]);
			sum[j] = min(dp[i][j],sum[j - 1]);
		}
	}
	ll ans = INF;
	for(int i = 1;i <= tot;i ++ )
	{
		ans = min(ans,dp[n][i]);
	}
	printf("%d",ans);
	return 0;
}


#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const int INF = 1e9 + 7;
const int SZ = 3000 + 100;
int n;
ll dp[SZ][SZ],sum[SZ];
int a[SZ],b[SZ];

int main()
{
	scanf("%d",&n);
	for(int i = 1;i <= n;i ++ )
	{
		 scanf("%d",&a[i]);
		 a[i] -= i;
		 b[i] = a[i];
	}
	sort(a + 1,a + n + 1);
	sum[0] = 1e18;
	int tot = unique(a + 1,a + n + 1) - (a + 1);
	for(int i = 1;i <= tot;i ++ )
	{
		dp[1][i] = abs(b[1] - a[i]);
		sum[i] = min(dp[1][i],sum[i - 1]);
	}
	for(int i = 2;i <= n;i ++ )
	{
		for(int j = 1;j <= tot;j ++ )
		{
			dp[i][j] = sum[j] + abs(b[i] - a[j]);
			sum[j] = min(dp[i][j],sum[j - 1]);
		}
	}
	ll ans = 1e18;
	for(int i = 1;i <= tot;i ++ )
	{
		ans = min(ans,dp[n][i]);
	}
	printf("%d",ans);
	return 0;
}


#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const int INF = 1e9 + 7;
const int SZ = 3000 + 100;
int n;
ll dp[SZ][SZ],sum[SZ];
int a[SZ],b[SZ];

int main()
{
	scanf("%d",&n);
	for(int i = 1;i <= n;i ++ )
	{
		 scanf("%d",&a[i]);
		 a[i] -= i;
		 b[i] = a[i];
	}
	sort(a + 1,a + n + 1);
	int tot = unique(a + 1,a + n + 1) - (a + 1);
	for(int i = 1;i <= tot;i ++ )
	{
		dp[1][i] = abs(b[1] - a[i]);
		if(i == 1) sum[i] = dp[1][i];
		else sum[i] = min(dp[1][i],sum[i - 1]);
	}
	for(int i = 2;i <= n;i ++ )
	{
		for(int j = 1;j <= tot;j ++ )
		{
			dp[i][j] = sum[j] + abs(b[i] - a[j]);
			if(j == 1) sum[j] = dp[i][j];
			else sum[j] = min(dp[i][j],sum[j - 1]);
		}
	}
	ll ans = 1e18;
	for(int i = 1;i <= tot;i ++ )
	{
		ans = min(ans,dp[n][i]);
	}
	printf("%d",ans);
	return 0;
}


#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const int INF = 1e9 + 7;
const int SZ = 3000 + 100;
int n;
ll dp[SZ][SZ],sum[SZ];
int a[SZ],b[SZ];

int main()
{
	scanf("%d",&n);
	for(int i = 1;i <= n;i ++ )
	{
		 scanf("%d",&a[i]);
		 a[i] -= i;
		 b[i] = a[i];
	}
	sort(a + 1,a + n + 1);
	int tot = unique(a + 1,a + n + 1) - (a + 1);
	sum[0] = 1e18;
	for(int i = 1;i <= tot;i ++ )
	{
		dp[1][i] = abs(b[1] - a[i]);
		sum[i] = min(dp[1][i],sum[i - 1]);
	}
	for(int i = 2;i <= n;i ++ )
	{
		for(int j = 1;j <= tot;j ++ )
		{
			dp[i][j] = sum[j] + abs(b[i] - a[j]);
			sum[j] = min(dp[i][j],sum[j - 1]);
		}
	}
	ll ans = 1e18;
	for(int i = 1;i <= tot;i ++ )
	{
		ans = min(ans,dp[n][i]);
	}
	printf("%lld",ans);
	return 0;
}


#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const int INF = 1e9 + 7;
const int SZ = 3000 + 100;
int n;
ll dp[SZ][SZ],sum[SZ];
int a[SZ],b[SZ];

int main()
{
	scanf("%d",&n);
	for(int i = 1;i <= n;i ++ )
	{
		 scanf("%d",&a[i]);
		 a[i] -= i;
		 b[i] = a[i];
	}
	sort(a + 1,a + n + 1);
	sum[0] = INF;
	int tot = unique(a + 1,a + n + 1) - (a + 1);
	for(int i = 1;i <= tot;i ++ )
	{
		dp[1][i] = abs(b[1] - a[i]);
		sum[i] = min(dp[1][i],sum[i - 1]);
	}
	for(int i = 2;i <= n;i ++ )
	{
		for(int j = 1;j <= tot;j ++ )
		{
			dp[i][j] = sum[j] + abs(b[i] - a[j]);
			sum[j] = min(dp[i][j],sum[j - 1]);
		}
	}
	ll ans = 1e18;
	for(int i = 1;i <= tot;i ++ )
	{
		ans = min(ans,dp[n][i]);
	}
	printf("%d",ans);
	return 0;
}


#include<cstdio>
#include<cmath>
#include<algorithm>
#define MAXN 3001
using namespace std;
int n;
long long a[MAXN],b[MAXN],f[MAXN][MAXN];
int main()
{
	scanf("%d",&n);
	for(int i=1;i<=n;i++) {
		scanf("%I64d",&a[i]);
		a[i]-=i;
		b[i]=a[i];
	}
	sort(b+1,b+n+1);
	int bn=unique(b+1,b+n+1)-b;
	for(int i=1;i<=n;i++) {
		long long m=0x7fffffffffffffff;
		for(int j=1;j<=bn;j++) {
			m=min(m,f[i-1][j]);
			f[i][j]=m+abs(a[i]-b[j]);
		}
	}
	long long ans=0x7ffffffffffffff;
	for(int i=1;i<=bn;i++) ans=min(ans,f[n][i]);
	printf("%I64d\n",ans);
	return 0;
}


#include<cstdio>
#include<cmath>
#include<algorithm>
#define MAXN 3001
using namespace std;
int n,a[MAXN],b[MAXN],f[MAXN][MAXN];
int main()
{
	scanf("%d",&n);
	for(int i=1;i<=n;i++) {
		scanf("%d",&a[i]);
		a[i]-=i;
		b[i]=a[i];
	}
	sort(b+1,b+n+1);
	for(int i=1;i<=n;i++) {
		int m=0x7fffffff;
		for(int j=1;j<=n;j++) {
			m=min(m,f[i-1][j]);
			f[i][j]=m+abs(a[i]-b[j]);
		}
	}
	int ans=0x7fffffff;
	for(int i=1;i<=n;i++) ans=min(ans,f[n][i]);
	printf("%d\n",ans);
	return 0;
}


#include<cstdio>
#include<cmath>
#include<algorithm>
#define MAXN 3001
using namespace std;
int n;
long long a[MAXN],b[MAXN],f[MAXN][MAXN];
int main()
{
	scanf("%d",&n);
	for(int i=1;i<=n;i++) {
		scanf("%I64d",&a[i]);
		a[i]-=i;
		b[i]=a[i];
	}
	sort(b+1,b+n+1);
	for(int i=1;i<=n;i++) {
		long long m=0x7fffffffffffffff;
		for(int j=1;j<=n;j++) {
			m=min(m,f[i-1][j]);
			f[i][j]=m+abs(a[i]-b[j]);
		}
	}
	long long ans=0x7ffffffffffffff;
	for(int i=1;i<=n;i++) ans=min(ans,f[n][i]);
	printf("%I64d\n",ans);
	return 0;
}


#include<cstdio>
#include<cmath>
#include<algorithm>
#define MAXN 3001
using namespace std;
int n;
long long a[MAXN],b[MAXN],f[MAXN][MAXN];
int main()
{
	scanf("%d",&n);
	for(int i=1;i<=n;i++) {
		scanf("%I64d",&a[i]);
		a[i]-=i;
		b[i]=a[i];
	}
	sort(b+1,b+n+1);
	for(int i=1;i<=n;i++) {
		long long m=0x7fffffff;
		for(int j=1;j<=n;j++) {
			m=min(m,f[i-1][j]);
			f[i][j]=m+abs(a[i]-b[j]);
		}
	}
	long long ans=0x7fffffff;
	for(int i=1;i<=n;i++) ans=min(ans,f[n][i]);
	printf("%I64d\n",ans);
	return 0;
}


#include <iostream>
#include <cstdio>
#include <cstring>
#include <cmath>
#include <algorithm>
using namespace std;
typedef long long ll;
const int maxn = 3e3 + 5;
const ll INF = 0x7fffffffffffffff; //���ﲻ��const int �� const ll
ll a[maxn], b[maxn], dp[maxn][maxn]; //��Ϊÿ��������1e9��Χ�ڣ�����Ҫ��ll
int main()
{
    int n;
    cin >> n;
    for(int i = 1; i <= n; i++)
    {
        cin >> a[i];
        a[i] -= i;   //������ǰ��ϸ����ת���ɷ��ϸ����
        b[i] = a[i];
    }
    sort(b+1, b+n+1);
    for(int i = 1; i <= n; i++)
    {
        ll min1 = INF;
        for(int j = 1; j <= n; j++)
        {
            min1 = min(min1, dp[i-1][j]);  //���min1��ʾ�ľ���i-1�����������һ����С�ڵ���b[j]����Сֵ�����ּ�¼��ʽ�ܺ�
            dp[i][j] = min1 + abs(a[i]-b[j]);
        }
    }
    ll ans = INF;
    for(int j = 1; j <= n; j++)
    {
        ans = min(dp[n][j], ans);  //���ĸ���β��С
    }
    cout << ans << endl;
    return 0;
}


#include<bits/stdc++.h>
using namespace std;

#define I inline
#define ri register int
#define ll long long
#define int long long
#define ull unsigned long long
#define min(a,b) ((a)<(b)?(a):(b))
#define max(a,b) ((a)>(b)?(a):(b))
#define rep(i,a,b) for(ri i=(a);i<=(b);++i)
#define dow(i,a,b) for(ri i=(a);i>=(b);--i)
#define go(i,u) for(ri i=lnk[u];i;i=nxt[i])
#define pii pair<int,int>
#define mp make_pair
#define fi first
#define se second
#define vec vector
#define que queue
#define pb push_back
#define lowbit(x) (x&(-x))
#define mem(f,x) memset(f,x,sizeof(f))

I int gi(){
	int x=0,f=0;char ch=getchar();
	while(!isdigit(ch)){f|=ch=='-',ch=getchar();}
	while(isdigit(ch)){x=x*10+ch-48,ch=getchar();}
	return f?-x:x;
}

I void pi(int x){
	if(x<0)putchar('-'),x=-x;
	if(x>9)pi(x/10);
	putchar(x%10+48);
}
I void pib(int x){pi(x);putchar(' ');}
I void pin(int x){pi(x);putchar('\n');}

const int N = 3e3+5,inf = 1e18+5;

int f[N][N],g[N][N],a[N],n,b[N];

signed main(){

	n=gi();
	rep(i,1,n)a[i]=gi()-i,b[i]=a[i];
	sort(b+1,b+n+1);
	mem(f,0x3f);mem(g,0x3f);
	rep(i,1,n)f[0][i]=g[0][i]=0;
	rep(i,1,n){
		rep(j,1,n){
			f[i][j]=min(f[i][j],g[i-1][j]+abs(a[i]-b[j]));
			g[i][j]=min(g[i][j-1],f[i][j]);
		}
	}
	int ans=inf;
	rep(i,1,n)ans=min(ans,f[n][i]);
	pin(ans);
	return 0;
}


#include<bits/stdc++.h>
#define inf 0x3f3f3f3f3f3f
#define ll long long
using namespace std;
ll dp[3005][3005],n,mn,a[3005],rd[3005];
int main()
{
	memset(dp,0x3f,sizeof(dp));dp[0][1]=0;
	cin>>n;
	for(int i=1;i<=n;++i)
	{
		cin>>rd[i];
		rd[i]-=i;
		a[i]=rd[i];
	}
	sort(rd+1,rd+n+1);
	for(int i=1;i<=n;++i)
	{
		mn=inf;
		for(int j=1;j<=n;++j)
		{
		mn=min(mn,dp[i-1][j]);
		dp[i][j]=mn+abs(a[i]-rd[j]);
	    }
    }
	mn=inf;
	for(int i=1;i<=n;i++)
	mn=min(mn,dp[n][i]);
	cout<<mn;
}


#include<bits/stdc++.h>
using namespace std;
long long n,m,dp[3010][3010],a[3010],re[3010];
int main ( )
{
	scanf("%lld",&n);
	for(long long i=1;i<=n;i++)
	{
		scanf("%lld",&a[i]);
		a[i]-=i;
		re[i]=a[i];
	}
	sort(re+1,re+n+1);
	m=unique(re+1,re+n+1)-re-1;
	memset(dp,0x3f3f3f3f,sizeof(dp));
	dp[0][1]=0;
	for(long long i=1;i<=n;i++)
	{
		long long mina=999999999;
		for(long long j=1;j<=m;j++)
		{
			mina=min(mina,dp[i-1][j]);
			dp[i][j]=mina+abs(a[i]-re[j]);
		}
	}
	long long minn=0x3f3f3f3f3f3f;
	for(long long i=1;i<=m;i++)
	minn=min(minn,dp[n][i]);
	cout<<minn;
	return 0 ;
}


#include <cstdio>
#include <iostream>
#include <algorithm>
#include <queue>
using namespace std;
#define int long long
int n, ans;
priority_queue<int> Q;
signed main() {
    int n;
    scanf("%lld", &n);
    int x;
    for (int i = 1; i <= n; i++) {
        int x;
        scanf("%lld", &x);
        Q.push(x);
        if (Q.top() > x)
            ans += Q.top() - x, Q.pop(), Q.push(x);
    }
    printf("%lld", ans);
    return 0;
}


#include <iostream>
#include <cstdio>
#include <algorithm>
#include <cmath>
using namespace std;

const int MAXN=3001;
long long n,ans=1e18,a[MAXN],b[MAXN],dp[MAXN][MAXN];

int main()
{
	scanf("%lld",&n);

	for(long long i=1;i<=n;i++)
	{
		scanf("%lld",&b[i]);
		b[i]-=i;
		a[i]=b[i];
	}

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

	for(long long i=1;i<=n;i++)
		for(long long j=1;j<=n;j++)
			dp[i][j]=1e18;
	dp[0][1]=0;

	for(long long i=1;i<=n;i++)
	{
		long long tmp=1e18;
		for(long long j=1;j<=n;j++)
		{
			tmp=min(tmp,dp[i-1][j]);
			dp[i][j]=tmp+abs(a[i]-b[j]);
		}
	}

	for(long long i=1;i<=n;i++)
		ans=min(ans,dp[n][i]);

	printf("%lld",ans);
	return 0;
}


#pragma GCC optimize(2)
#include <cstdio>
#include <queue>

using namespace std;

int n;
long long ans;

priority_queue<int> Q;

inline int read() {
	int a=0;char c=getchar();
	while(c<'0'||c>'9') c=getchar();
	while(c>='0'&&c<='9') a=(a<<3)+(a<<1)+c-'0',c=getchar();
	return a;
}

int main() {
    n=read();
    for(register int i=1;i<=n;++i) {
        int x=read()-i;Q.push(x);
        if(Q.top()>x)
            ans+=Q.top()-x,Q.pop(),Q.push(x);
    } printf("%lld",ans);
    return 0;
}


#include<bits/stdc++.h>
using namespace std;
long long n,x,ans;
priority_queue<long long> q;
int main()
{
	cin>>n;
	for(int i=1;i<=n;i++){
		scanf("%lld",&x);
		x-=i;
		q.push(x);
		if(q.top()>x){
			ans+=q.top()-x;
			q.pop();
			q.push(x);
		}
	}
	cout<<ans;
	return 0;
}


#pragma GCC optimize(2)
#include <cstdio>
#include <algorithm>

using namespace std;

const int maxn=3e3+50;
const long long inf=0x7f7f7f7f7f7f7f7f;

int n,a[maxn],b[maxn];
long long f[maxn][maxn];

inline int read() {
	int a=0;char c=getchar();
	while(c<'0'||c>'9') c=getchar();
	while(c>='0'&&c<='9') a=(a<<3)+(a<<1)+c-'0',c=getchar();
	return a;
}

int main() {
    n=read();
    for(register int i=1;i<=n;++i) b[i]=a[i]=read()-i;
    sort(b+1,b+1+n);
    for(register int i=1;i<=n;++i) {
    	long long Min=inf;
    	for(register int j=1;j<=n;++j) {
    		Min=min(Min,f[i-1][j]);
    		f[i][j]=Min+abs(a[i]-b[j]);
		}
	} long long ans=inf;
	for(register int i=1;i<=n;++i) ans=min(ans,f[n][i]);
	printf("%lld",ans);
    return 0;
}


#include<bits/stdc++.h>
using namespace std;
long long n,x,ans;
priority_queue<long long>q;
int main()
{
    cin>>n;
    for(int i=1;i<=n;i++)
	{
        scanf("%lld",&x);
        x-=i;
        q.push(x);
        if(q.top()>x)
		{
            ans+=q.top()-x;
            q.pop();
            q.push(x);
        }
    }
    cout<<ans;
    return 0;
}


#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
ll ans;
int n;
priority_queue<ll> q;
int main(){
	scanf("%d",&n);
	for(int i=1;i<=n;i++){
		ll x;
		scanf("%lld",&x);
		x-=i;
		q.push(x);
		if(q.top()>x){
			ans+=q.top()-x;
			q.pop();
			q.push(x);
		}
	}
	printf("%lld\n",ans);
	return 0;
}


#include<iostream>
#include<cstdio>
#include<cstring>
#include<algorithm>
#include<queue>
#define ll long long
using namespace std;
ll a,a__[3010],a_[3010],dp[3010][3010],n,t,ans=1e18;
int main(){
	scanf("%lld",&n);
	for(int i=1;i<=n;i++){
		scanf("%lld",&a);
		a__[i]=a-i;
		a_[i]=a__[i];
	}
	sort(a__+1,a__+n+1);
	for(int i=1;i<=n;i++){
		dp[1][i]=abs(a_[1]-a__[i]);
	}
	for(int i=1;i<=n;i++){
		t=1e18;
		for(int j=1;j<=n;j++){
			t=min(t,dp[i-1][j]);
			dp[i][j]=t+abs(a_[i]-a__[j]);
		}
	}
	for(int i=1;i<=n;i++){
		ans=min(ans,dp[n][i]);
	}
	printf("%d",ans);
	return 0;
}
/*

*/


#include<cstdio>
#include<queue>
using namespace std;
priority_queue<int>q;
int main(){
	int n;
	long long ans=0;
	scanf("%d",&n);
    for(int i = 1; i <= n; i++) {
        int num;
        scanf("%d",&num);
        q.push(num);
        if(num < q.top()) {
            ans += q.top() - num;
            q.pop();
            q.push(num);
        }
    }
    printf("%lld\n", ans);
}


//感谢hyl大佬与zml老师的思路与指点
#include<iostream>
#include<cstdio>
#include<set>
#include<ctime>
#include<map>
#include<cstdlib>
#include<algorithm>
#include<queue>
#include<stack>
#include<string>
#include<cstring>
#include<cmath>
using namespace std;
long long dp[3005][3005],a[3005],b[3005];//dp[i][j]表示a前i个变为b的前j个时的最小操作次数.
int main()
{
	long long n,i,j,minn,ans=2e18;
    cin>>n;
    for(i=1;i<=n;i++)
    {
    	cin>>a[i];
    	a[i]-=i;//将a[i]减去一个上升的序列。使修改b[i]后a[i]严格上升。
    	b[i]=a[i];//用b[i]备份a[i]，准备离散化。
	}
	sort(b+1,b+n+1);//sort排一遍使b[i]严格不下降。
	for(i=1;i<=n;i++)
	{
		dp[1][i]=abs(a[1]-b[i]);//初始化,将a[1]变b[i]的操作次数记录下来.
	}
	for(i=2;i<=n;i++)//开始dp
	{
		minn=2e18;
		for(j=1;j<=n;j++)
		{
			minn=min(minn,dp[i-1][j]);
			dp[i][j]=minn+abs(a[i]-b[j]);
		}
	}
	for(i=1;i<=n;i++)
	{
		ans=min(ans,dp[n][i]);
	}
	cout<<ans;
	return 0;
}


#include<bits/stdc++.h>
#define reg register
#define ll long long
#define inf 0x3f3f3f3f
#define iinf 0x3f3f3f3f3f3f3f3f

using namespace std;
ll n,x,ans;
priority_queue<ll>q;、
int main()
{
    scanf("%d",&n);
    for(reg int i=1;i<=n-1;i++)
    {
        scanf("%lld",&x);
        x-=i;
        q.push(x);
        if(q.top()>x)
        {
            ans+=q.top()-x;
            q.pop();
            q.push(x);
        }
    }
    printf("%lld\n",ans);
    return 0;
}


#include <cstdio>
#include <queue>
//贪心 或 暴力dp
using namespace std;

int n;
long long ans;

priority_queue<int> Q;

int main() {
	scanf("%d",&n);
	for(register int i=1;i<=n;++i) {
		int x;scanf("%d",&x);x-=i;
		//通过修改x将题目转化为求不下降序列
		Q.push(x);
		if(Q.top()>x) {
		//x不是当前不下降序列的最大值
			printf("%d ",Q.top()-x);
			ans+=Q.top()-x;
			//更新答案
			Q.pop();Q.push(x);
		}
	} printf("\n%lld",ans);
	return 0;
}


#include <iostream>
#include <cstdio>
#include <algorithm>
#include <cmath>
#include <string.h>
#include <queue>
#include <vector>
#include <set>
#include <cctype>
#include <cstdlib>
#include <time.h>
#include <map>
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;
#define mp make_pair
inline ll read(){
	ll x = 0; char ch = getchar(); bool positive = 1;
	for (; !isdigit(ch); ch = getchar())	if (ch == '-')	positive = 0;
	for (; isdigit(ch); ch = getchar())	x = x * 10 + ch - '0';
	return positive ? x : -x;
}
inline void write(ll a){
    if(a<0){
    	a=-a; putchar('-');
	}
    if(a>=10)write(a/10);
    putchar('0'+a%10);
}
int rnd(int mod){
	unsigned long long ans=0;
	for(int i=0;i<5;i++)ans=ans<<15^rand();
	return ans%(mod-1)+1;
}
const int maxn=1e5+10;
const int inf=0x3f3f3f3f;
int n;
typedef pair<int,int>pll;
ll dp[3010][3010];
ll a[maxn];
ll b[maxn];
int main() {
	memset(dp,0,sizeof(dp));
	n=read();
	for(int i=1;i<=n;i++){
		a[i]=read();
		//sum+=a[i];
		a[i]-=i;
		//num.push_back(a[i]);
		b[i]=a[i];
	}
	sort(b+1,b+n+1);
	for(int i=1;i<=n;i++) {
		dp[i][1]=dp[i-1][1]+abs(a[i]-b[1]);
		for(int j=2;j<=n;j++) {
			dp[i][j]=min(dp[i][j-1],dp[i-1][j]+abs(a[i]-b[j]));
		}
	}
	cout<<dp[n][n]<<endl;
	return 0;
}


#include<bits/stdc++.h>
using namespace std;
priority_queue<int>q;
int n,temp;
long long ans=0;
int main()
{
	scanf("%d",&n);
	for(int i=1;i<=n;i++)
	{
		scanf("%d",&temp);
		temp-=i;
		q.push(temp);
		if(temp<q.top())
		{
			ans+=(q.top()-temp);
			q.pop();
			q.push(temp);
		}
	}
	cout<<ans;
	return 0;
}


#include<bits/stdc++.h>
using namespace std;
priority_queue<int> q;
int n,x;long long ans;
signed main(){
	cin>>n;
	while(n--){
		cin>>x;q.push(x);
		if(x<=q.top()){
			ans+=q.top()-x+1;
			q.pop();q.push(x);
		}
	}
	printf("%lld\n",ans);
	return 0;
}


#include<bits/stdc++.h>
#define N 3010
#define M
#define V
#define INF 0x7fffffff
#define _INF 1e18
#define oo 0x3f3f3f3f
#define inf 0x3fffffff
#define int LL
#define LL long long
#define LLU unsigned long long
#define LD long double
#define FOR(i,l,r) for(int i=(l);i<=(r);++i)
#define _FOR(i,l,r,x) for(int i=(l);i<=(r);i+=x)
#define REP(i,l,r) for(int i=(l);i>=(r);--i)
#define _REP(i,l,r,x) for(int i=(l);i>=(r);i-=x)
#define LIN(p,l) for(int p=(l);p;p=nxt[p])
#define fin(x) freopen(x".in","r",stdin)
#define fout(x) freopen(x".out","w",stdout)
using namespace std;
inline int read()
{
	char ch;int f=1,x;
	while(ch=getchar(),!isdigit(ch)) if(ch=='-') f=-1;x=(ch^48);
	while(ch=getchar(),isdigit(ch)) x=(x<<3)+(x<<1)+(ch^48);
	return x*f;
}
inline void write(int x)
{
	if(x<0)
	{
		putchar('-');
		write(-x);
		return;
	}
	if(x>=10) write(x/10);
	putchar(x%10^48);
}
inline void writ(int x)
{
	write(x);
	puts("");
}
int n,ans,a[N];
priority_queue<int> q;
signed main()
{
	n=read();
	FOR(i,1,n) a[i]=read()-i;
	FOR(i,1,n)
	{
		q.push(a[i]);
		if(q.top()>a[i])
		{
			ans+=q.top()-a[i];
			q.pop();
			q.push(a[i]);
		}
	}
	writ(ans);
	return 0;
}


import java.util.*;
import java.lang.*;
import java.io.*;
import java.awt.Point;

// SHIVAM GUPTA :
//NSIT
//decoder_1671
//BEING PERFECTIONIST IS NOT AN OPTION.
// YOUR LOVE MAKE ME STRONGER BUT UR HATE MAKES ME STRONGEST ... NOW ITS UR CHOICE..........
// STOP NOT TILL IT IS DONE OR U DIE .
//EITHER MAKE IT OR BREAK IT.
//NEVER UNDERESTIMATE URSELF.
// U KNOW THAT IF THIS DAY WILL BE URS THEN NO ONE CAN DEFEAT U HERE................
// REST ..HAVE FAITH ON DESTINY
//MIRACLE HAPPENS RARELY .....BUT IT HAPPENS ...

// ASCII = 48 + i ;

// 2^28 = 268,435,456  > 2* 10^8

// log 10 base 2 = 3.3219

// odd:: (x^2+1)/2 , (x^2-1)/2 ; x>=3

// even:: (x^2/4)+1 ,(x^2/4)-1  x >=4

// FOR ANY ODD NO N : N,N-1,N-2
//ALL ARE PAIRWISE COPRIME
//THEIR COMBINED LCM IS PRODUCT OF ALL THESE NOS

// two consecutive odds are always coprime to each other

// two consecutive even have always gcd  = 2 ;

/* Name of the class has to be "Main" only if the class is public. */

public class Main
{

    // static int[] arr = new int[100002] ;
    // static int[] dp = new int[100002] ;

     static PrintWriter out;

	static class FastReader{
		BufferedReader br;
		StringTokenizer st;
		public FastReader(){
			br=new BufferedReader(new InputStreamReader(System.in));
			out=new PrintWriter(System.out);
		}
		String next(){
			while(st==null || !st.hasMoreElements()){
				try{
					st= new StringTokenizer(br.readLine());
				}
				catch (IOException e){
					e.printStackTrace();
				}
			}
			return st.nextToken();
		}
		int nextInt(){
			return Integer.parseInt(next());
		}
		long nextLong(){
			return Long.parseLong(next());
		}
		double nextDouble(){
			return Double.parseDouble(next());
		}
		String nextLine(){
			String str = "";
			try{
				str=br.readLine();
			}
			catch(IOException e){
				e.printStackTrace();
			}
			return str;
		}
	}

////////////////////////////////////////////////////////////////////////////////////
 public static int countDigit(long n)
    {
        return (int)Math.floor(Math.log10(n) + 1);
    }

/////////////////////////////////////////////////////////////////////////////////////////

 public static int sumOfDigits(long n)
 {

  if( n< 0)return -1 ;

  int sum = 0;

  while( n > 0)
  {
      sum = sum + (int)( n %10) ;

      n /= 10 ;
  }

  return sum ;

 }

 //////////////////////////////////////////////////////////////////////////////////////////////////

public static long arraySum(int[] arr , int start , int end)
{
    long ans = 0 ;

    for(int i = start ; i <= end  ; i++)ans += arr[i] ;

    return ans  ;
}

/////////////////////////////////////////////////////////////////////////////////

public static int mod(int x)
{
      if(x <0)return -1*x ;
      else return x ;
}
public static long mod(long x)
{
      if(x <0)return -1*x ;
      else return x ;
}

////////////////////////////////////////////////////////////////////////////////

public static void swapArray(int[] arr , int start , int end)
{
    while(start < end)
    {
        int temp = arr[start] ;
        arr[start] = arr[end];
        arr[end] = temp;
        start++ ;end-- ;
    }
}

//////////////////////////////////////////////////////////////////////////////////

public static int[][] rotate(int[][] input){

int n =input.length;
int m = input[0].length ;
int[][] output = new int [m][n];

for (int i=0; i<n; i++)
	for (int j=0;j<m; j++)
		output [j][n-1-i] = input[i][j];
return output;
}
///////////////////////////////////////////////////////////////////////////////////////////////////////

public static int countBits(long n)
    {
        int count = 0;
        while (n != 0)
        {
            count++;
            n = (n) >> (1L) ;
        }

        return count;

    }
/////////////////////////////////////////// ////////////////////////////////////////////////

public static boolean isPowerOfTwo(long n)
{
    if(n==0)
    return false;

if(((n ) & (n-1)) == 0 ) return true ;
else return false  ;

}

/////////////////////////////////////////////////////////////////////////////////////

public static int  min(int a ,int b , int c, int d)
{
     int[] arr = new int[4] ;
      arr[0] = a;arr[1] = b ;arr[2] = c;arr[3] = d;Arrays.sort(arr) ;

      return arr[0];
}
 /////////////////////////////////////////////////////////////////////////////
public static int  max(int a ,int b , int c, int d)
{
     int[] arr = new int[4] ;
      arr[0] = a;arr[1] = b ;arr[2] = c;arr[3] = d;Arrays.sort(arr) ;

      return arr[3];
}

///////////////////////////////////////////////////////////////////////////////////

public static String reverse(String input)
{
  StringBuilder str  = new StringBuilder("") ;

    for(int i =input.length()-1 ; i >= 0  ; i-- )
    {
        str.append(input.charAt(i));
    }

return str.toString() ;
}
///////////////////////////////////////////////////////////////////////////////////////////

public static boolean sameParity(long a  ,long b )
{
     long x = a% 2L; long y = b%2L ;
     if(x==y)return true  ;
     else return false  ;
}

////////////////////////////////////////////////////////////////////////////////////////////////////
public static boolean isPossibleTriangle(int a  ,int b , int c)
{
      if( a + b > c && c+b > a && a +c > b)return true  ;
      else return false  ;
}

////////////////////////////////////////////////////////////////////////////////////////////
static long xnor(long num1, long num2) {
		if (num1 < num2) {
			long temp = num1;
			num1 = num2;
			num2 = temp;
		}
		num1 = togglebit(num1);
		return num1 ^ num2;
	}

	static long togglebit(long n) {
		if (n == 0)
			return 1;
		long i = n;
		n |= n >> 1;
		n |= n >> 2;
		n |= n >> 4;
		n |= n >> 8;
		n |= n >> 16;
		return i ^ n;
	}

///////////////////////////////////////////////////////////////////////////////////////////////

public static int xorOfFirstN(int n)
{

 if( n % 4 ==0)return n ;

 else if( n % 4 == 1)return 1 ;

 else if( n % 4 == 2)return n+1 ;

 else return 0 ;

}
//////////////////////////////////////////////////////////////////////////////////////////////

public static int gcd(int a, int b )
{

if(b==0)return a ;

else return gcd(b,a%b) ;

}

public static long gcd(long a, long b )
{

if(b==0)return a ;

else return gcd(b,a%b) ;

}

////////////////////////////////////////////////////////////////////////////////////

public static int lcm(int a, int b ,int c , int d )
{

int temp = lcm(a,b , c) ;

 int ans = lcm(temp ,d ) ;

return ans  ;

}

///////////////////////////////////////////////////////////////////////////////////////////

public static int lcm(int a, int b ,int c )
{

int temp = lcm(a,b) ;

int ans =  lcm(temp ,c) ;

return ans  ;

}

////////////////////////////////////////////////////////////////////////////////////////

public static int lcm(int a , int b )
{

int gc = gcd(a,b);

return (a*b)/gc ;
}

public static long lcm(long a , long b )
{

long gc = gcd(a,b);

return (a*b)/gc ;
}

///////////////////////////////////////////////////////////////////////////////////////////
static boolean isPrime(long n)
{
      if(n==1)
      {
            return false  ;
      }

      boolean ans =  true  ;

      for(long i = 2L; i*i <= n ;i++)
      {
            if(n% i ==0)
            {
                  ans = false  ;break ;
            }
      }

      return ans  ;
}
///////////////////////////////////////////////////////////////////////////

static int sieve =  1000000 ;

static boolean[] prime =  new boolean[sieve + 1] ;

public static void sieveOfEratosthenes()
    {
        // FALSE == prime

        // TRUE ==  COMPOSITE

        // FALSE== 1

        // time complexity = 0(NlogLogN)== o(N)

        // gives prime nos bw 1 to N

        for(int i = 4; i<= sieve ; i++)
        {
            prime[i] = true  ;
            i++ ;
        }

        for(int p = 3; p*p <= sieve; p++)
        {

            if(prime[p] == false)
            {

                for(int i = p*p; i <= sieve; i += p)
                    prime[i] = true;
            }

            p++ ;
        }

    }

///////////////////////////////////////////////////////////////////////////////////

public static void sortD(int[] arr , int s  , int e)
{
      sort(arr ,s , e) ;

      int i =s ; int j = e  ;

      while( i < j)
      {
            int temp = arr[i] ;
            arr[i] =arr[j] ;
            arr[j] = temp ;
            i++ ; j-- ;
      }

      return ;
}

/////////////////////////////////////////////////////////////////////////////////////////

public static long countSubarraysSumToK(long[] arr ,long sum )
    {
      HashMap<Long,Long> map = new HashMap<>() ;

      int n = arr.length ;

      long prefixsum = 0 ;

      long count = 0L ;
      for(int i  = 0; i < n ; i++)
      {
          prefixsum  = prefixsum +  arr[i] ;

          if(sum == prefixsum)count = count+1 ;

          if(map.containsKey(prefixsum -sum))
          {
              count = count + map.get(prefixsum -sum) ;
          }

          if(map.containsKey(prefixsum ))
          {
              map.put(prefixsum , map.get(prefixsum) +1 );
          }

          else{
              map.put(prefixsum , 1L );
          }

      }

      return count  ;

    }

///////////////////////////////////////////////////////////////////////////////////////////////

// KMP ALGORITHM : TIME COMPL:O(N+M)
// FINDS THE OCCURENCES OF PATTERN AS A  SUBSTRING IN STRING
//RETURN THE ARRAYLIST OF INDEXES
// IF SIZE OF LIST IS ZERO MEANS PATTERN IS NOT PRESENT IN STRING

public static ArrayList<Integer> kmpAlgorithm(String str , String pat)
     {
        ArrayList<Integer> list =new ArrayList<>();

        int n = str.length() ;
        int m = pat.length() ;

        String q = pat + "#" + str ;

        int[] lps  =new int[n+m+1] ;

         longestPefixSuffix(lps, q,(n+m+1)) ;

         for(int i =m+1 ; i < (n+m+1) ; i++ )
         {
             if(lps[i] == m)
             {
                 list.add(i-2*m) ;
             }
         }

        return list ;

    }

public static void longestPefixSuffix(int[] lps ,String str , int n)
    {
        lps[0] =  0 ;

        for(int i = 1  ; i<= n-1; i++)
        {
          int l = lps[i-1] ;

          while( l > 0 && str.charAt(i) != str.charAt(l))
          {
              l = lps[l-1] ;
          }

          if(str.charAt(i) == str.charAt(l))
          {
              l++ ;
          }

          lps[i] = l ;
        }

    }

///////////////////////////////////////////////////////////////////////////////////////////////////
///////////////////////////////////////////////////////////////////////////////////////////////////

 // CALCULATE TOTIENT Fn FOR ALL VALUES FROM 1 TO n
    // TOTIENT(N) = count of nos less than n and grater than 1 whose gcd with n is 1
    // or n and the no  will be coprime in nature
    //time : O(n*(log(logn)))

    public static void eulerTotientFunction(int[] arr ,int n )
    {

      for(int i = 1; i <= n  ;i++)arr[i] =i  ;

      for(int i= 2 ; i<= n ;i++)
      {
          if(arr[i] == i)
          {
              arr[i] =i-1 ;

              for(int j =2*i ; j<= n  ; j+= i )
              {
                  arr[j] = (arr[j]*(i-1))/i ;
              }

          }
      }

      return  ;

    }

/////////////////////////////////////////////////////////////////////////////////////////////
public static long nCr(int n,int k)
{
    long ans=1L;
    k=k>n-k?n-k:k;
    int j=1;
    for(;j<=k;j++,n--)
    {
        if(n%j==0)
        {
            ans*=n/j;
        }else
        if(ans%j==0)
        {
            ans=ans/j*n;
        }else
        {
            ans=(ans*n)/j;
        }
    }
    return ans;
}

///////////////////////////////////////////////////////////////////////////////////////////

public static ArrayList<Integer> allFactors(int n)
{
      ArrayList<Integer> list = new ArrayList<>() ;

    for(int i = 1; i*i <= n ;i++)
    {
          if( n % i == 0)
          {
              if(i*i == n)
              {
                    list.add(i) ;
              }
              else{
                    list.add(i) ;
                    list.add(n/i) ;

              }
          }
    }

     return list ;

}

public static ArrayList<Long> allFactors(long n)
{
      ArrayList<Long> list = new ArrayList<>() ;

    for(long i = 1L; i*i <= n ;i++)
    {
          if( n % i == 0)
          {
              if(i*i == n)
              {
                    list.add(i) ;
              }
              else{
                    list.add(i) ;
                    list.add(n/i) ;

              }
          }
    }

     return list ;

}
////////////////////////////////////////////////////////////////////////////////////////////////////

  static final int MAXN = 10000001;

    static int spf[] = new int[MAXN];

    static void sieve()
    {
        spf[1] = 1;
        for (int i=2; i<MAXN; i++)

            spf[i] = i;

        for (int i=4; i<MAXN; i+=2)
            spf[i] = 2;

        for (int i=3; i*i<MAXN; i++)
        {

            if (spf[i] == i)
            {

                for (int j=i*i; j<MAXN; j+=i)

                    if (spf[j]==j)
                        spf[j] = i;
            }
        }
    }

// The above code works well for n upto the order of 10^7.
// Beyond this we will face memory issues.

// Time Complexity: The precomputation for smallest prime factor is done in O(n log log n)
// using sieve.
// Where as in the calculation step we are dividing the number every time by
// the smallest prime number till it becomes 1.
// So, let’s consider a worst case in which every time the SPF is 2 .
// Therefore will have log n division steps.

// Hence, We can say that our Time Complexity will be O(log n) in worst case.

    static Vector<Integer> getFactorization(int x)
    {
        Vector<Integer> ret = new Vector<>();
        while (x != 1)
        {
            ret.add(spf[x]);
            x = x / spf[x];
        }
        return ret;
    }

 //////////////////////////////////////////////////////////////////////////////////////////////////
 //////////////////////////////////////////////////////////////////////////////////////////////////

public static void merge(int arr[], int l, int m, int r)
    {
        // Find sizes of two subarrays to be merged
        int n1 = m - l + 1;
        int n2 = r - m;

        /* Create temp arrays */
        int L[] = new int[n1];
        int R[] = new int[n2];

        /*Copy data to temp arrays*/
        for (int i=0; i<n1; ++i)
            L[i] = arr[l + i];
        for (int j=0; j<n2; ++j)
            R[j] = arr[m + 1+ j];

        /* Merge the temp arrays */

        // Initial indexes of first and second subarrays
        int i = 0, j = 0;

        // Initial index of merged subarry array
        int k = l;
        while (i < n1 && j < n2)
        {
            if (L[i] <= R[j])
            {
                arr[k] = L[i];
                i++;
            }
            else
            {
                arr[k] = R[j];
                j++;
            }
            k++;
        }

        /* Copy remaining elements of L[] if any */
        while (i < n1)
        {
            arr[k] = L[i];
            i++;
            k++;
        }

        /* Copy remaining elements of R[] if any */
        while (j < n2)
        {
            arr[k] = R[j];
            j++;
            k++;
        }
    }

    // Main function that sorts arr[l..r] using
    // merge()
  public static void sort(int arr[], int l, int r)
    {
        if (l < r)
        {
            // Find the middle point
            int m = (l+r)/2;

            // Sort first and second halves
            sort(arr, l, m);
            sort(arr , m+1, r);

            // Merge the sorted halves
            merge(arr, l, m, r);
        }
    }

public static void sort(long arr[], int l, int r)
    {
        if (l < r)
        {
            // Find the middle point
            int m = (l+r)/2;

            // Sort first and second halves
            sort(arr, l, m);
            sort(arr , m+1, r);

            // Merge the sorted halves
            merge(arr, l, m, r);
        }
    }

public static void merge(long arr[], int l, int m, int r)
    {
        // Find sizes of two subarrays to be merged
        int n1 = m - l + 1;
        int n2 = r - m;

        /* Create temp arrays */
        long L[] = new long[n1];
        long R[] = new long[n2];

        /*Copy data to temp arrays*/
        for (int i=0; i<n1; ++i)
            L[i] = arr[l + i];
        for (int j=0; j<n2; ++j)
            R[j] = arr[m + 1+ j];

        /* Merge the temp arrays */

        // Initial indexes of first and second subarrays
        int i = 0, j = 0;

        // Initial index of merged subarry array
        int k = l;
        while (i < n1 && j < n2)
        {
            if (L[i] <= R[j])
            {
                arr[k] = L[i];
                i++;
            }
            else
            {
                arr[k] = R[j];
                j++;
            }
            k++;
        }

        /* Copy remaining elements of L[] if any */
        while (i < n1)
        {
            arr[k] = L[i];
            i++;
            k++;
        }

        /* Copy remaining elements of R[] if any */
        while (j < n2)
        {
            arr[k] = R[j];
            j++;
            k++;
        }
    }

 /////////////////////////////////////////////////////////////////////////////////////////

	public static long knapsack(int[] weight,long value[],int maxWeight){

        int n=  value.length ;

	//dp[i] stores the profit with KnapSack capacity "i"
  long []dp = new long[maxWeight+1];

    //initially profit with 0 to W KnapSack capacity is 0
    Arrays.fill(dp, 0);

    // iterate through all items
    for(int i=0; i < n; i++)

        //traverse dp array from right to left
        for(int j = maxWeight; j >= weight[i]; j--)
            dp[j] = Math.max(dp[j] , value[i] + dp[j - weight[i]]);

    /*above line finds out maximum of dp[j](excluding ith element value)
    and val[i] + dp[j-wt[i]] (including ith element value and the
    profit with "KnapSack capacity - ith element weight") */
    return dp[maxWeight];
	}

///////////////////////////////////////////////////////////////////////////////////////////
//////////////////////////////////////////////////////////////////////////////////////////

// to return max sum of any subarray in given array
public static long kadanesAlgorithm(long[] arr)
{
      long[] dp = new long[arr.length] ;

      dp[0] = arr[0] ;
      long max =  dp[0] ;

      for(int i = 1; i <  arr.length ; i++)
      {
            if(dp[i-1] > 0)
            {
                  dp[i] = dp[i-1] + arr[i] ;
            }
            else{
                  dp[i] = arr[i] ;
            }

            if(dp[i] >  max)max = dp[i] ;

      }

      return max  ;

}
/////////////////////////////////////////////////////////////////////////////////////////////
public static long kadanesAlgorithm(int[] arr)
{
      long[] dp = new long[arr.length] ;

      dp[0] = arr[0] ;
      long max =  dp[0] ;

      for(int i = 1; i <  arr.length ; i++)
      {
            if(dp[i-1] > 0)
            {
                  dp[i] = dp[i-1] + arr[i] ;
            }
            else{
                  dp[i] = arr[i] ;
            }

            if(dp[i] >  max)max = dp[i] ;

      }

      return max  ;

}

///////////////////////////////////////////////////////////////////////////////////////

/////////////////////////////////////////////////////////////////////////////////////////

public static long binarySerachGreater(int[] arr , int start , int end , int val)
{

      // fing total no of elements strictly grater than val in sorted array arr

      if(start >  end)return  0 ; //Base case

      int mid = (start + end)/2  ;

      if(arr[mid] <=val)
      {
          return binarySerachGreater(arr,mid+1, end ,val) ;

      }
      else{

         return binarySerachGreater(arr,start , mid -1,val) + end-mid+1 ;

      }

}

//////////////////////////////////////////////////////////////////////////////////
////////////////////////////////////////////////////////////////////////////////////

//TO GENERATE ALL(DUPLICATE ALSO EXIST) PERMUTATIONS OF A STRING

// JUST CALL generatePermutation( str,  start,  end) start :inclusive ,end : exclusive

//Function for swapping the characters at position I with character at position j
    public static String swapString(String a, int i, int j) {
        char[] b =a.toCharArray();
        char ch;
        ch = b[i];
        b[i] = b[j];
        b[j] = ch;
        return String.valueOf(b);
    }

//Function for generating different permutations of the string
    public static void generatePermutation(String str, int start, int end)
    {
        //Prints the permutations
        if (start == end-1)
            System.out.println(str);
        else
        {
            for (int i = start; i < end; i++)
            {
                //Swapping the string by fixing a character
                str = swapString(str,start,i);
                //Recursively calling function generatePermutation() for rest of the characters
                generatePermutation(str,start+1,end);
                //Backtracking and swapping the characters again.
                str = swapString(str,start,i);
            }
        }
    }

////////////////////////////////////////////////////////////////////////////////////////////////////
//////////////////////////////////////////////////////////////////////////////////////////////////////

public static long factMod(long n, long mod) {
    if (n <= 1) return 1;
    long ans = 1;
    for (int i = 1; i <= n; i++) {
      ans = (ans * i) % mod;
    }
    return ans;
  }

/////////////////////////////////////////////////////////////////////////////////////////////
//////////////////////////////////////////////////////////////////////////////////////////////////

public static long power(int x  ,int n)
    {
        //time comp : o(logn)

        if(n==0)return 1 ;
        if(n==1)return x;

        long ans =1L  ;

      while(n>0)
      {
          if(n % 2 ==1)
          {
              ans = ans *x ;
          }

          n /= 2 ;

          x =  x*x ;

      }

      return ans ;
    }

////////////////////////////////////////////////////////////////////////////////////////////////////
public static long powerMod(long x, long n, long mod) {
    //time comp : o(logn)

    if(n==0)return 1L ;
        if(n==1)return x;

    long ans = 1;
    while (n > 0) {
      if (n % 2 == 1) ans = (ans * x) % mod;
      x = (x * x) % mod;
      n /= 2;
    }
    return ans;
  }

//////////////////////////////////////////////////////////////////////////////////

/////////////////////////////////////////////////////////////////////////////////

/*
lowerBound - finds largest element equal or less than value paased
upperBound - finds smallest element equal or more than value passed

if not present return -1;

*/

public static long lowerBound(long[] arr,long k)
	{
		long ans=-1;

		int start=0;
		int end=arr.length-1;

		while(start<=end)
		{
			int mid=(start+end)/2;

			if(arr[mid]<=k)
			{
				ans=arr[mid];
				start=mid+1;
			}
			else
			{
				end=mid-1;
			}

		}

		return ans;

	}

	public static int lowerBound(int[] arr,int k)
	{
		int ans=-1;

		int start=0;
		int end=arr.length-1;

		while(start<=end)
		{
			int mid=(start+end)/2;

			if(arr[mid]<=k)
			{
				ans=arr[mid];
				start=mid+1;
			}
			else
			{
				end=mid-1;
			}

		}

		return ans;

	}

	public static long upperBound(long[] arr,long k)
	{
		long ans=-1;

		int start=0;
		int end=arr.length-1;

		while(start<=end)
		{
			int mid=(start+end)/2;

			if(arr[mid]>=k)
			{
				ans=arr[mid];
				end=mid-1;
			}
			else
			{
				start=mid+1;
			}

		}

		return ans;
	}

	public static int upperBound(int[] arr,int k)
	{
		int ans=-1;

		int start=0;
		int end=arr.length-1;

		while(start<=end)
		{
			int mid=(start+end)/2;

			if(arr[mid]>=k)
			{
				ans=arr[mid];
				end=mid-1;
			}
			else
			{
				start=mid+1;
			}

		}

		return ans;
	}

//////////////////////////////////////////////////////////////////////////////////////////

public static void printArray(int[] arr)
{
    for(int i = 0  ; i  < arr.length ; i++)
    {
        out.print(arr[i] +" ") ;
    }
    out.println() ;
}

public static void printArray(long[] arr)
{
    for(int i = 0  ; i  < arr.length ; i++)
    {
        out.print(arr[i] +" ") ;
    }
    out.println() ;
}

/////////////////////////////////////////////////////////////////////////////////////
////////////////////////////////////////////////////////////////////////////////////////////
////////////////////////////////////////////////////////////////////////////////////////////

static ArrayList<Integer>[] tree ;
static long[] child;
static int mod= 1000000007 ;
static int[][] pre  = new int[3001][3001];
static int[][] suf = new int[3001][3001] ;

//program to calculate noof nodes in subtree for every vertex including itself

// static void dfs(int sv)
// {
//     child[sv] = 1L;

//     for(Integer x : tree[sv])
//     {
//         if(child[x] == 0)
//         {

//           dfs(x) ;

//           child[sv] += child[x] ;
//         }
//     }
// }

//////////////////////////////////////////////////////////////////////////////////////////////
//////////////////////////////////////////////////////////////////////////////////////////
////////////////////////////////////////////////////////////////////////////////////////////

public static void solve()
{
FastReader scn = new FastReader() ;

//int[] store = {2 ,3, 5 , 7  ,11 , 13 , 17 , 19 , 23 , 29 , 31 , 37 } ;

// product of first 11 prime nos is greater than 10 ^ 12;

//ArrayList<Integer> arr[] = new ArrayList[n] ;
ArrayList<Integer> list = new ArrayList<>() ;
ArrayList<Long> listl = new ArrayList<>() ;
//ArrayList<Integer> lista = new ArrayList<>() ;
//ArrayList<Integer> listb = new ArrayList<>() ;
//ArrayList<String> lists = new ArrayList<>() ;

HashMap<Integer,Integer> map = new HashMap<>() ;
//HashMap<Long,Long> map = new HashMap<>() ;
HashMap<Integer,Integer> map1  = new HashMap<>() ;
HashMap<Integer,Integer> map2  = new HashMap<>() ;
//HashMap<String,Integer> maps = new HashMap<>() ;
//HashMap<Integer,Boolean> mapb = new HashMap<>() ;
//HashMap<Point,Integer> point = new HashMap<>() ;

 Set<Integer> set = new HashSet<>() ;
 Set<Integer> setx = new HashSet<>() ;
 Set<Integer> sety = new HashSet<>() ;

StringBuilder sb =new StringBuilder("") ;

//Collections.sort(list);

//if(map.containsKey(arr[i]))map.put(arr[i] , map.get(arr[i]) +1 ) ;
//else map.put(arr[i],1) ;

// if(map.containsKey(temp))map.put(temp , map.get(temp) +1 ) ;
// else map.put(temp,1) ;

//int bit  =Integer.bitCount(n);
// gives total no of set bits in n;

// Arrays.sort(arr, new Comparator<Pair>() {
// 			@Override
// 			public int compare(Pair a, Pair b) {
// 				if (a.first != b.first) {
// 					return a.first - b.first; // for increasing order of first
// 				}
// 				return a.second - b.second ; //if first is same then sort on second basis
// 			}
// 		});

int testcase = 1;

 // testcase = scn.nextInt() ;

while(testcase-- > 0)
{

 //if(map.containsKey(arr[i]))map.put(arr[i],map.get(arr[i])+1) ;else map.put(arr[i],1) ;
 //if(map.containsKey(temp))map.put(temp,map.get(temp)+1) ;else map.put(temp,1) ;

// tree = new ArrayList[n] ;

// child  = new long[n] ;

// for(int i = 0; i< n; i++)
// {
//     tree[i] = new ArrayList<Integer>();
// }

int n = scn.nextInt() ;
//int m = scn.nextInt() ;
//int k = scn.nextInt() ;

// long n  = scn.nextLong() ;
//long a = scn.nextLong() ;
int[] arr =  new int[n] ; for(int i = 0 ; i < arr.length ; i++)arr[i] = scn.nextInt() ;
//long b = scn.nextLong() ;
//long[] arr = new long[n] ; for(int i = 0 ; i < n ;i++)arr[i] = scn.nextLong() ;

sort(arr, 0 , n-1) ;

for(int i = 0 ; i < n; i++)
{
    if(i == 0)out.print(1+" ") ;
    else  out.println(arr[i-1]+" ") ;
}

//out.println() ;

//out.println(ans) ;

//out.println(ans) ;

//out.println() ;

//for(int i = 0; i < n; i++)out.print(arr[i]+ " ") ;

// for(int i = 0; i < arr.length ; i++)
//  {
//      for(int j = 0; j < arr[0].length ; j ++)
//      {
//          out.print(arr[i][j] +" ");
//      }
//      out.println() ;
//   }

sb.delete(0 , sb.length()) ;
list.clear() ;
map.clear() ;
map1.clear() ;
map2.clear() ;
set.clear() ;

} // test case  end loop

out.flush() ;
} // solve fn ends

public static void main (String[] args) throws java.lang.Exception
{

solve() ;

}

}

 class Pair
{
  int first ;

  int second  ;

@Override
	public String toString() {

	String ans = "" ;
	ans  += this.first ;
	ans += " ";
	ans += this.second ;

	return ans  ;
	}

}