n = int(input())
l = list(map(int,input().split()))
s1 = l[0] * sum(l[1:])
s2 = sum(l[:-1]) * l[-1]
print(min(s1,s2))