n = int(input()) ys = map(int, input().split()) MaxY = 10005 dp = [0 for _ in range(MaxY)] for y in ys: for j in range(MaxY): dp[j] += abs(j - y) for j in range(MaxY-1): dp[j+1] = min(dp[j], dp[j+1]) res = 10000007 for d in dp: res = min(res, d) print(res)