n = int(input()) Y = [0] + list(map(int, input().split())) # 1-index INF = 10 ** 18 dp = [[INF] * 10010 for _ in range(n + 1)] dp[0][0] = 0 for i in range(1, n + 1): mn = 10 ** 18 # temp_min for j in range(10010): # 実際はmax(Y)まで回せば十分 mn = min(mn, dp[i - 1][j]) # 最小値の更新 dp[i][j] = mn + abs(Y[i] - j) # 遷移 print(min(dp[n]))