Go: package main

import (
	"bufio"
	"fmt"
	"os"
	"sort"
	"strconv"
	"strings"
)

func main() {
	stdin := bufio.NewScanner(os.Stdin)
	index := make(map[string]string)
	keys := []string{}
	for stdin.Scan() {
		l := strings.Split(stdin.Text(), " ")
		if l[0] == "0" {
			break
		}
		if index[l[0]] == "" {
			keys = append(keys, l[0])
		}
		index[l[0]] += l[1] + " "
	}
	sort.Strings(keys)
	for _, k := range keys {
		fmt.Println(k)
		p := strings.Split(strings.TrimRight(index[k], " "), " ")
		pages := []int{}
		for _, v := range p {
			i, _ := strconv.Atoi(v)
			pages = append(pages, i)
		}
		sort.Ints(pages)
		for i, v := range pages {
			if i > 0 {
				fmt.Printf(" ")
			}
			fmt.Printf("%d", v)
		}
		fmt.Println()
	}
}

C++: #include <bits/stdc++.h>
#define _USE_MATH_DEFINES
using namespace std;
 
 
#define li			long long int
#define rep(i,to)	for(li i=0;i<((li)(to));i++)
#define repp(i,start,to)	for(li i=(li)(start);i<((li)(to));i++)
#define pb			push_back
#define sz(v)		((li)(v).size())
#define bgn(v)		((v).begin())
#define eend(v)		((v).end())
#define allof(v)	(v).begin(), (v).end()
#define dodp(v,n)		memset(v,(li)n,sizeof(v))
#define bit(n)		(1ll<<(li)(n))
#define mp(a,b)		make_pair(a,b)
#define rin	rep(i,n)
#define rjm	rep(j,m)


#define DBGP 1


#define idp if(DBGP)
#define F first
#define S second
#define p2(a,b)		idp cout<<a<<"\t"<<b<<endl
#define p3(a,b,c)		idp cout<<a<<"\t"<<b<<"\t"<<c<<endl
#define p4(a,b,c,d)		idp cout<<a<<"\t"<<b<<"\t"<<c<<"\t"<<d<<endl
#define p5(a,b,c,d,e)		idp cout<<a<<"\t"<<b<<"\t"<<c<<"\t"<<d<<"\t"<<e<<endl
#define p6(a,b,c,d,e,f)		idp cout<<a<<"\t"<<b<<"\t"<<c<<"\t"<<d<<"\t"<<e<<"\t"<<f<<endl
#define p7(a,b,c,d,e,f,g)		idp cout<<a<<"\t"<<b<<"\t"<<c<<"\t"<<d<<"\t"<<e<<"\t"<<f<<"\t"<<g<<endl
#define p8(a,b,c,d,e,f,g,h)		idp cout<<a<<"\t"<<b<<"\t"<<c<<"\t"<<d<<"\t"<<e<<"\t"<<f<<"\t"<<g<<"\t"<<h<<endl
#define p9(a,b,c,d,e,f,g,h,i)		idp cout<<a<<"\t"<<b<<"\t"<<c<<"\t"<<d<<"\t"<<e<<"\t"<<f<<"\t"<<g<<"\t"<<h<<"\t"<<i<<endl
#define p10(a,b,c,d,e,f,g,h,i,j)		idp cout<<a<<"\t"<<b<<"\t"<<c<<"\t"<<d<<"\t"<<e<<"\t"<<f<<"\t"<<g<<"\t"<<h<<"\t"<<i<<"\t"<<j<<endl
#define foreach(it,v)	for(__typeof((v).begin()) it=(v).begin(); it!=(v).end(); ++it)
#define p2p(x)		idp p2((x).F, (x).S)
#define dump(x,n)	idp{rep(i,n){cout<<x[i]<<" ";}puts("");}
#define dump2(x,n)	idp{rep(i,n){cout<<"["<<x[i].F<<" , "<<x[i].S<<"] ";}puts("");}
#define dumpi(x)	idp{foreach(it, x){cout<<(*it)<<" ";}puts("");}
#define dumpi2(x)	idp{foreach(it, x){cout<<"["<<(it)->F<<" , "<<(it)->S<<"] ";}puts("");}

#define read2d(a,w,h)	rep(i,h)rep(j,w)cin>>a[i][j]
#define dump2d(a,w,h)	rep(i,h){rep(j,w)cout<<a[i][j]<<" ";puts("");}


#define EPS 1e-10
#define ETOL 1e-8
#define MOD 1000000007
#define INF bit(60)

typedef pair<li, li> PI;

vector<pair<string, li>> book;

int main(int argc, char *argv[]){
	string s;
	li page;
	while(cin>>s){
		if(s=="hogehogehogehogehogehogehogehogehogehoge")break;
		cin>>page;
		book.pb({s, page});
	}
	sort(allof(book));

	string prev="";
	foreach(it, book){
		if(it->F!=prev){
			prev=it->F;
			cout<<endl;
			cout<<prev<<endl;
		}
		cout<<it->S<<" ";
	}
	puts("");


	return 0;
}

C++: #include<iostream>
#include<map>
#include<algorithm>
#include<set>
using namespace std;

int main(){
  map<string,set<int> > Index;
  string s;
    int val;
  while(cin  >> s >> val){
    Index[s].insert(val);
  }

  map<string,set<int> >::iterator it = Index.begin();
  while(it != Index.end()){
    cout << it->first << endl;  
    set<int>::iterator it2 = (it->second).begin();
    while(it2 != (it->second).end()){
      cout << *it2;
      if(it2 != (it->second).end())cout << " ";
      it2++; 
    } 
   cout << endl;
   it++;
  }
  return 0;
}

C++: #include <iostream>
#include <string>
#include <vector>
#include <map>
#include <algorithm>
using namespace std;

int main()
{
	map<string,vector<int> > dict;
	string str;
	int page;
	while(cin >> str >> page)
		dict[str].push_back(page);
	for(map< string,vector<int> >::iterator it = dict.begin();it!=dict.end();it++){
		sort(it->second.begin(),it->second.end());
		cout << it->first << endl;
		for(unsigned i=0;i<it->second.size();i++){
			cout << it->second[i];
			if(i<it->second.size()-1)
				cout << " ";
			else
				cout << endl;
		}
	}
	return 0;
}

C++: #include <bits/stdc++.h>

using namespace std;

int main(void) {
    string s;
    int p;
    map<string, set<int> > mp;

    while (cin >> s >> p)
        mp[s].insert(p);
    
    for (map<string, set<int> >::iterator itm = mp.begin(); itm != mp.end(); itm++) {
        int flag = 0;
        cout << (*itm).first << '\n';
        for (set<int>::iterator its = (*itm).second.begin(); its != (*itm).second.end(); its++) {
            if (flag) printf(" ");
            printf("%d", (*its));
            flag = 1;
        }
        printf("\n");
    }

    return 0;
}

C++: #include <iostream>
#include <map>
#include <string>
#include <vector>
#include <algorithm>

int main()
{
    std::map<std::string, std::vector<int>> BookIndex;
    std::string word;
    int page;

    while (std::cin >> word >> page) {
        if (BookIndex.count(word)) {
            BookIndex[word].push_back(page);
        } else {
            BookIndex[word] = std::vector<int>(1, page);
        }
    }

    for (std::map<std::string, std::vector<int>>::iterator bookindex = BookIndex.begin(); bookindex != BookIndex.end(); ++bookindex) {
        std::cout << (*bookindex).first << std::endl;
        std::sort((*bookindex).second.begin(), (*bookindex).second.end());
        
        for (int i = 0; i < static_cast<int>((*bookindex).second.size()); ++i) {
            std::cout << (i == 0 ? "" : " " ) <<(* bookindex).second[i];
        }
        
        std::cout << std::endl;
        
    }

    return 0;
}

C++: #include<iostream>
#include<string>
#include<set>
#include<map>
#include<algorithm>
using namespace std;
int main(){
	map<string,set<int> > data;
	string tmpWord;
	int tmpPage;
	while(cin>>tmpWord>>tmpPage){
		data[tmpWord].insert(tmpPage);
	}
	for(map<string,set<int> >::iterator i=data.begin();i!=data.end();i++){
		cout<<(i->first)<<endl;
		for(set<int>::iterator j=(i->second).begin();j!=(i->second).end();j++){
			if(j!=(i->second).begin())cout<<" ";
			cout<<*j;
		}
		cout<<endl;
	}
}

C++: #include <iostream>
#include <vector>
#include <string>
#include <algorithm>
using namespace std;

class myList
{
public:
	myList() : mSize( 0 ){}

	void insert( string str, int page ){
		for( int i = 0; i < mSize; ++i ){
			if( str == mList[ i ].first ){
				mList[ i ].second.push_back( page );
				return;
			}
		}
		vector< int > vec;
		vec.push_back( page );
		mList.push_back( pair< string, vector< int > >( str, vec ) );
		++mSize;
	}

	void sort(){
		std::sort( mList.begin(), mList.end() );
		for( int i = 0; i < mSize; ++i ){
			std::sort( mList[ i ].second.begin(), mList[ i ].second.end() );
		}
	}

	void output(){
		for( int i = 0; i < mSize; ++i ){
			cout << mList[ i ].first << endl;
			for( int j = 0; j < (int)mList[ i ].second.size(); ++j ){
				if( j != 0 ){
					cout << " ";
				}
				cout << mList[ i ].second[ j ];
			}
			cout << endl;
		}
	}

	vector< pair< string, vector< int > > > mList;
	int mSize;
};

int main()
{
	string str;
	int page;
	myList db;

	while( cin >> str >> page ){
		db.insert( str, page );
	}
	db.sort();
	db.output();

	return 0;
}