# frozen_string_literal: true

n = gets.to_i
a = gets.split.map(&:to_i)
b = []
a.each_index do |i|
  b.push [i, a[i]]
end
max = 0
b.permutation(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
