#include<bits/stdc++.h> using namespace std; using ll = long long int; using lc = complex<double>; int main(void) { constexpr ll MOD = 1e9 + 7; constexpr double PI = acos(-1); cout << fixed << setprecision(32); cin.tie(0); ios::sync_with_stdio(false); ll n; cin >> n; vector<vector<ll>> dp(n+1, vector<ll>(1e4+1)); for(ll i=0; i<n; i++) { ll y; cin >> y; dp[i+1][0] = dp[i][0] + abs(y); for(ll j=1; j<=1e4; j++) dp[i+1][j] = min(dp[i+1][j-1], dp[i][j] + abs(y-j)); } cout << *min_element(dp[n].begin(), dp[n].end()) << endl; }