function main(input) {
  const inputs = input.split('\n')
  const N = Number(inputs[0])
  const A = inputs[1].split(' ').map(Number)

  const a = A.map((e,i) => [e, i]).sort((a, b) => {
    return a[0] < b[0] ?
      1:
      -1
  })
  // console.log(a)
  const dp = Array.from(new Array(N+1)).map(e => [])
  // console.log(dp)
  dp[0][0] = 0
  for(let i = 0; i < N; i++) {
    const aind = a[i][1]
    const ai = a[i][0]
    for(let l = 0; l < i+1; l++) {
      const r = i - l
      // ここにdp...?
      // console.log(aind, i, l, r)
      const c = dp[i][l]
      // calc next
      // 右
      if (dp[i+1][l] === undefined) dp[i+1][l] = 0
      // console.log('calc:', i, l)
      // console.log('right point:', ai * ((N - r - 1) - aind))
      dp[i+1][l] = Math.max(dp[i+1][l], dp[i][l] + ai * ((N - r - 1) - aind))
      // 左
      if (dp[i+1][l+1] === undefined) dp[i+1][l+1] = 0
      // console.log('calc:', i, l+1)
      // console.log('left point:', dp[i][l] + ai * (aind - l))
      dp[i+1][l+1] = Math.max(dp[i+1][l+1], dp[i][l] + ai * (aind - l))
      // console.log(dp)
    }
  }
  console.log(Math.max.apply(null, dp[dp.length-1]))
}
main(require("fs").readFileSync("/dev/stdin", "utf8"));
