#include<bits/stdc++.h>
using namespace std;
using ll = long long;
using ld = long double;
using P = pair<ll,ll>;
using vl = vector<ll>;
using Map = map<ll,ll>;
using Tup = tuple<ll,ll,ll>;
using vvl = vector<vector<ll>>;
#define all(v) v.begin(), v.end()
#define prt(v) cout<<(v)<<"\n";
#define fl cout<<flush;
#define fi(v) get<0>(v)
#define se(v) get<1>(v)
#define th(v) get<2>(v)
#define endl "\n"
template <typename T> bool chmax(T &a, const T &b){if (a<b){a=b;return 1;}return 0;}
template <typename T> bool chmin(T &a, const T &b){if (a>b){a=b;return 1;}return 0;}
const ll INF=1LL<<60;
const ll MOD=1000000007;
const ll MOD2=998244353;
const ld pi=3.141592653589793238;
int N;
vector<int> Y(1003,0);

signed main(void){
    cin.tie(0);cout.tie(0);ios::sync_with_stdio(false);
    cin >> N;
    for(int i=0;i<N;++i)cin>>Y[i];
    //dp[i][j]はY[i]までを見て、最後jの最小コスト
    vector<vector<ll>> dp(N, vector<ll>(10001, INF));
    for(ll j=0;j<10001;++j){
        dp[0][j]=llabs(Y[0]-j);
    }
    for(ll i=1;i<N;++i){
        for(ll j=0;j<10001;++j){
            if(j>0)
            chmin(dp[i][j],dp[i][j-1]-llabs(Y[i]-(j-1))+llabs(Y[i]-j));
            chmin(dp[i][j],dp[i-1][j]+llabs(Y[i]-j));
        }
    }
    ll ans=INF;
    for(ll i=0;i<10001;++i)chmin(ans,dp[N-1][i]);
    prt(ans)fl

    return 0;
}