N = gets.to_i c = gets.split.map(&:to_i) puts c.zip([* ?1 .. ?9]).reverse.sum("") { |c, d| d * c }