#include <bits/stdc++.h>
using namespace std;
const long long INF = (long long)1e18 + 7;
long long a[3005];
pair<long long, long long> dp[3005];
multiset<long long> small, big;
int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  int n;
  cin >> n;
  for (int i = 1; i <= n; i++) cin >> a[i];
  dp[0] = make_pair(0, -INF);
  for (int i = 1; i <= n; i++) {
    long long S = 0, B = 0;
    small.clear(), big.clear();
    dp[i] = make_pair(INF, INF);
    for (int j = i; j > 0; j--) {
      long long A = a[j] - (long long)j;
      if (small.empty() || *small.rbegin() > A)
        small.insert(A), S += A;
      else
        big.insert(A), B += A;
      if ((int)small.size() - (int)big.size() > 1) {
        long long T = *small.rbegin();
        small.erase(small.find(T));
        big.insert(T);
        S -= T, B += T;
      }
      if ((int)small.size() < (int)big.size()) {
        long long T = *big.begin();
        big.erase(big.find(T));
        small.insert(T);
        S += T, B -= T;
      }
      long long M = *small.rbegin();
      if (dp[j - 1].second < M + (long long)j)
        dp[i] =
            min(dp[i], make_pair(dp[j - 1].first + (long long)small.size() * M -
                                     S + B - (long long)big.size() * M,
                                 M + (long long)i));
    }
  }
  cout << dp[n].first;
  return 0;
}
