#!/usr/bin/env python3
import sys


def solve(N: int, A: "List[int]"):
    moved = [False]*N
    result = 0
    actual =[""]*N
    upIndex = N-1
    downIndex = 0
    def checkNext(i):
        maxScore = -1
        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]
        return (maxScore,maxScoreIndex)
    while upIndex >= downIndex:
        fromDown,di = checkNext(downIndex)
        fromUp,ui = checkNext(upIndex)
        if fromDown > fromUp:
            result+= fromDown
            actual[downIndex] = A[di]
            moved[di] = True
            # print(f"Down{downIndex}:{di} - {A[di]}")
            # print(moved)
            # print(f"down:{downIndex},up:{upIndex}")
            downIndex+=1
        else:
            result+=fromUp
            actual[upIndex] = A[ui]
            moved[ui] = True
            # print(f"Up{upIndex}:{ui} - {A[ui]}")
            # print(moved)
            # print(f"down:{downIndex},up:{upIndex}")
            upIndex-=1
    # 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()
