// Arup Guha
// 7/15/2015
// Written in SI@UCF Java GUI class
// Test that uses a Hash Map to keep track of the 3 of occurrences of each word in a file.

import java.util.*;

public class TestHashMap {

	public static void main(String[] args) {

		Scanner stdin = new Scanner(System.in);
		HashMap<String,Integer> map = new HashMap<String,Integer>();

        // Read in all the words
		while (stdin.hasNext()) {
			String s = stdin.next();

			// We've seen this before, add 1 to its count.
			if (map.containsKey(s)) {
				int freq = map.get(s);
				map.put(s, freq+1);
			}

			// First time, its count is 1.
			else
				map.put(s, 1);
		}

        // Create a list of words, then sort by frequency.
		ArrayList<word> myWords = new ArrayList<word>();
		for (String s: map.keySet())
			myWords.add(new word(s, map.get(s)));
		Collections.sort(myWords);

		// Output the words (with frequency)
		for (int i=0; i<myWords.size(); i++)
			System.out.println(myWords.get(i));
	}
}

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;
	}
}
