def solve(n, aaa):
    aaa_with_idx = list(zip(aaa, range(n)))
    n2 = n // 2
    ans = 0
    for i in range(n2 + 1 + n % 2):
        srt = sorted(aaa_with_idx[i:], reverse=True)
        left = srt[:n2]
        right = sorted(srt[n2:] + aaa_with_idx[:i])
        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(max(solve(n, aaa), solve(n, reversed(aaa))))
