#include <bits/stdc++.h>
using namespace std;
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];
long long 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) {
  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 = ((x->l) ? (x->l->size) : (0)) + ((x->r) ? (x->r->size) : (0)) + 1;
  if (((x->l) ? (x->l->dis) : (-1)) < ((x->r) ? (x->r->dis) : (-1))) {
    node *t = x->l;
    x->l = x->r;
    x->r = t;
  }
  x->dis = ((x->r) ? (x->r->dis) : (-1)) + 1;
  return x;
}
PI Merge(PI x, PI y) {
  PI ans;
  ans.first = merge(x.first, y.first, 1);
  ans.second = x.second + y.second;
  while (((ans.first) ? (ans.first->size) : (0)) > ((ans.second + 1) >> 1)) {
    ans.first = merge((ans.first)->l, (ans.first)->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.first = p;
    now.second = 1;
    while (tot && (Q[tot].first->key) > (now.first->key)) {
      now = Merge(Q[tot--], now);
    }
    Q[++tot] = now;
  }
  int cur = 1;
  for (int i = 1; i <= tot; i++) {
    int ret = Q[i].first->key;
    for (int j = 0; j < Q[i].second; j++)
      ans += (long long)((ret - a[j + cur]) > 0 ? (ret - a[j + cur])
                                                : (-(ret - a[j + cur])));
    cur += Q[i].second;
  }
  cout << ans << endl;
  return 0;
}
