n = gets.to_i tables = [] n.times { tables.push gets.split.map(&:to_i) } tables.map do |table| if table[0] <= 2 1 * table[1] else 2 * table[1] end end.inject(:+).tap{|t| p t}