import sys
readline = sys.stdin.readline

N = int(readline())
A = list(map(int, readline().rstrip().split()))
B = [-1] * N

def find_best():
    ma_sel = -1
    for i, a in enumerate(A):
        if a == -1:
            continue
        ma = -1
        for j in range(N):
            if B[j] != -1:
                continue
            get = a * abs(j-i)
            if get > ma:
                ma = get
                idx = j
        if ma > ma_sel:
            ma_sel = ma
            idx_from = i
            idx_to = idx

    return idx_from, idx_to, ma_sel

def main():
    global A, B
    for _ in range(N):
        idx_from, idx_to, ma_sel = find_best()
        A[idx_from] = -1
        B[idx_to] = ma_sel

    print(sum(B))


if __name__ == '__main__':
    main()