def solve(n, aaa):
    aaa_with_idx = list(zip(aaa, range(n)))
    n2 = n // 2
    ans = 0
    for i in range(n):
        if i <= n2:
            srt = sorted(aaa_with_idx[i:], reverse=True)
            left = srt[:n2]
            right = sorted(srt[n2:] + aaa_with_idx[:i])
        else:
            srt = sorted(aaa_with_idx[:i])
            right = srt[-n2:]
            left = sorted(srt[:-n2] + aaa_with_idx[i:], reverse=True)

        tmp = sum(a * abs(j - k) for j, (a, k) in enumerate(left + right))
        ans = max(ans, tmp)
    return ans


n = int(input())
aaa = list(map(int, input().split()))
print(solve(n, aaa))
