def a
  m = {}

  while (s = gets) != "\n"
    (n, c) = s.chomp.split(/,/).map(&:to_i)
    m[n] = [] if !m.key?(n)
    m[n].push(c)
  end

  m
end

pm = a
tm = a

pm.keys.sort.each do |k|
  if tm.key?(k)
    puts "#{k} #{pm[k].size + tm[k].size}"
  end
end