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