#include using namespace std; #define REP(i,a,n) for(int i=(a); i<(int)(n); i++) #define rep(i,n) REP(i,0,n) #define FOR(it,c) for(__typeof((c).begin()) it=(c).begin(); it!=(c).end(); ++it) #define ALLOF(c) (c).begin(), (c).end() typedef long long ll; typedef unsigned long long ull; static const int INF = 1e9; int dp[1005][10005]; int main(){ int N; cin >> N; vector v; rep(i,N){ int a; cin >> a; v.push_back(a); } rep(i,1005) rep(j,10005) dp[i][j] = INF; rep(i,10005){ dp[0][i] = abs(i - v[0]); } REP(i,1,N){ int mn = dp[i-1][0]; rep(j,10005){ mn = min(mn, dp[i-1][j]); dp[i][j] = abs(j - v[i]) + mn; } } int ret = dp[N-1][0]; rep(i,10005){ ret = min(ret, dp[N-1][i]); } cout << ret << endl; return 0; }