#include <cstdio>
#include <algorithm>
#include <cstring>
#include <iostream>
#include <cstdlib>
#include <cmath>
#include <queue>
#define ll long long
#define INF 1000000000
#define For(i,a,b) for(int i=a;i<=b;++i)
#define p(x) ('0'<=x&&x<='9')
char cc; int C;
template <class T>
void read( T &x )
{
x=0; C=1; cc=getchar();
while(!p(cc)) { if(cc=='-') C=-1; cc=getchar(); }
while(p(cc)) { x=x*10+cc-48; cc=getchar(); }
x*=C;
}
#undef p
using namespace std;
#define N 1000010
struct node
{
int c[2],val,dep;
node() { c[0]=c[1]=val=0; dep=1; }
int& operator [] (const int &x) { return c[x]; }
}pool[N];
queue<int> q;
int root[N],siz[N],_siz[N],tot,pcnt;
int merge(int x,int y)
{
if(!x||!y) return (x+y);
if(pool[x].val<pool[y].val) swap(x,y);
pool[x][1]=merge(pool[x][1],y);
if(pool[pool[x][0]].dep<pool[pool[x][1]].dep) swap(pool[x][1],pool[x][0]);
pool[x].dep=pool[pool[x][1]].dep+1;
return x;
}
int pop(int &x) { q.push(x); x=merge(pool[x][0],pool[x][1]); }
int getpt()
{
static int ret;
if( q.empty() ) ret=++pcnt;
else { ret=q.front(); q.pop(); };
pool[ret]=node();
return ret;
}
int z[N],n,w[N];
ll ans;
void init()
{
while(!q.empty()) q.pop();
read(n);
For(i,1,n) read(z[i]),z[i]-=i;
pool[0].dep=0;
}
int main()
{
int node=1;
init();
For(i,1,n)
{
root[++tot]=getpt(); pool[root[tot]].val=w[tot]=z[i];
siz[tot]=_siz[tot]=1;
while(w[tot]<w[tot-1]&&tot>1)
{
root[tot-1]=merge(root[tot-1],root[tot]);
siz[tot-1]+=siz[tot]; _siz[tot-1]+=_siz[tot];
tot--;
while(_siz[tot] != (siz[tot]>>1)+(siz[tot]&1)) pop(root[tot]),_siz[tot]--;
w[tot]=pool[root[tot]].val;
}
}
For(i,1,tot)
{
for(;siz[i];siz[i]--) ans+=abs(z[node++]-w[i]);
}
printf("%lld",ans);
return 0;
}