n = int(input()) y = list(map(int, input().split())) INF = 10 ** 9 ans = 10 ** 18 dp = [[INF] * (10 ** 4 + 1) for i in range(n + 1)] dp[0][0] = 0 for i in range(n): ru = [INF] * (10 ** 4 + 2) for height in range(10 ** 4 + 1): ru[height + 1] = min(ru[height], dp[i][height]) for height in range(10 ** 4 + 1): dp[i + 1][height] = ru[height + 1] + abs(height - y[i]) print(min(dp[-1]))