n = int(input())
a = list(map(int, input().split()))
sum_total = sum(a)#列表中数字总和
sum_left = 0#左边列表数字和
min_mul = float("inf")#最小切割代价
for i in range(n - 1):#遍历列表寻找最小切割代价
sum_left += a[i]
min_mul = min(min_mul, sum_left * (sum_total - sum_left))
print(min_mul)



京公网安备 11010502036488号