n = int(input()) a = list(map(int, input().split())) s = [0 for _ in range(n + 1)] for i in range(n): s[i + 1] = s[i] + a[i] ans = - sum((n - l) * s[l] for l in range(n)) + sum(r * s[r] for r in range(1, n + 1)) print(ans)