#include using namespace std; #define rep(i,n) for(int i = 0; i < (n);i++) #define sz(x) int(x.size()) typedef long long ll; typedef long double ld; typedef pair P; constexpr int INF = 2e9; constexpr int AMAX = 1001; int main() { int n; cin >> n; vector a(n); rep(i,n) cin >> a[i]; vector dp(AMAX, INF); dp[0] = 0; for (int i = 0; i < n; i++) { vector cum(AMAX + 1, INF); for (int j = 0; j < AMAX; j++) { cum[j + 1] = min(cum[j], dp[j]); } for (int j = 0; j < AMAX; j++) { dp[j] = cum[j + 1]; if (dp[j] != INF) dp[j] += abs(j - a[i]); } } int res = INF; for (int i = 0; i < AMAX; i++) res = min(res, dp[i]); cout << res << endl; return 0; }