import numpy as np
if __name__ == "__main__":
    # 入力パターン．
    # 先に要素数Nが与えられて，その数読み込むパターン
    ### N
    ### a_1 a_2 a_3 ... a_N
    N = int(input())
    # int型のリスト
    line = list(map(int, input().rstrip().split(' ')))

    arr = [[line[i]*np.abs(i-j) for j in range(N)] for i in range(N)]
    arr = np.array(arr)
    cost = arr + arr.T
    #print(arr)
    #print(cost)
    ans = 0
    unused = np.array([True for i in range(N)])
    for i in range(N):
        c = cost[i]
        if unused.sum() > 0:
            add = c[unused].max()
            used = c == add
            used = unused * used
            used_idx = used.argmax()
            #print(used)
            unused[i] = False
            unused[used_idx] = False
            ans += add
            #print(c)
            #print(add)
            #print(unused)
    print(ans)

