#include #ifdef _DEBUG #include "debug.hpp" #else #define debug(...) #endif #define REP(i, m, n) for(int i = (int)(m); i < (int)(n); ++i) #define rep(i, n) REP(i, 0, n) using namespace std; using ll = long long; using ld = long double; using pll = pair; template inline bool chmax(T &a, const U &b) { if(a < b) { a = b; return true; } return false; } template inline bool chmin(T &a, const U &b) { if(a > b) { a = b; return true; } return false; } int n, y[1000], dp[1010][10100]; int main() { cin.tie(0); ios::sync_with_stdio(false); cin >> n; rep(i, n) cin >> y[i]; rep(i, 1010) rep(j, 10100) dp[i][j] = (1<<30); dp[0][0] = 0; REP(i, 1, n+1) { int mn = (1<<30); rep(j, 10001) { chmin(mn, dp[i-1][j]); dp[i][j] = mn+abs(y[i]-j); } } int ans = (1<<30); rep(j, 10100) chmin(ans, dp[n-1][j]); cout << ans << '\n'; return 0; }