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 <algorithm>
#include <iostream>
#include <string>
#include <map>
#include <vector>

using namespace std;

int main() {
    map<string, vector<int>> list;
    string word;
    int page;
    while (cin >> word >> page) {
        if (list.count(word)) {
            list[word].push_back(page);
        } else {
            list[word] = vector<int>(1, page);
        }
    }
    for (auto li : list) {
        cout << li.first << endl;
        sort(li.second.begin(), li.second.end());
        for (int i=0; i<(int)li.second.size(); ++i) {
            cout << (i == 0 ? "" : " ") << li.second[i];
        }
        cout << endl;
    }
    return 0;
}

C++: #include <stdio.h>
#include <iostream>
#include <vector>
#include <queue>

using namespace std;

typedef pair<string,int> Pairsi;

int main(){
	priority_queue<Pairsi,vector<Pairsi>,greater<Pairsi> > q;
	Pairsi psi;
	vector<int> tn;
//	int tn[1000],tni=0;
	int c=0,n;
	string s,ts;


//input
	while(1){
		cin >> s >> n;
		if(cin.eof())break;
		q.push(make_pair(s,n));
		c++;
	}

//output
/*
	for(int i=0;i<c;i++){
		psi = q.top();
		q.pop();

		if(i==0){
	
		}else if(ts==psi.first){
			cout << "equal";
		}else{
			cout << ts << endl;

			for(int j=0;j<tn.size();j++){
				cout << tn[j] << ' ';
			}
			tn.clear();
			cout << endl;
		}

		ts = psi.first;
		tn.push_back(psi.second);
//		tn[tni++] = psi.second;

	}*/
	for(int i=0;i<c;i++){
		psi = q.top();
		q.pop();

		if(ts==psi.first){
			cout << " " << psi.second;
		}else{
			if(i!=0){
				cout << endl;
			}
			cout << psi.first << endl;
			cout << psi.second;
		}

		ts = psi.first;
	}

	puts("");

	return 0;
}

C++: #include <iostream>
#include <string>
#include <map>
#include <queue>
using namespace std;
 
int main() {
	map<string, priority_queue<int,vector<int>,greater<int> > > index;
	string word;
	int page;
 
	while(cin>>word>>page){
		index[word].push(page);
	}
 
	for(multimap<string,priority_queue<int,vector<int>,greater<int> > >::iterator it = index.begin(); it != index.end(); ++it){
		cout << it->first << endl;
 
		priority_queue<int,vector<int>,greater<int> > temp = it->second;
		while(1){
			cout << temp.top();
			temp.pop();
			if(!temp.empty()){cout<<" ";continue;}
			break;
		}
		cout << endl;
 	}
 
	return 0;
}

C++: #include<iostream>
#include<string>
#include<algorithm>
using namespace std;
string tn[1000];
int tp[1000][1000],tt[1000];
int main(){
	string a;
	int b,top=0;
	while(cin>>a>>b){
		bool t=true;
		for(int i=0;i<top;i++){
			if(tn[i]==a){
				t=false;
				tp[i][tt[i]]=b;
				tt[i]++;
			}
		}
		if(t==true){
			tn[top]=a;
			tp[top][0]=b;
			tt[top]=1;
			top++;
		}
		for(int i=0;i<top-1;i++){
			for(int j=top-1;j>i;j--){
				bool w=true;
				int k=0;
				while(true){
					if(tn[j][k]>tn[j-1][k])
						break;
					if(tn[j][k]<tn[j-1][k]){
						w=false;
						break;
					}
					k++;
					if(k==tn[j-1].size())
						break;
					if(k==tn[j].size()){
						w=false;
						break;
					}
				}
				if(w==false){
					string tmps=tn[j];
					tn[j]=tn[j-1];
					tn[j-1]=tmps;
					int tmph[1000];
					for(int k=0;k<tt[j];k++)
						tmph[k]=tp[j][k];
					for(int k=0;k<tt[j-1];k++)
						tp[j][k]=tp[j-1][k];
					for(int k=0;k<tt[j];k++)
						tp[j-1][k]=tmph[k];
					int tmp=tt[j];
					tt[j]=tt[j-1];
					tt[j-1]=tmp;
				}
				for(int i=0;i<top;i++)
			        sort(tp[i],tp[i]+tt[i]);
			}
		}
	}
	for(int i=0;i<top-1;i++){
			for(int j=top-1;j>i;j--){
				bool w=true;
				int k=0;
				while(true){
					if(tn[j][k]>tn[j-1][k])
						break;
					if(tn[j][k]<tn[j-1][k]){
						w=false;
						break;
					}
					k++;
					if(k==tn[j].size())
						break;
					if(k==tn[j-1].size()){
						w=false;
						break;
					}
				}
				if(w==false){
					string tmps=tn[j];
					tn[j]=tn[j-1];
					tn[j-1]=tmps;
					int tmph[100];
					for(int k=0;k<tt[j];k++)
						tmph[k]=tp[j][k];
					for(int k=0;k<tt[j-1];k++)
						tp[j][k]=tp[j-1][k];
					for(int k=0;k<tt[j];k++)
						tp[j-1][k]=tmph[k];
					int tmp=tt[j];
					tt[j]=tt[j-1];
					tt[j-1]=tmp;
				}
			}
		}
		for(int i=0;i<top;i++)
			sort(tp[i],tp[i]+tt[i]);
		for(int i=0;i<top;i++){
			cout<<tn[i]<<endl;
			cout<<tp[i][0];
			for(int j=1;j<tt[i];j++)
				cout<<" "<<tp[i][j];
			cout<<endl;
		}
	return 0;
}

C++: #include <cstdio>
#include <cstring>
#include <algorithm>
#include <string>
#include <cmath>
#include <stack>
#include <vector>
#include <map>
#include <set>
#include <queue>
#include <list>
#include <iostream>
#include <climits>
#include <cfloat>

typedef long long ll;

using namespace std;

int main()
{
	int p;
	string s;
	map<string, set<int> > b;
	while (cin >> s >> p)
		b[s].insert(p);

	for (map<string, set<int> >::iterator i = b.begin(); i != b.end(); ++i)
	{
		string w = i->first;
		cout << w << endl;
		set<int>& t = i->second;
		for (set<int>::iterator it = t.begin(); it != t.end(); ++it)
		{
			if (it != t.begin())
				cout << " ";
			cout << *it;
		}
		cout << endl;
	}

	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(); ++j)
		{
			cout << Vec[i].second[j] << " ";
		}
		cout << endl;
	}
}

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

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

map<string,set<int>> p;

int main()
{
    string str;
    int t;
    while (cin >> str >> t) p[str].insert(t);
    for (auto it = p.begin(); it != p.end(); it++) {
        auto s = it->second.begin();
        cout << it->first  << endl << *s;
        for (++s; s != it->second.end(); s++)
            cout << " " << *s;
        cout << endl;
    }

    return 0;
}

C++: #include <iostream>
#include <utility>
#include <vector>
#include <algorithm>
using namespace std;
typedef pair< string,int > p;

vector<p> book;

int main() {
  string s;
  int P;
  while(cin >> s >> P) {
    p temp;
    temp.first = s;
    temp.second = P;
    book.push_back(temp);
  }
  sort(book.begin(),book.end());
  bool r;
  string now = "";
  for(unsigned int i=0;i<book.size();i++) {
    if(now != book[i].first) {
      if(i!=0) cout << endl;
      now = book[i].first;
      cout << now << endl;
      r = false;
    }
    if(r) {
      cout << " ";
    }
    cout << book[i].second;
    r = true;
  }
  cout << endl;
}