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(reverse=True)
    det = set()
    res = {}
    for i in range(N):
        hbest = -1
        arg = None
        for j in range(N):
            if j in det:
                continue
            for h, pos in pref[j]:
                if pos in res:
                    continue
                if hbest < h:
                    hbest = h
                    arg = (j,pos)
        baby, pos = arg
        res[pos] = hbest
        det.add(baby)
    assert len(det) == N
    return sum(res.values())

print(solve())
