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

    if maxindR == maxindL:
        if maxvalL >= maxindR: # L > R
            if filled[indL]:
                indL += 1
                indR -= 1
                continue
            filled[indL] = True
            used[maxindL] = True
            res += maxvalL
            #print("L:", indL, "maxind", maxindL, "maxval", maxvalL)
            maxindR = -1
            maxvalR = -9999999999999999999999
            for ind in range(n):
                if used[ind]: # もう使っているならパス
                    continue
                disR = abs(ind - indR)
                if (dat[ind] * disR) > maxvalR:
                    maxvalR = dat[ind] * disR
                    maxindR = ind
            if filled[indR]:
                indL += 1
                indR -= 1
                continue
            filled[indR] = True
            used[maxindR] = True
            res += maxvalR
            #print("R:", indR, "maxind",maxindR, "maxval",maxvalR)
        else: # R < L
            if filled[indR]:
                indL += 1
                indR -= 1
                continue
            filled[indR] = True
            used[maxindR] = True
            res += maxvalR
            #print("R:", indR, "maxind",maxindR, "maxval",maxvalR)
            maxindL = -1
            maxvalL = -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
            if filled[indL]:
                indL += 1
                indR -= 1
                continue
            filled[indL] = True
            used[maxindL] = True
            res += maxvalL
            #print("L:", indL, "maxind", maxindL, "maxval", maxvalL)
    else:
        if filled[indL]:
            indL += 1
            indR -= 1
            continue
        filled[indL] = True
        used[maxindL] = True
        res += maxvalL
        #print("L:", indL, "maxind",maxindL, "maxval",maxvalL)
        if filled[indR]:
            indL += 1
            indR -= 1
            continue
        filled[indR] = True
        used[maxindR] = True
        res += maxvalR
        #print("R:", indR, "maxind",maxindR, "maxval",maxvalR)
    indL += 1
    indR -= 1

print(res)

