#!/bin/python3 import sys from itertools import * def powerset(numlist): N = len(numlist) indices = {(a, b) for (a, b) in product(range(N)+1, range(N)+1) if a < b} return {numlist[a:b] for (a, b) in indices} def value(B): return sum(x*y for x, y in product(B, B)) def largestValue(A): return max({value(B) for B in powerset(A)}) if __name__ == "__main__": n = int(input().strip()) A = list(map(int, input().strip().split(' '))) result = largestValue(A) print(result)