











import Foundation
let main: () = {
    let N = nextInt()
//    let A = listOfInt().enumerated().map { ($0.1, $0.0 ) }.sorted { $0.0 > $1.0 }
    let A = listOfInt().enumerated().map { ($0.1, $0.0 ) }
    let g0 = Array<Int>(N)
    var G = Array(N) { _ in g0 }
    repeate(N, N) { n, m in
        G[n][m] = A[n].0 * abs(A[n].1 - m)
    }
    var ans = Array<Int>(N)
    repeate(N) { m in
        var max = 0
        var id = 0
        repeate(N) { n in
            if (max < G[n][m]) {
                max = G[n][m]
                id = n
            }
            
        }
        ans[m] = max
        repeate(N) { m in
            G[id][m] = 0
        }
    }
    print(ans.sum())
}()

@inlinable func next() -> String { readLine()! }
@inlinable func nextInt() -> Int { Int(next())! }
@inlinable func listOfString() -> [String] { next().split(separator: " ").map(String.init) }
@inlinable func listOfInt() -> [Int] { listOfString().map { Int($0)! } }
extension Array {
    init(_ size: Int, _ initValue: ((Int) -> Element)) {
        self = [Element]()
        for index in 0 ..< size {
            let value = initValue(index)
            self.append(value)
        }
    }
}
extension Array where Element == Int {
    @inlinable func sum() -> Element { self.reduce(0, +) }
    init(_ size: Int) {
        self = [Element]()
        for _ in 0 ..< size {
            self.append(0)
        }
    }
}
prefix operator *
prefix func * <T> (a: [T]) -> (T, T) { (a[0], a[1]) }

@inlinable func repeate(_ times1: Int, _ times2: Int, _ action: (Int, Int) -> Void) {
    for index1 in 0 ..< times1 {
        for index2 in 0 ..< times2 {
            action(index1, index2)
        }
    }
}
@inlinable func repeate(_ times1: Int, _ action: (Int) -> Void) {
    for index1 in 0 ..< times1 {
        action(index1)
    }
}
