gets
ais = read_line.split.map(&.to_i64)
vals = ais.map_with_index {|a, i| {i.to_i64, a}}

ans = 0_i64
vals.size.times do
  (vals.size - 1).times do |i|
    ai, aa = vals[i]
    bi, ba = vals[i + 1]
    current = (ai - i).abs * aa + (bi - (i + 1)).abs * ba
    test = (ai - (i + 1)).abs * aa + (bi - i).abs * ba
    if test > current
      vals[i], vals[i + 1] = vals[i + 1], vals[i]
      ans += test - current
    end
  end
end
p ans
