#include #define rep(i,n) for (int i = 0; i < (n); i ++) using namespace std; using ll = long long; using PL = pair; using P = pair; constexpr int INF = 1000000000; constexpr long long HINF = 1000000000000000; constexpr long long MOD = 1000000007; constexpr double EPS = 1e-4; constexpr double PI = 3.14159265358979; constexpr int H = 20000; int main() { int N; cin >> N; vector Y(N); rep(i,N) cin >> Y[i]; vector> dp(N + 1,vector(H,INF)); rep(i,N) { if (i == 0) { rep(j,H) { if (j == 0) dp[i + 1][j] = abs(j - Y[i]); else dp[i + 1][j] = min(dp[i + 1][j - 1],abs(j - Y[i])); } } else { rep(j,H) { if (j == 0) dp[i + 1][j] = dp[i][j] + abs(j - Y[i]); else dp[i + 1][j] = min(dp[i + 1][j - 1],dp[i][j] + abs(j - Y[i])); } } } ll ans = HINF; rep(i,H) { ans = min(ans,dp[N][i]); } cout << ans << endl; return 0; }