import math
n = int(input())
dat = list(map(int, input().split()))
#dat = [[i, datSource[i]] for i in range(n)]
#dat.sort(key=lambda x: (-x[1], -x[0]))
indL = 0
indR = n - 1


loop = math.ceil(n / 2)
used = [False] * n # その数は使ったか？
filled = [False] * n # 埋まっているか？
res = 0
while indR >= indL:
    # まずL
    maxindL = -1
    maxvalL = -9999999999999999999999
    maxindR = -1
    maxvalR = -9999999999999999999999

    for ind in range(n):
        if used[ind]: # もう使っているならパス
            continue
        disL = abs(ind - indL)
        if (dat[ind] * disL) > maxvalL:
            maxvalL = dat[ind] * disL
            maxindL = ind
        disR = abs(ind - indR)
        if (dat[ind] * disR) > maxvalR:
            maxvalR = dat[ind] * disR
            maxindR = ind

    #print(maxvalL, maxvalR)
    if maxvalL >= maxvalR: # L > R
        filled[indL] = True
        used[maxindL] = True
        res += maxvalL
        #print("L:", indL, "maxind", maxindL, "maxval", maxvalL)
        indL += 1
    else:
        filled[indR] = True
        used[maxindR] = True
        res += maxvalR
        #print("R:", indR, "maxind",maxindR, "maxval",maxvalR)
        indR -= 1
print(res)
