package finalset;


import java.util.NoSuchElementException;
import java.util.Scanner;

/**
 * Given a set of lines of ASCII english text (including spaces and punctuation), you 
 * are to report the top ten most frequent letters (regardless of capitalization) and 
 * their count totals.
 * 
 * If two letters have the exact same count total, then you should order the letters
 * alphabetically.
 * 
 * The source text is terminated by a single line containing a single "." (Period).
 * 
 * You can be assured that each input text contains at least ten different letters.
 * 
 * @author George
 *
 */
public class Problem5 {
	// array of # of character seen.
	static int []letters = new int[27];  // A = 1, Z = 26
	
	public static void main (String args[]) {
		String s;
		Scanner sc = null;
		sc = new Scanner (System.in);
		String corpus = "";
		try{
			while (true) {
				s = sc.nextLine();
				if (s == null) {
					break;
				}
				
				corpus += s; 
				if (s.equals(".")) break;
			}
		} catch (NoSuchElementException nsee) {
			// done.
		}
		System.out.println(computeHistogram(corpus));
	
	}

	// process line.
	public static void process(String s) {
		s = s.toLowerCase();
		for (int i = 0; i < s.length(); i++) {
			char ch = s.charAt(i);
			if ((ch >= 'a') && (ch <= 'z')) {
				int off = ch-'a'+1;
				letters[off]++;
			}
		}
	}

	// output results.
	public static String computeHistogram(String s) {
		process(s);
		char []topTen = new char[10];
		int []topTenCount = new int [10];
		int idx = 0;
		
		// count total # of letters.
		int totalLetters = 0;
		for (int tt : letters) {
			totalLetters += tt;
		}
		
		// pull out top ten achievers.
		for (int i = 0; i < 10; i++) {
			int max = -9;
			int maxChar = -1;
			for (int j = 1; j <= 26; j++) {
				if (letters[j] > max) {
					max = letters[j];
					maxChar = j;
				} else if (letters[j] == max) {
					// smaller j always wins. so we never move.
				}
			}
			
			topTenCount[idx] = letters[maxChar];
			topTen[idx] = (char) ('a' + maxChar - 1);
			letters[maxChar] = -9; // kill for next time.
			idx++;
		}
		
		String res = "";
		for (int i = 0; i < 10; i++) {
			res +=(topTen[i] + " " + topTenCount[i]) + "\n";
		}
		
		return res;
		
	}

	public static void reset() {
		letters = new int[27];  // A = 1, Z = 26		
	}
}
