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


	return 0;
}

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

using namespace std;
typedef pair<string, vector<int> > P;

void solve()
{
	vector<P> Vec;
	string str;
	while(cin >> str)
	{
		int n;
		cin >> n;
		bool existFlag = false;
		for(int i = 0; i < Vec.size(); ++i)
		{
			if(Vec[i].first == str)
			{
				Vec[i].second.push_back(n);
				existFlag = true;
				break;
			}
		}
		if(!existFlag)
		{
			vector<int> V;
			V.push_back(n);
			Vec.push_back(make_pair(str, V));
		}
	}
	sort(Vec.begin(), Vec.end());
	for(int i = 0; i < Vec.size(); ++i)
	{
		cout << Vec[i].first << endl;
		sort(Vec[i].second.begin(), Vec[i].second.end());
		for(int j = 0; j < Vec[i].second.size() - 1; ++j)
		{
			cout << Vec[i].second[j] << " ";
		}
		cout << Vec[i].second[Vec[i].second.size() - 1] << endl;
	}
}

int main()
{
	solve();
	return(0);
}

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

int StringComp(const string &s1, const string &s2){
	return s1.compare(s2);
}

int main(void){
	map<string, vector<int>> m;
	while( true ){
		string word;
		int page;

		cin >> word >> page;
		if( cin.eof() ) break;

		m[word].push_back(page);
	}
	map<string, vector<int>>::iterator itM = m.begin();
	while(itM != m.end()){
		sort(itM->second.begin(), itM->second.end());
		cout << itM->first << '\n';
		cout << itM->second[0];
		for(unsigned int i = 1; i < itM->second.size(); i++){
			cout << ' ' << itM->second[i];
		}
		cout << endl;
		itM++;
	}
	return 0;
}

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

using namespace std;

int main(){
	string strInput;
	map< string,vector<int> > index;
	int intInput = 0;
	while(cin >> strInput >> intInput){
		index[strInput].push_back(intInput);
	}
	
	for(map< string,vector<int> >::iterator it = index.begin(); it != index.end() ; it++){
		sort( index[(*it).first].begin(),index[(*it).first].end() );
		cout << (*it).first << endl;
		for(int i = 0; i < index[(*it).first].size(); i++){
			if(i == index[(*it).first].size() - 1){
				cout <<  index[(*it).first][i];
				break;
			}
			cout <<  index[(*it).first][i] << ' ';
		}
		cout << endl;
	}

	return 0;
}

C++: #include<iostream>
#include<string>
#include<algorithm>
using namespace std;
pair<string,int> d[101];
int ptop[101];
int p[101][101];
int main(){
	string a;
	int q,top;
	top=0;
	int u=0;//**
	while(cin>>a>>q){
		bool news=true;
		for(int i=0;i<top;i++){
			if(d[i].first==a){
				p[i][ptop[i]]=q;
				ptop[i]++;
				news=false;
			}
		}
		if(news){
			d[top].first=a;
			d[top].second=top;
			ptop[top]=1;
			p[top][0]=q;
			top++;
		}
		u++;//***
		if(u==8)break;//***
	}
	sort(d,d+top);
	for(int i=0;i<top;i++)sort(p[i],p[i]+ptop[i]);
	for(int i=0;i<top;i++){
		cout<<d[i].first<<endl;
		cout<<p[d[i].second][0];
		for(int j=1;j<ptop[d[i].second];j++){
			cout<<" "<<p[d[i].second][j];
		}
		cout<<endl;
	}
	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;
      it2++;
      if(it2 != (it->second).end())cout << " ";
    } 
   cout << endl;
   it++;
  }
  return 0;
}