#include <bits/stdc++.h>
using namespace std;
const int MAXN = 5000 + 10;
int n, a[MAXN], b[MAXN];
long long dp[2][MAXN];
int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
  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);
  dp[0][1] = abs(a[1] - b[1]);
  for (int i = 2; i <= n; i++) {
    dp[0][i] = min(dp[0][i - 1], 1LL * abs(a[1] - b[i]));
  }
  for (int i = 2; i <= n; i++) {
    dp[1][1] = dp[0][1] + abs(a[i] - b[1]);
    for (int j = 2; j <= n; j++) {
      dp[1][j] = min(dp[1][j - 1], dp[0][j] + abs(a[i] - b[j]));
    }
    for (int i = 1; i <= n; i++) {
      dp[0][i] = dp[1][i];
    }
  }
  cout << dp[1][n];
  return 0;
}
