#!/usr/bin/env python
# -*- coding: utf-8 -*-

import sys
sys.setrecursionlimit(10**7)
from pprint import pprint as pp
from pprint import pformat as pf

import math
#from sortedcontainers import SortedList, SortedDict, SortedSet # no in atcoder
import bisect

from heapq import heappush, heappop
class PriorityQueue:

    def __init__(self):
        self.contaier = []

    def push(self, priority, value):
        heappush(self.contaier, (priority, value))

    def pop(self):
        return heappop(self.contaier)

    def is_empty(self):
        return len(self.contaier) == 0

class Solver():

    def __init__(self, n, students):
        self.n = n
        self.students = students
        self.pq = PriorityQueue()
        self.ans = 0
        self.used_frm = [False] * (n + 1) # [0] is dummy
        self.used_to = [False] * (n + 1) # [0] is dummy

    def run(self):
        self.register()
        self.select()
        return -1 * self.ans

    def register(self):
        for i, active in enumerate(self.students):
            frm = i + 1
            for i in range(n):
                to = i + 1
                point = active * abs(frm - to)
                self.pq.push(-1 * point, (frm, to))

    def select(self):
        self.ans = 0
        while not self.pq.is_empty():
            point, (frm, to) = self.pq.pop()
            #print('self.used_frm, to') # debug
            #print(self.used_frm) # debug
            #print(self.used_to) # debug
            #print('point, frm, to') # debug
            #print(point, frm, to) # debug
            if self.used_frm[frm] or self.used_to[to]:
                continue
            #print('used') # debug
            self.ans += point
            self.used_frm[frm] = True
            self.used_to[to] = True




if __name__ == '__main__':
    n = int(input())
    students = list(map(int, input().split()))
    ans = Solver(n, students).run()
    print(ans)



    #print('\33[32m' + 'end' + '\033[0m') # debug
