#!/bin/python from itertools import combinations import sys def subA(A): for i in xrange(len(A)-1): for j in xrange(i, len(A)): yield A[i:j] def product(A): return sum(a*b for a,b in combinations(A, 2)) def largestValue(A): # Return the largest value of any of A's nonempty subarrays. return max(product(x) for x in subA(A)) if __name__ == "__main__": n = int(raw_input().strip()) A = map(int, raw_input().strip().split(' ')) result = largestValue(A) print result