object Main extends App {

  val src = io.Source.stdin.getLines.filter(_ != "").flatMap(_.split(",")).toList.map(_.toInt)
  val (xs, ys) = src.filter(src.indexOf(_) % 2 == 0).splitAt(src.length / 4)
  val intersects = xs.intersect(ys).sorted

  for (num <- intersects) println(s"${num} ${src.count(_ == num)}")
}

