#include <bits/stdc++.h>
using namespace std;
const int N = 10005;
const int M = 400007;
const int inf = 0x3f3f3f3f;
struct E {
  int fr, to, next, cap, c;
  E(int fr = 0, int to = 0, int next = 0, int cap = 0, int c = 0)
      : fr(fr), to(to), next(next), cap(cap), c(c) {}
} edge[M << 1];
int head[N], S, T, tot = 1;
void add(int x, int y, int cap, int c) {
  edge[++tot] = E(x, y, head[x], cap, c);
  head[x] = tot;
  edge[++tot] = E(y, x, head[y], 0, -c);
  head[y] = tot;
}
queue<int> Q;
int dis[N], inq[N], p[N], f[N];
bool spfa() {
  memset(inq, 0, sizeof(inq));
  memset(dis, 0x3f, sizeof(dis));
  dis[S] = 0;
  Q.push(S);
  inq[S] = 1;
  f[S] = inf;
  while (!Q.empty()) {
    int u = Q.front();
    Q.pop();
    inq[u] = 0;
    for (int i = head[u]; i; i = edge[i].next)
      if (edge[i].cap) {
        int v = edge[i].to;
        int w = edge[i].c;
        if (dis[u] + w < dis[v]) {
          dis[v] = dis[u] + w;
          p[v] = i;
          f[v] = min(f[u], edge[i].cap);
          if (!inq[v]) {
            inq[v] = 1;
            Q.push(v);
          }
        }
      }
  }
  return dis[T] < inf;
}
long long mfmc() {
  long long cost = 0;
  while (spfa()) {
    int now = T;
    while (p[now]) {
      edge[p[now]].cap -= f[T];
      edge[p[now] ^ 1].cap += f[T];
      cost += f[T] * edge[p[now]].c;
      int u = edge[p[now]].fr;
      now = u;
    }
  }
  return cost;
}
int n, a[N], b[N];
int main() {
  scanf("%d", &n);
  for (int i = 1; i <= (n); i++) scanf("%d", &a[i]);
  for (int i = 1; i <= (n - 1); i++) b[i] = a[i + 1] - a[i];
  S = n, T = n + 1;
  for (int i = 1; i <= (n - 1); i++) {
    if (i - 1 >= 1) add(i, i - 1, inf, 1);
    if (i + 1 <= n - 1) add(i, i + 1, inf, 1);
  }
  for (int i = 1; i <= (n - 1); i++) {
    if (b[i] > 1)
      add(S, i, b[i] - 1, 0);
    else if (b[i] < 1)
      add(i, T, -b[i] + 1, 0);
  }
  add(S, 1, inf, 1);
  add(S, n - 1, inf, 1);
  long long ans = mfmc();
  printf("%I64d\n", ans);
}
