N = int(input()) A = list(map(int, input().split())) M = [0] * 2 m, n = 0, 0 ans = 0 i = N - 1 for a in A[::-1]: ans += m * a * (~-i < N ) m, n = n - n * a + 1, m * a + 1 i -= 1 print(ans)