N = int(input()) Y = list(map(int,input().split())) import sys if N == 1: print(0) exit() C = 10 ** 4 inf = 10 ** 10 dp = [[inf] * (C+1) for _ in range(N)] for i in range(C+1): dp[0][i] = abs(i-Y[0]) for i in range(N-1): _min = inf for j in range(C+1): _min = min(_min,dp[i][j]) dp[i+1][j] = _min + abs(j - Y[i+1]) print(min(dp[-1]))