N = int(input()) Y = list(map(int, input().split())) M = 10005 inf = 10 ** 18 pre = [0] * M Acp = [0] * (M + 1) for i in range(N): dp = [0] * M Ac = [inf] * (M + 1) for y in range(M): dp[y] = Acp[y + 1] + abs(y - Y[i]) Ac[y + 1] = min(Ac[y], dp[y]) dp, pre = pre, dp Acp, Ac = Ac, Acp print(min(pre))