class Calc0035 def initialize(args) args = args.map { |l| l.chomp.split(/\s+/) } @n = args.shift.first.to_i @periods = args.map { |l| [l[0].to_i, l[1]] } end def calc @periods.inject([0, 0]) { |(sum_h, sum_m), (t, s)| a = 12 * t / 1000 h = [s.size, a].min [sum_h + h, sum_m + s.size - h] } end def run calc.join(' ') end end puts Calc0035.new(STDIN.readlines).run if __FILE__ == $0