N = int(input()) A = [int(s) for s in input().split()] ans = 0 while len(A) >= 2: a, b = A.pop(), A.pop() ans += a * b A.append(a + b) print(ans)