n = int(input())
a = list(map(int, input().split()))
ans = 0
for i in range(1,n):
    left = [[a[i], i] for i in range(i)]
    right = [[a[i], i] for i in range(i, n)]
    left.sort()
    right.sort(reverse=True)
    tmp = []
    for _,i in right:
        tmp.append(i)
    for _,i in left:
        tmp.append(i)
    ans_tmp = 0
    for i in range(n):
        ans_tmp += a[tmp[i]]*abs(i-tmp[i])
    ans = max(ans, ans_tmp)
print(ans)