import sys import numpy as np read = sys.stdin.buffer.read n, *y = map(int, read().split()) MaxY = 10005 dp = np.zeros(MaxY, dtype=np.int32) ix = np.arange(MaxY) for i in range(n): dp += abs(ix - y[i]) np.minimum.accumulate(dp, out=dp) print(np.minimum.reduce(dp))