# import sys
# sys.setrecursionlimit(10 ** 6)
int1 = lambda x: int(x) - 1
def II(): return int(input())

def MI(): return map(int, input().split())
def MI1(): return map(int1, input().split())

def LI(): return list(map(int, input().split()))
def LLI(rows_number): return [LI() for _ in range(rows_number)]

from collections import deque

def solve():
    n = II()
    A = [(idx+1, j) for idx, j in enumerate(MI())]
    d = deque([i+1 for i in range(n)])
    B = sorted(A, key=lambda x:x[1], reverse=True)
    dct = {}
    for idx, j in B:
        dct[idx] = j

    # print(dct)
    # print(d)
    harf = n // 2
    ans = 0
    # for b, idx in B:
    for j in range(n):
        idx, b = B[j]
        if idx <= harf:
            p = d.pop()
        else:
            p = d.popleft()
        # print(idx, b, p, abs(idx - p))
        ans = ans + b * abs(idx - p)
        # d.remove(idx)
        # print(d)
    print(ans)





if __name__ == '__main__':
    solve()
