#include <bits/stdc++.h>
using namespace std;
int n, a[3005], w[3005], valm;
long long b[3005], w2[3005], ans;
bool check[3005];
int main() {
  scanf("%d", &n);
  for (int i = (int)(1); i <= (int)(n); ++i) {
    scanf("%d", &a[i]);
    valm = max(valm, a[i]);
  }
  for (int i = (int)(1); i <= (int)(n); ++i) b[i] = (long long)valm + i - 1;
  w2[0] = (long long)1000000000007;
  while (1) {
    int id = 0;
    int val = 0;
    int val2 = 0;
    for (int i = (int)(1); i <= (int)(n); ++i) {
      w[i] = w[i - 1] + (b[i] > a[i] ? 1 : -1);
      w2[i] = min(w2[i - 1],
                  (b[i] > a[i] ? b[i] - a[i] : (long long)1000000000007));
    }
    for (int i = (int)(n); i >= (int)(1); --i) {
      if (b[i] > a[i]) {
        if (!id && w[i] > 0) {
          id = i;
          val = 0;
          val2 = 0;
        } else if (id && w[i] > 0 && val > val2) {
          id = i;
          val = val2 = 0;
        }
        ++val2;
      } else
        ++val;
    }
    if (id)
      for (int i = (int)(1); i <= (int)(id); ++i) b[i] = b[i] - w2[id];
    else
      break;
  }
  for (int i = (int)(1); i <= (int)(n); ++i) ans = ans + abs(a[i] - b[i]);
  cout << ans;
  return 0;
}
