import collections
N = int(input())
A = list(map(int, input().split()))

def solve():
    happy = [[0]*N for _ in range(N)]
    pref = [[] for _ in range(N)]
    for i, a in enumerate(A):
        for j in range(N):
            h = abs(j - i) * a
            happy[i][j] = h
            pref[i].append((h,j))
        pref[i].sort()
    rem = set(range(N))
    res = {}
    for i in range(N):
        hbest = -1
        arg = None
        for j in rem:
            pj = pref[j]
            for k in range(len(pj)-1, -1, -1):
                h, pos = pj[k]
                if pos in res:
                    del pj[k]
                    continue
                if hbest < h:
                    hbest = h
                    arg = (j,pos)
        baby, pos = arg
        res[pos] = hbest
        rem.remove(baby)
    assert len(rem) == 0
    return sum(res.values())

print(solve())
