import itertools

n = int(input())
a = list(map(int, input().split()))

def make_key(select):
    key = ''
    for i in select:
        key += str(i)
    return key

dp = {}
def f(select):
    try:
        key = make_key(select)
        return dp[key]
    except KeyError:
        if len(select) == 1:
            return 0
        if len(select) == 2:
            i, j = select
            return abs(i - j) * (a[i] + a[j])
        happy = 0
        for i, j in itertools.combinations(select, 2):
            tmp = abs(i - j) * (a[i] + a[j]) + f(select - {i, j})
            happy = max(tmp, happy)
        key = make_key(select)
        dp[key] = happy
        return happy

select = set([i for i in range(n)])
print(f(select))