#include #define rep(i,n) for(ll i=0;i<(int)(n);i++) using namespace std; using ll = long long ; using P = pair ; using pll = pair; constexpr int INF = 1e9; constexpr long long LINF = 1e17; constexpr int MOD = 1000000007; constexpr double PI = 3.14159265358979323846; const ll MX = 10005; int main(){ ll n; cin >> n; vector y(n); rep(i,n) cin >> y[i]; vector> dp(n+1,vector(MX,0)); for(ll i=1;i<=n;i++){ ll mn = INF; rep(j,MX){ mn = min(mn,dp[i-1][j]); dp[i][j] = mn + abs(y[i-1] - j); } } ll ans = INF; rep(j,MX){ ans = min(ans,dp[n][j]); } cout << ans << endl; return 0; }