#!/usr/bin/env python3
import sys


def solve(N: int, A: "List[int]"):
    moved = [False]*N
    result = 0
    actual =[]
    upIndex = N-1
    downIndex = 0
    up = True
    while upIndex >= downIndex:
        i = 0
        if up:
            i = downIndex
        else:
            i = upIndex
        maxScore = 0
        maxScoreIndex = -1
        for j in range(N):
            if not moved[j] and maxScore < abs(i-j)*A[j]:
                maxScoreIndex = j
                maxScore = abs(i - j) * A[j]
        moved[maxScoreIndex] = True
        # actual.append(f"{maxScoreIndex}(Ai={A[maxScoreIndex]})")
        result+=maxScore
        if up:
            downIndex +=1
        else:
            upIndex -=1
        up=not up
    # print(actual)
    print(result)
    return


# Generated by 1.1.6 https://github.com/kyuridenamida/atcoder-tools  (tips: You use the default template now. You can remove this line by using your custom template)
def main():
    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word
    tokens = iterate_tokens()
    N = int(next(tokens))  # type: int
    A = [int(next(tokens)) for _ in range(N)]  # type: "List[int]"
    solve(N, A)

if __name__ == '__main__':
    main()
