Go: package main

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

var scanner = bufio.NewScanner(os.Stdin)

func main() {
	dictionary := make(map[string][]int)

	for {
		var word string
		var page int
		fmt.Scanf("%s %d", &word, &page)

		if word == "" || page == 0 {
			break
		}

		pages := dictionary[word]
		pages = append(pages, page)
		dictionary[word] = pages
	}

	words := make([]string, 0)
	for i := range dictionary {
		words = append(words, i)
	}

	sort.Strings(words)

	for _, v := range words {
		sort.Ints(dictionary[v])
		fmt.Println(v)
		for i, page := range dictionary[v] {
			if i == len(dictionary[v])-1 {
				fmt.Printf("%d\n", page)
			} else {
				fmt.Printf("%d ", page)
			}
		}
	}
}

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;
}

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

using namespace std;

int print_vec(const vector<int>& v)
{
	for (int i = 0; i < v.size(); i++){
		printf("%d%c", v[i], " \n"[i == v.size() - 1]);
	}
	return 0;
}

int main()
{
	map<string, vector<int> > dict;
	string word;
	int page;
	while (cin >> word >> page){
		if (!dict.count(word)){
			vector<int> v;
			v.push_back(page);
			dict[word] = v;
		}
		else dict[word].push_back(page);
	}
	for (map<string, vector<int> >::iterator it = dict.begin(); it != dict.end(); ++it){
		sort(it->second.begin(), it->second.end());
		print_vec(it->second);
	}
}