from itertools import product
import numpy as np


def read():
    N = int(input())
    A = list(map(int, input().split()))
    return N, A


def rmq_init(n, INF=2**16+1):
    n0 = 2**(n-1).bit_length()
    rmq = [INF] * (2 * n0)
    rmq_idx = [INF] * (2 * n0)
    return rmq, rmq_idx


def rmq_update(rmq, rmq_idx, k, x):
    n0 = len(rmq) // 2
    k += n0 - 1
    rmq[k] = x
    rmq_idx[k] = k-(n0-1)
    while k >= 0:
        k = (k-1) // 2
        if rmq[2*k+1] < rmq[2*k+2]:
            rmq[k] = rmq[2*k+1]
            rmq_idx[k] = rmq_idx[2*k+1]
        else:
            rmq[k] = rmq[2*k+2]
            rmq_idx[k] = rmq_idx[2*k+2]
    

def rmq_query(rmq, l, r, INF=2**16+1):
    n0 = len(rmq) // 2
    L = l + n0
    R = r + n0
    s = INF
    while L < R:
        if R & 1:
            R -= 1
            s = min(s, rmq[R-1])
        if L & 1:
            s = min(s, rmq[L-1])
            L += 1
        L >>= 1
        R >>= 1
    return s


def rmq_query_idx(rmq, rmq_idx, l, r, INF=2**16+1):
    n0 = len(rmq) // 2
    L = l + n0
    R = r + n0
    s = INF
    s_idx = -1
    while L < R:
        if R & 1:
            R -= 1
            if rmq[R-1] < s:
                s = rmq[R-1]
                s_idx = rmq_idx[R-1]
        if L & 1:
            if rmq[L-1] < s:
                s = rmq[L-1]
                s_idx = rmq_idx[L-1]
            L += 1
        L >>= 1
        R >>= 1
    return s_idx


def solve(N, A, INF=2**16+1):
    S = np.empty((N, N), dtype=np.int)
    rmqs = list()
    rmq_idxs = list()
    for i in range(N):
        rmq, rmq_idx = rmq_init(N)
        for j in range(N):
            S[i][j] = A[i] * abs(i - j)
            rmq_update(rmq, rmq_idx, j, -S[i][j])
        rmqs.append(rmq)
        rmq_idxs.append(rmq_idx)
    ans = 0
    skip = [False for i in range(N)]
    for k in range(N):
        max_v = 0
        max_idx = -1
        max_ldx = -1
        for i in range(N):
            if not skip[i]:
                v = -rmq_query(rmqs[i], 0, N)
                ldx = rmq_query_idx(rmqs[i], rmq_idxs[i], 0, N)
                if max_v < v:
                    max_v = v
                    max_idx = i
                    max_ldx = ldx
        ans += max_v
        for i in range(N):
            rmq_update(rmqs[i], rmq_idxs[i], max_ldx, INF)
        skip[max_idx] = True
    return ans

if __name__ == '__main__':
    inputs = read()
    print("{}".format(solve(*inputs)))
