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 <iostream>
#include <string>
#include <set>
#include <map>
using namespace std;

int main() {
    map<string, set<int> > index;
    string word;
    int page;
    while (cin >> word >> page) {
        index[word].insert(page);
    }
    for (map<string, set<int> >::iterator it = index.begin(); it != index.end(); it++) {
        cout << it->first << endl;
        bool insertSpace = false;
        for (set<int>::iterator sit = it->second.begin(); sit != it->second.end(); sit++) {
            if (insertSpace) {
                cout << " ";
            } else {
                insertSpace = true;
            }
            cout << *sit;
        }
        cout << endl;
    }
}

C++: #include <algorithm>
#include <bitset>
#include <cctype>
#include <complex>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>
#include <deque>
#include <functional>
#include <iomanip>
#include <iostream>
#include <list>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <utility>
#include <vector>

using namespace std;

inline int toInt(string s) {int v; istringstream sin(s);sin>>v;return v;}
template<class T> inline string toString(T x) {ostringstream sout;sout<<x;return sout.str();}
template<class T> inline T sqr(T x) {return x*x;}

typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<string> vs;
typedef pair<int, int> pii;
typedef long long ll;

#define all(a)  (a).begin(),(a).end()
#define rall(a) (a).rbegin(), (a).rend()
#define pb push_back
#define mp make_pair
#define each(i,c) for(typeof((c).begin()) i=(c).begin(); i!=(c).end(); ++i)
#define exist(s,e) ((s).find(e)!=(s).end())
#define range(i,a,b) for(int i=(a);i<(b);++i)
#define rep(i,n)  range(i,0,n)
#define clr(a,b) memset((a), (b) ,sizeof(a))
#define dump(x)  cerr << #x << " = " << (x) << endl;
#define debug(x) cerr << #x << " = " << (x) << " (L" << __LINE__ << ")" << " " << __FILE__ << endl;

const double eps = 1e-10;
const double pi  = acos(-1.0);
const ll INF =1LL << 62;
const int inf =1 << 29;

pair<string,int> dic[1010];

int main(void){
	int n=0;
	while(true){
		string key;
		int num;
		cin >> key >> num;
		if(cin.eof())
			break;
		dic[n].first=key;
		dic[n++].second=num;
	}
	sort(dic,dic+n);
	string prev="";
	rep(i,n){
		if(prev==""){
			cout << dic[i].first << endl;
			cout << dic[i].second;
		}else if(prev==dic[i].first){
			cout << " " << dic[i].second;
		}else{
			cout << endl;
			cout << dic[i].first << endl;
			cout << dic[i].second;
		}
		prev=dic[i].first;
	}
	cout << endl;
	return 0;
}

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

int main(){
  map<string, set<int> > index;
  string name;
  int num;
  while(cin>>name>>num){
    index[name].insert(num);
  }
  map<string, set<int> >::iterator it = index.begin();
  while(it != index.end()){
    cout<<(*it).first<<endl;
    set<int>::iterator it0 = (*it).second.begin();
    while(true){
      cout<<*it0;
      it0++;
      if(it0 != (*it).second.end()){
	cout<<" ";
      }
      else
	break;
    }
    cout<<endl;
    it++;
  }
  return 0;
}

C++: #include <iostream>
#include <string>
#include <set>
#include <algorithm>
using namespace std;
set<pair<string,int> >RB;set<pair<string,int> >::iterator it,ot;string T;int N;
int main() {
    while ((cin>>T)!=NULL) {cin>>N;RB.insert(make_pair(T,N));} it=ot=RB.begin();cout<<(it->first)<<endl<<(it->second);it++;
    while (it!=RB.end()) {if ((ot->first)==(it->first)) cout<<" "<<(it->second); else cout<<endl<<(it->first)<<endl<<(it->second);it++,ot++;}
    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 <iostream>
#include <map>
#include <string>
#include <vector>
#include <algorithm>
 
using namespace std;
 
int main(int argc, char const *argv[]){
    vector<int> pages;
    map<string, vector<int> > books; 
    string name;
    int page, page_count;
 
    while (cin>>name>>page){
        auto it = books.find(name);
        if (it != books.end()){
            books[name].push_back(page);
        }
        else{
            vector<int> pages = {page};
            books.insert(make_pair(name, pages));
        }
    }
 
    for (auto& book : books){
        cout<<book.first<<endl;
        page_count=0;
        sort(book.second.begin(), book.second.end());
        for (int page : book.second){
            if (page_count) cout<<" "<<page;
            else cout<<page;
            page_count++;
        }
        cout<<'\n';
    }
    return 0;
}

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

using namespace std;

int main()
{
	map<string, vector<int> > index;
	vector<string> strv;
	string s;
	int p;
	
	while (cin >> s >> p){
		if (index.find(s) == index.end()){
			strv.push_back(s);
		}
		index[s].push_back(p);
	}
	sort(strv.begin(), strv.end());
	for (int i = 0; i < strv.size(); i++){
		sort(index[strv[i]].begin(), index[strv[i]].end());
		cout << strv[i] << endl;
		cout << index[strv[i]][0];
		for (int j = 1; j < index[strv[i]].size(); j++){
			cout << ' ' << index[strv[i]][j];
		}
		cout << endl;
	}
	
	return 0;
}

C++: #include <algorithm>
#include <cmath>
#include <climits>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <fstream>
#include <iostream>
#include <list>
#include <map>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <vector>
#include <cassert>
#include <functional>

using namespace std;

#define LOG(...) printf(__VA_ARGS__)
//#define LOG(...)
#define FOR(i,a,b) for(int i=(int)(a);i<(int)(b);++i)
#define REP(i,n) for(int i=0;i<(int)(n);++i)
#define ALL(a) (a).begin(),(a).end()
#define RALL(a) (a).rbegin(),(a).rend()
#define EXIST(s,e) ((s).find(e)!=(s).end())
#define SORT(c) sort((c).begin(),(c).end())
#define RSORT(c) sort((c).rbegin(),(c).rend())
#define CLR(a) memset((a), 0 ,sizeof(a))

typedef long long ll;
typedef unsigned long long ull;
typedef vector<bool> vb;
typedef vector<int> vi;
typedef vector<ll> vll;
typedef vector<vb> vvb;
typedef vector<vi> vvi;
typedef vector<vll> vvll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;

const int dx[] = { -1, 0, 1, 0 }; const int dy[] = { 0, 1, 0, -1 };
struct index{
	string s;
	int p;
	bool operator<(const index &right) const{
		return right.s != s ? right.s > s :right.p > p;
	}

};
int main() {
	vector<index> book;
	string s;
	int n;
	while (cin >> s >> n)
		book.push_back({ s, n });
	SORT(book);
	s = "";
	REP(i, book.size()){
		if (book[i].s != s){
			if (i != 0)cout << endl;
			cout << book[i].s << endl;
			cout << book[i].p;
		}
		else{
			cout << ' ' << book[i].p;
		}
		s = book[i].s;
	}
	cout << endl;
}