import sys readline = sys.stdin.readline readall = sys.stdin.read ns = lambda: readline().rstrip() ni = lambda: int(readline().rstrip()) nm = lambda: map(int, readline().split()) nl = lambda: list(map(int, readline().split())) prn = lambda x: print(*x, sep='\n') def solve(): n = ni() m = 10**4 + 1 l = nl() prv = [0]*m nxt = [0]*m for x in l: cur = prv[0] for i in range(m): cur = min(cur, prv[i]) nxt[i] = abs(i - x) + cur prv, nxt = nxt, prv print(min(prv)) return solve()