N = int(input()) B = list(map(int, input().split())) A = [0] * N j = 0 for i, b in enumerate(B): while b > 0: A[j] = i j += 1 b -= 1 ans = 0 for i in range(N): ans += abs(A[i] - i) print(ans)