import java.util.*;

public class store2 {

	public static void main(String[] args) {

		Scanner stdin = new Scanner(System.in);
		HashMap<String,Integer> map = new HashMap<String,Integer>();

		int numCommands = stdin.nextInt();

		for (int loop=0; loop<numCommands; loop++) {

			char command = stdin.next().charAt(0);

			// Trying to add an item.
			if (command == 'a') {

				String item = stdin.next();
				int quantity = stdin.nextInt();
				if (map.containsKey(item)) {
					int newq = map.get(item) + quantity;
					map.put(item, newq);
					System.out.println("Added "+quantity+" of "+item+". Now have "+map.get(item)+" of it.");
				}
				else {
					map.put(item, quantity);
					System.out.println("New item "+item+" added "+quantity);
				}
			}

			else if (command == 'r') {

				String item = stdin.next();
				int quantity = stdin.nextInt();

				if (!map.containsKey(item))
					System.out.println("Can't remove "+item+". It's not in the set.");
				else if (map.get(item) < quantity)
					System.out.println("Sorry we don't have "+quantity+" of "+item+".");
				else {
					int newq = map.get(item) - quantity;
					System.out.println(quantity +" of "+item+" has been removed.");

					if (newq == 0) {
						System.out.println("There is no more of "+item+" left.");
						map.remove(item);
					}
					else
						map.put(item, newq);
				}
			}

			else if (command == 's') {
				System.out.println("The map has "+map.size()+" number of items.");
			}

			else if (command == 'e') {
				map.clear();
				System.out.println("The map has been emptied.");
			}

			else if (command == 'c'){
				String item = stdin.next();
				int quantity = stdin.nextInt();

				if (map.containsKey(item) && map.get(item) >= quantity)
					System.out.println("The map contains at least "+quantity+" of "+item+".");
				else
					System.out.println("The map does not have "+quantity+" of "+item+".");

			}

			else if (command == 'p') {

				for (String item : map.keySet())
					System.out.println(item+" "+map.get(item));
			}

			else if (command == 't') {

				int res = 0;
				for (Integer item : map.values())
					res += item;
				System.out.println("There is a total of "+res+" items.");
			}

		}
	}
}