# frozen_string_literal: true

n = gets.not_nil!.to_i
a = gets.not_nil!.split.map(&.to_i)
b = [] of Array(Int32)
a.each_index do |i|
  b.push [i, a[i]]
end
max = 0
b.permutations(n).each do |e|
  sum = 0
  e.each_index do |i|
    sum += (e[i][0] - i).abs * e[i][1]
  end
  max = sum if max < sum
end
puts max
