import java.util.*;
import java.io.*;

// This is an illustration of a non-linear structure called a
// HashMap.  This program reads lines that have items and counts
// for an inventory.  It sums all of the counts for each item.

public class InventoryProgram {

	/**
	 * @param args
	 */
	public static void main(String[] args) {
		HashMap<String, Integer>inventory = new HashMap<String, Integer>();
		Scanner console = new Scanner(System.in);
		
		boolean done = false;
		while (!done) {
			System.out.print( "Item count: ");
			String line = console.nextLine();
			if (line.length() == 0)
				done = true;
			else {
				int lastSpace = line.lastIndexOf( ' ');
				int count = Integer.parseInt( line.substring(lastSpace+1));
				String name = line.substring(0,  lastSpace);
				if (inventory.containsKey(name)) {
					int current = inventory.get(name);
					inventory.put(name, current+count);
				}
				else 
					inventory.put(name,  count);
			}
		}
		Set keys = inventory.keySet();
		Iterator<String> iter = keys.iterator();
		while (iter.hasNext()) {
			String name = iter.next();
			Integer count = inventory.get(name);
			System.out.printf( "%-10s %3d \n", name, count);
		}
	}

}
