import sys

readline = sys.stdin.readline
MOD = 10 ** 9 + 7
INF = float('INF')
sys.setrecursionlimit(10 ** 5)


def main():
    n = int(input())
    a = list(map(int, readline().split()))

    left = 0
    right = n - 1

    ans = 0
    used = [False] * n
    pos = [0] * n

    for _ in range(n):
        xmax = [0] * n

        for i in range(n):
            if used[i]:
                continue

            l = abs(i - left) * a[i]
            r = abs(i - right) * a[i]

            if l > r:
                xmax[i] = l
                pos[i] = True
            else:
                xmax[i] = r
                pos[i] = False

        m = max(xmax)
        ans += m
        idx = xmax.index(m)
        used[idx] = True

        if pos[idx]:
            left += 1
        else:
            right -= 1

    print(ans)


if __name__ == '__main__':
    main()
