n = gets.to_i a = gets.split.map &.to_i puts a.each_with_index.sum { |v, i| v * (i + 1) * (n - i) }