def main(str)
  n, as = str.split("\n")
  as = as.split(" ").map(&:to_i)
  n = n.to_i
  origi = as.length.times.map(&:to_i)
  loop do
    max = 0
    maxes = nil
    as.each.with_index do |a0, i0|
      as.each.with_index do |a1, i1|
        next if (i0 >= i1)
        cur_val = a0 * (origi[i0] - i0).abs + a1 * (origi[i1] - i1).abs
        nex_val = a0 * (origi[i0] - i1).abs + a1 * (origi[i1] - i0).abs
        val = nex_val - cur_val
        if max < val
          max = val
          maxes = [i0, i1]
        end
      end
    end
    if maxes
      i0, i1 = maxes[0], maxes[1]
      origi[i0], origi[i1] = origi[i1], origi[i0]
      as[i0], as[i1] = as[i1], as[i0]
    else
      sum = 0
      as.each.with_index do |a0, i0|
        sum += a0 * (origi[i0] - i0).abs
      end
      return sum
    end
  end
end

puts main($stdin.read.chomp)