import kotlin.math.abs

fun main() {
    println(solve())
}

val solve: () -> Any = {
    val N = readInt()
    val A = readLongList().withIndex().toList().toTypedArray()
    repeat(N) {
        for (n in 0 until N-1) {
            val now = abs(A[n].index - n) * A[n].value + abs(A[n+1].index - n) * A[n+1].value
            val nex = abs(A[n].index - n - 1) * A[n].value + abs(A[n+1].index - n + 1) * A[n+1].value
            if (now < nex)
                A[n] = A[n+1].also { A[n+1] = A[n] }
        }
    }
    A.withIndex().map {(i, v) -> abs(v.index - i) * v.value }.sum()
}

fun readString() = readLine()!!
fun readInt() = readLine()!!.toInt()
fun readLong() = readLine()!!.toLong()
fun readStringList() = readLine()!!.split(" ")
fun readIntList() = readLine()!!.split(" ").map(String::toInt)
fun readLongList() = readLine()!!.split(" ").map(String::toLong)