// Arup Guha
// 7/15/2015
// Written in SI@UCF Java GUI class
// Test that uses a Tree Map - presents data sorted by keys, not values.

import java.util.*;

public class TestTreeMap {

	public static void main(String[] args) {

		Scanner stdin = new Scanner(System.in);
		TreeMap<String,Integer> map = new TreeMap<String,Integer>();

		// Process all the words.
		while (stdin.hasNext()) {
			String s = stdin.next();
			if (map.containsKey(s)) {
				int freq = map.get(s);
				map.put(s, freq+1);
			}
			else
				map.put(s, 1);
		}

        // Pull words from map in lexicographical order (by key)
		while (map.size() > 0) {
			String s = map.firstKey();
			System.out.println(s+" "+map.get(s));
			map.pollFirstEntry();
		}

	}
}

class word implements Comparable<word> {
	private String str;
	private int freq;

	public word(String s, int numTimes) {
		str = s;
		freq = numTimes;
	}

	public int compareTo(word other) {
		if (this.freq != other.freq) return other.freq - this.freq;
		return this.str.compareTo(other.str);
	}

	public String toString() {
		return str+" "+freq;
	}
}
