N = int(input())
active = list(map(int, input().split(" ")))
ans = 0


head = 0 
tail = N-1
for _ in range(N) :
    _max = -float('inf')
    at_head = True
    idx = -1
    
    for j in range(N) :
        if active[j] == -1 :
            continue
        v1 = abs(head-j)*active[j] 
        v2 = abs(tail-j)*active[j] 
        if _max < v1 :
            _max = v1
            idx = j
            at_head = True
        elif _max == v1 :
            if active[idx] > active[j] :
                idx = j
                at_head = True


        if _max < v2 :
            _max = v2
            idx = j
            at_head = False
        elif _max == v2 :
            if active[idx] > active[j] :
                idx = j
                at_head = False

    active[idx] = -1
    ans += _max
    if at_head :
        head += 1
    else :
        tail -= 1

print(ans)