def main(): N = int(input()) Y = list(map(int, input().split())) dp = [0] * (10 ** 4 + 1) for i in range(N): t = float('inf') for j in range(10 ** 4 + 1): t = min(t, dp[j]) dp[j] = t + abs(Y[i] - j) print(min(dp)) main()