#include <bits/stdc++.h>
const int MEMORY_LIMIT_MB = 50;
const int TIME_LIMIT_S = 1;
const char input_filename[] = "";
const char output_filename[] = "";
using namespace std;
template <typename T, typename U>
inline ostream &operator<<(ostream &out, const pair<T, U> &p) {
  out << p.first << ' ' << p.second;
  return out;
}
template <typename T, typename U>
inline istream &operator>>(istream &in, pair<T, U> &p) {
  in >> p.first >> p.second;
  return in;
}
template <typename T>
inline ostream &operator<<(ostream &out, const vector<T> &v) {
  if (v.empty()) return out;
  out << v.front();
  for (auto it = ++v.begin(); it != v.end(); ++it) out << ' ' << *it;
  return out;
}
template <typename T>
inline istream &operator>>(istream &in, vector<T> &v) {
  for (auto &i : v) in >> i;
  return in;
}
class Reader {
 public:
  inline Reader(const string &filename) {
    if (not filename.empty())
      assert(freopen(filename.c_str(), "r", stdin) != nullptr);
  }
  template <typename T>
  inline void operator()(T &x) {
    cin >> x;
  }
  template <typename T, typename... Args>
  inline void operator()(T &x, Args &...args) {
    operator()(x), operator()(args...);
  }
  template <typename T>
  inline T r() {
    T x;
    cin >> x;
    return x;
  }
};
Reader rd(input_filename);
class Printer {
 public:
  inline Printer(const string &filename) {
    if (not filename.empty())
      assert(freopen(filename.c_str(), "w", stdout) != nullptr);
  }
  template <typename T>
  inline void p(const T x) {
    cout << x;
  }
  template <typename T, typename... Args>
  inline void p(const T x, const Args... args) {
    p(x), p(args...);
  }
  inline void operator()() { p('\n'); }
  template <typename T>
  inline void operator()(const T x) {
    p(x), p('\n');
  }
  template <typename T, typename... Args>
  inline void operator()(const T x, const Args... args) {
    p(x), p(' '), operator()(args...);
  };
  inline void f() { cout.flush(); }
};
Printer pr(output_filename);
const int N = 3002;
long long a[N];
long long dp[N][N];
inline void mainFunction() {
  int n;
  rd(n);
  const long long INF = 228228228228228ll;
  fill((long long *)dp, (long long *)dp + N * N, INF);
  for (auto i = 1; i < n + 1; ++i) {
    rd(a[i]);
  }
  for (int i = 0; i <= n; ++i) {
    dp[0][i] = 0;
  }
  for (int i = 1; i <= n; ++i) {
    vector<pair<long long, long long>> v;
    v.reserve(N);
    for (int j = 1; j <= n; ++j) {
      v.push_back({a[j] + ((i - 1) - j), dp[i - 1][j]});
    }
    sort(v.begin(), v.end());
    for (int j = 1; j < n; ++j) {
      v[j].second = min(v[j].second, v[j - 1].second);
    }
    for (int j = 1; j <= n; ++j) {
      dp[i][j] =
          (--lower_bound(v.begin(), v.end(), make_pair(a[j] + (i - j), -1ll)))
              ->second +
          abs(a[i] - (a[j] + (i - j)));
    }
  }
  long long ans = INF;
  for (int i = 1; i <= n; ++i) {
    ans = min(ans, dp[n][i]);
  }
  pr(ans);
}
class Solution {
 public:
  void solve() {
    cin.tie(nullptr);
    ios_base::sync_with_stdio(false);
    return mainFunction();
  }
};
int main() {
  auto _s = new Solution;
  _s->solve();
  delete _s;
}
