Problem:
Book Index

Books are indexed. Write a program which reads a list of pairs of a word and a page number, and prints the word and a list of the corresponding page numbers.

You can assume that a word consists of at most 30 characters, and the page number is less than or equal to 1000. The number of pairs of a word and a page number is less than or equal to 100. A word never appear in a page more than once.

The words should be printed in alphabetical order and the page numbers should be printed in ascending order.

Input

word page_number
:
:

Output

word
a_list_of_the_page_number
word
a_list_of_the_Page_number
:
:

Sample Input

style 12
even 25
introduction 3
easy 9
style 7
document 13
style 21
even 18

Output for the Sample Input

document
13
easy
9
even
18 25
introduction
3
style
7 12 21

Solution in JAVA (judge verdict: Wrong Answer)

import java.util.ArrayList;
import java.util.Collections;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.PriorityQueue;
import java.util.Scanner;

//Book Index
public class Main{

	public static class B implements Comparable<B>{
		public String s;
		public PriorityQueue<Integer> q;
		public B(String s) {
			this.s = s;
			q = new PriorityQueue<Integer>();
		}
		public int compareTo(B o) {
			return s.compareTo(o.s);
		}
	}

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		List<B> list = new ArrayList<B>();
		Map<String, Integer> ref = new HashMap<String, Integer>();
		int id = 0;
		while(sc.hasNext()){
			String s = sc.next();
			if(ref.containsKey(s))list.get(ref.get(s)).q.add(sc.nextInt());
			else {
				B b = new B(s);
				b.q.add(sc.nextInt());
				list.add(b);
				ref.put(s, id++);
			}
		}
		Collections.sort(list);
		for(B b:list){
			System.out.println(b.s);
			boolean f = true;
			for(int a:b.q){
				if(!f)System.out.print(" ");
				f = false;
				System.out.print(a);
			}
			System.out.println();
		}
	}
}