from itertools import accumulate



_ = int(eval(input()))

d = tuple(map(int, input().split()))

a = tuple(reversed(tuple(accumulate(reversed(d)))))

print((sum(dd * aa for dd, aa in zip(d, a[1:]))))
from itertools import accumulate



_ = int(eval(input()))

d = tuple(map(int, input().split()))

a = tuple(accumulate(reversed(d)))[::-1]

print((sum(dd * aa for dd, aa in zip(d, a[1:]))))
from itertools import accumulate

_ = int(eval(input()))
d = tuple(map(int, input().split()))
a = tuple(reversed(tuple(accumulate(reversed(d)))))
print((sum(dd * aa for dd, aa in zip(d, a[1:]))))

from itertools import accumulate

_ = int(eval(input()))
d = tuple(map(int, input().split()))
a = tuple(accumulate(reversed(d)))[::-1]
print((sum(dd * aa for dd, aa in zip(d, a[1:]))))

-a = tuple(reversed(tuple(accumulate(reversed(d))))) +a = tuple(accumulate(reversed(d)))[::-1]