#include <bits/stdc++.h>
using namespace std;
int a[3333], Last[3333], Next[3333], n;
pair<long long, long long> dp[3333], b[3333];
int getfa(int fa[], int u) {
  return u <= 0 || u > n || u == fa[u] ? u : fa[u] = getfa(fa, fa[u]);
}
template <typename T>
bool umin(T &a, T b) {
  if (b < a) {
    a = b;
    return 1;
  }
  return 0;
}
int main() {
  cin >> n;
  for (int i = 1; i <= n; i++) cin >> a[i], a[i] -= i;
  memset(dp, 0x3f, sizeof(dp));
  dp[0] = make_pair(0, -1e9 - 7);
  for (int i = 0; i < n; i++) {
    for (int j = i + 1; j <= n; j++)
      b[j] = make_pair(a[j], j), Last[j] = Next[j] = j;
    sort(b + i + 1, b + n + 1);
    int midl = i + 1 + n >> 1, midr = midl + ((n - i) % 2 == 0);
    long long cur = 0;
    for (int j = i + 1; j <= n; j++) cur += abs(b[j].first - b[midl].first);
    for (int j = n; j > i; j--) {
      if (dp[i].second < b[midr].first)
        umin(dp[j], make_pair(dp[i].first + cur,
                              max(b[midl].first, dp[i].second + 1)));
      int pos =
          lower_bound(b + i + 1, b + n + 1, make_pair(1ll * a[j], 1ll * j)) - b;
      Last[pos] = pos > i + 1 ? pos - 1 : 0;
      Next[pos] = pos + 1;
      int cnt = j - i;
      if (cnt % 2 == 0) {
        if (pos <= midl)
          midl = getfa(Next, midl + 1), cur -= b[midl].first - b[pos].first;
        else
          cur -= b[pos].first - b[midl].first;
        midr = midl;
      } else {
        int buf = midl;
        if (pos >= midl)
          midl = getfa(Last, midl - 1),
          cur += b[buf].first - b[midl].first - (b[pos].first - b[midl].first);
        else
          cur -= b[midl].first - b[pos].first;
        midr = getfa(Next, midl + 1);
      }
    }
  }
  cout << dp[n].first << endl;
  return 0;
}
