N = int(input()) A = sorted(map(int, input().split())) ans = 0 for i in range(1, N): ans += A[0]*A[i] A[0] += A[i] print(ans)