import java.io.*;
import java.util.*;

class Concordance {
	Concordance(String filename) throws Exception {
		Scanner scanner = new Scanner(new FileInputStream(filename));

		int lineNum = 0;

		while (scanner.hasNextLine()) {
			lineNum++;
			String line = scanner.nextLine();

			int wordOnLine = 0;

			int pos = 0;
			while (pos < line.length()) {
				if (Character.isAlphabetic(line.charAt(pos))) {
					String word = "";
					while (pos< line.length() && Character.isAlphabetic(line.charAt(pos))) {
						word += line.charAt(pos);
						pos++;
					}
					wordOnLine++;
					ArrayList<Location> locations =  map.get(word);
					
					if (locations == null) {
						locations = new ArrayList<Location>();
						map.put(word, locations);
					}
					locations.add(new Location(lineNum, wordOnLine));
				}
				else
					pos++;
			}
		}
	}

	public String toString() {
		String result = "";
		for (String word : map.keySet()) 
			result += word + ": " + map.get(word) + "\n";
		return result;
	}
			
	private Map<String, ArrayList<Location>> map = new TreeMap<String, ArrayList<Location>>();

	public static void main(String [] args) throws Exception {
		if (args.length != 1) {
			System.out.println("Usage: Concordance <filename>");
			System.exit(1);
		}
		Concordance concordance = new Concordance(args[0]);
		System.out.println(concordance);
	}
}

