n = int(input())
a = list(map(int, input().split()))

fun = [[0]*n for _ in range(n)]
freq = dict()
el = set()
for i in range(n):
    for j in range(n):
        cost = a[i]*abs(i-j)
        fun[i][j]= cost
        el.add(cost)
        try:
            freq[cost].append((i,j))
        except:
            freq[cost] = [(i,j)]

el = list(el)
el.sort(reverse=True)
ans=0
usedi=set()
usedj=set()
for cost in el:
    for i,j in freq[cost]:
        if not (i in usedi or j in usedj):
            ans+=cost
            usedi.add(i)
            usedj.add(j)

print(ans)
# for i in range(n):
#     print(*fun[i])