#include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include using ll=long long; #define int ll #define rng(i,a,b) for(int i=int(a);i=int(a);i--) #define per(i,b) gnr(i,0,b) #define eb emplace_back #define all(x) x.begin(),x.end() #define SZ(x) ((int)x.size()) #define fi first #define se second const int INF = 1e15; using namespace std; template using vc=vector; template using vvc=vc>; using pi=pair; using vi=vc; template inline bool chmax(T &a,T b){if(a inline bool chmin(T &a,T b){if(a>b){a=b;return true;}return false;} signed main() { cin.tie(0); ios::sync_with_stdio(0); cout<> N; int Y[N]; rep(i,N) cin >> Y[i]; vvc dp(N+1,vi(11000,INF)); dp[0][0]=0; rep(i,N) { vi a(11000,INF); a[0]=dp[i][0]; rng(j,1,11000) a[j]=min(a[j-1],dp[i][j]); rep(j,11000) { chmin(dp[i+1][j],abs(Y[i]-j)+a[j]); } } int ans=INF; rep(i,11000) chmin(ans,dp[N][i]); cout << ans << endl; }