
n = parse(Int, readline())
arr = [tpl for tpl in enumerate(parse.(Int, split(readline())))]
arr = sort(arr, by = tpl -> -tpl[2])

dp = zeros(n + 1, n + 1)

for ln = 0 : n
  for rn = 0 : n - ln
    if ln + rn > n || dp[ln + 1, rn + 1] > 0
      continue
    end

    if ln + rn > 0
      p, a = arr[ln + rn]
      val_l = ln > 0 ? dp[ln, rn + 1] + a * abs(p - ln) : 0
      val_r = rn > 0 ? dp[ln + 1, rn] + a * abs(p - (n - rn + 1)) : 0

      dp[ln + 1, rn + 1] = max(val_l, val_r)
    end
  end
end

println(Int(maximum([dp[i+ 1, n - i + 1] for i in 0 : n])))
