// Problem idea by Thomas Tang // Problem written by Thomas Tang // This solution written by Thomas Tang import java.io.*; import java.util.*; public class list { public static void main(String[] args) throws Exception { BufferedReader in = new BufferedReader(new InputStreamReader(System.in)); int n = Integer.parseInt(in.readLine()); TreeMap tmap = new TreeMap(); for (int i = 0; i < n; i++) { String line = in.readLine(); String country = line.substring(0, line.indexOf(" ")); if (!tmap.containsKey(country)) { tmap.put(country, new Integer(1)); } else { int newValue = ((Integer) tmap.get(country)).intValue() + 1; tmap.put(country, new Integer(newValue)); } } for (Iterator i = tmap.keySet().iterator(); i.hasNext();) { String country = (String) i.next(); System.out.println(country + " " + tmap.get(country)); } } }