def main():
    # import sys
    # readline = sys.stdin.readline
    # readlines = sys.stdin.readlines
    from heapq import heappush, heappop
    N = int(input())
    A = list(map(int, input().split()))

    done = [0] * N
    cnt = 0

    for i in range(N // 2):
        l = i
        r = N - 1 - i
        q = []

        for j in range(N):
            if done[j]:
                continue
            heappush(q, (-A[j] * abs(l - j), j, 'l'))
            heappush(q, (-A[j] * abs(r - j), j, 'r'))

        rflag = 0
        lflag = 0
        while not (lflag & rflag):
            c, j, pos = heappop(q)
            if done[j] != 1 and ((rflag == 0 and pos == 'r') or (lflag == 0 and pos == 'l')):
                cnt += -c
                done[j] = 1
                if pos == 'r':
                    rflag = 1
                else:
                    lflag = 1

    if N % 2 == 1:
        for idx, flag in enumerate(done):
            if flag == 0:
                break
        # print(idx)
        # print(N // 2)
        cnt += A[idx] * abs(idx - (N // 2))

    print(cnt)


if __name__ == "__main__":
    main()
