#include #pragma GCC optimize("O3") using namespace std; using ll = long long; #define rep(i,n) for (int i = 0; i < (n); ++i) #define rep2(i,m,n) for (int i = (m); i < (n); ++i) #define rep3(i,a,b) for (int i = (a); i >= (b); --i) #define all(x) (x).begin(),(x).end() inline int popcount(const int x) { return __builtin_popcount(x);} inline ll popcount(const ll x) { return __builtin_popcountll(x);} template void chmin(T &a, const T &b) noexcept { if (b < a) a = b;} template void chmax(T &a, const T &b) noexcept { if (a < b) a = b;} template void drop(const T &x) { std::cout< void debug_out(const T &x, const Args &... args) { std::cout<> n; vector Y(n); rep(i,n) cin >> Y[i]; vector > dp(n+1, vector(10001, INF)); //i番目の高さをjにしたときの総和のmin dp[0][0] = 0; rep(i, n) { vector cul = dp[i]; rep2(j, 1, 10001) chmin(cul[j], cul[j-1]); rep(j, 10001) { chmin(dp[i+1][j], cul[j] + llabs(Y[i] - j)); } } ll ans = INF; rep(i, 10001) chmin(ans, dp[n][i]); cout << ans << endl; return 0; }