import math  # noqa
import bisect  # noqa
import queue  # noqa


if __name__ == '__main__':
    N = int(input())
    A = list(map(int, input().split()))

    MAX = N - 1
    MIN = 0
    used = set()

    ans = 0
    while len(used) < N:
        diff = []
        for i, a in enumerate(A):
            res = max(abs(i - MIN), abs(MAX - i))
            if i not in used:
                diff.append([res * a, i])
        diff.sort(reverse=True)
        ans += diff[0][0]
        used.add(diff[0][1])
        idx = 0
        while abs(diff[idx][1] - MIN) == abs(MAX - diff[idx][1]):
            idx += 1
            if idx == len(diff):
                idx -= 1
                break
        if abs(diff[idx][1] - MIN) < abs(MAX - diff[idx][1]):
            MAX -= 1
        else:
            MIN += 1

    print(ans)
