#include <bits/stdc++.h>
using namespace std;
int n, a[100005];
priority_queue<pair<int, int> > pq;
vector<pair<int, int> > lst;
int main() {
  iostream::sync_with_stdio(0);
  cin >> n;
  long long sum = 0;
  for (int i = 0; i < n; i++) cin >> a[i], a[i] += (int)1e5 - i;
  for (int i = 0; i < n; i++) {
    sum += a[i];
    int delta = 0;
    while (pq.size() && delta != 1) delta += pq.top().second, pq.pop();
    pq.push(pair<int, int>(1, -1));
    pq.push(pair<int, int>(a[i] + 1, 1));
    pq.push(pair<int, int>(a[i] + 1, 1));
  }
  while (pq.size()) {
    lst.push_back(pq.top());
    pq.pop();
  }
  reverse(lst.begin(), lst.end());
  int last = 0;
  long long ans = (long long)sum;
  int delta = 0;
  lst.push_back(pair<int, int>((int)1e9 + 1e5 - 1, 0));
  for (int i = 0; i < (int)lst.size() - 1; i++) {
    int en = i;
    for (; en < lst.size() - 1; en++)
      if (lst[en].first != lst[i].first) break;
    en--;
    sum += 1ll * delta * (lst[i].first - last - 1);
    ans = min(ans, sum);
    for (int j = i; j <= en; j++) delta += lst[j].second;
    sum += delta;
    ans = min(ans, sum);
    i = en;
    last = lst[i].first;
  }
  cout << ans;
}
