from itertools import accumulate N = int(input()) A = list(map(int, input().split())) U = 10 ** 4 + 10 dp = [i for i in range(U)] for a in A: dp = list(accumulate(dp, func=min)) dp = [x + abs(i - a) for i, x in enumerate(dp)] print(min(dp))