#!/usr/bin/env python3
import sys
import heapq

def solve(N: int, A: "List[int]"):
    heap = []

    for i in range(N):
        for j in range(N):
            heapq.heappush(heap,(-A[i]*abs(i-j),i,j))
    
    moved_infant = set()
    moved_index = set()
    answer = 0
    while len(moved_index) < N:
        score,index,infant = heapq.heappop(heap)

        if index not in moved_index and infant not in moved_infant:
            moved_infant.add(infant)
            moved_index.add(index)
            answer -= score
    print(answer)
    return


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()
