n = int(input())
a = [(int(x), i) for i, x in enumerate(input().split())]

def gain(i, j):
    val, index = a[i]
    return val * abs(index - j)

ans = 0
def do_swap():
    global ans
    for i in range(1, n):
        old = gain(i - 1, i - 1) + gain(i, i)
        new = gain(i - 1, i) + gain(i, i - 1)
        if old < new:
            a[i - 1], a[i] = a[i], a[i - 1]
            ans += new - old
            return True
    return False

while do_swap():
    pass

print(ans)