#include #define rep(i,n) for(int i=(0);i<(n);i++) using namespace std; typedef long long ll; typedef long double ld; template bool chmax(T &a, const T &b) { if (a bool chmin(T &a, const T &b) { if (a>b) { a=b; return 1; } return 0; } int main(){ cin.tie(0); ios::sync_with_stdio(false); int n; cin >> n; vector y(n); rep(i, n) cin >> y[i]; int max_y = 10101; ll dp[2][max_y]; rep(i, 2) rep(j, max_y) dp[i][j] = 0; rep(i, n){ ll mn = 1e15; rep(j, max_y){ chmin(mn, dp[i%2][j]); dp[(i+1)%2][j] = mn + abs(j - y[i]); } } ll ans = 1e15; rep(i, max_y) chmin(ans, dp[n%2][i]); cout << ans << endl; }