#define _USE_MATH_DEFINES
#include <bits/stdc++.h>
using namespace std;

//template
#define rep(i,a,b) for(int i=(int)(a);i<(int)(b);i++)
#define ALL(v) (v).begin(),(v).end()
typedef long long int ll;
const int inf = 0x3fffffff; const ll INF = 0x1fffffffffffffff; const double eps=1e-12;
template<typename T>inline bool chmax(T& a,T b){if(a<b){a=b;return 1;}return 0;}
template<typename T>inline bool chmin(T& a,T b){if(a>b){a=b;return 1;}return 0;}
//end

const int m=10101;
int dp[m];

int main(){
   int n; cin>>n;
   vector<int> a(n);
   rep(i,0,n)cin>>a[i];
   rep(i,0,m)dp[i]=inf;
   dp[0]=0;
   rep(i,0,n){
      rep(j,1,m)chmin(dp[j],dp[j-1]);
      rep(k,0,m)dp[k]+=abs(k-a[i]);
   }
   int res=inf;
   rep(i,0,m)chmin(res,dp[i]);
   cout<<res<<endl;
   return 0;
}