# coding: utf-8
import sys
from collections import deque
from heapq import heapify, heappop, heappush

sr = lambda: sys.stdin.readline().rstrip()
ir = lambda: int(sr())
lr = lambda: list(map(int, sr().split()))

N = ir()
A = lr()
heap = []
for i in range(N):
    for j in range(N):
        if i == j:
            continue
        heappush(heap, (-A[i] * abs(j-i), i, j))

answer = 0
i_used = set()
j_used = set()
while heap:
    happy, ip, jp= heappop(heap)
    if ip in i_used or jp in j_used:
        continue
    i_used.add(ip); j_used.add(jp)
    answer -= happy

print(answer)
