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
//------------------------------------------
#include <vector>
#include <list>
#include <map>
#include <set>
#include <deque>
#include <stack>
#include <bitset>
#include <algorithm>
#include <functional>
#include <numeric>
#include <utility>
#include <sstream>
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <cctype>
#include <string>
#include <cstring>
#include <ctime>
#include <fstream>
#include <conio.h>
using namespace std;

//conversion
//------------------------------------------
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();}

//math
//-------------------------------------------
template<class T> inline T sqr(T x) {return x*x;}

//typedef
//------------------------------------------
typedef vector<int> VI;
typedef vector<VI> VVI;
typedef vector<string> VS;
typedef pair<int, int> PII;
typedef pair<long, long> PLL;
typedef long long LL;
//container util
//------------------------------------------
#define ALL(a)  (a).begin(),(a).end()
#define RALL(a) (a).rbegin(), (a).rend()
#define PB push_back
#define MP make_pair
#define SZ(a) int((a).size())
#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 SORT(c) sort((c).begin(),(c).end())

//repetition
//------------------------------------------
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n)  FOR(i,0,n)

//constant
//--------------------------------------------
const double EPS = 1e-10;
const double PI  = acos(-1.0);

//clear memory
#define CLR(a) memset((a), 0 ,sizeof(a))




int main(){
	string str;
	vector<pair<string,int>>sp;
	int num;
	while(cin>>str>>num){
		sp.PB(MP(str,num));
	}
	bool c=false;
	SORT(sp);
	REP(i,SZ(sp)){
		if(!c)cout<<sp[i].first<<endl;
		if(i!=SZ(sp)-1&&sp[i].first==sp[i+1].first){
			cout<<sp[i].second<<" ";
			c=true;
		}else{
			c=false;
			cout<<sp[i].second<<endl;
		}
		
	}
	return 0;
}

C++: #include <cstdio>
#include <cstdlib>
#include <cmath>
#include <iostream>
#include <sstream>
#include <vector>
#include <string>
#include <queue>
#include <set>
#include <map>
#include <utility>
#include <algorithm>
#include <functional>

using namespace std;

#define rep(i,n) for((i)=0;(i)<(int)(n);(i)++)
#define foreach(itr,c) for(__typeof((c).begin()) itr=(c).begin();itr!=(c).end();itr++)

int main(){
  int page;
  string doc;
  map< string, vector<int> > mp;

  while(cin >> doc >> page) mp[doc].push_back(page);

  int i;
  foreach(itr,mp){
    cout << itr->first << endl;
    sort(itr->second.begin(),itr->second.end());
    rep(i,itr->second.size()){
      cout << itr->second[i];
      if(itr->second.size()-1 == i) cout << endl; else cout << ' ';
    }
  }

  return 0;
}

C++: #include <iostream>
#include <vector>
#include <string>
#include <map>
#include <set>
#include <queue>
#include <stack>
#include <algorithm>
#include <functional>
#include <numeric>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <climits>
#include <sstream>
using namespace std;

#define REP(i,a,n) for(i=a; i<n; i++)
#define rep(i,n) REP(i,0,n)
#define all(x) x.begin(), x.end()
#define rall(x) x.rbegin(), x.rend()
#define foreach(it,x) for(typeof(x.begin()) it=x.begin(); it!=x.end(); it++)


int main(){
    map<string,set<int> > msv;
    string in;
    int page,i;

    while( cin >> in >> page ){
        if( msv.count(in) ){
            msv[in].insert(page);
        }
        else{
            set<int> tmp; tmp.insert(page);
            msv[in] = tmp;
        }
    }

    foreach(it,msv){
        cout << it->first << endl;
        i = 0;
        foreach(js,it->second){
            if( i > 0 ) putchar(' ');
            printf("%d",*js);
            i++;
        }
        puts("");
    }

    return 0;
}

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

using namespace std;

typedef map<string, priority_queue<int, vector<int>, greater<int> > > Book; 

int main()
{

    int page;
    string word;
    Book book;

    while(cin >> word >> page)
    {
        book[word].push(page);
    }

    for(Book::iterator it = book.begin(); it != book.end(); it++)
    {
        cout << it->first << endl;
        while(!(it->second.empty()))
        {
            cout << it->second.top();
            cout << (it->second.size() == 1 ? '\n' : ' ');
            it->second.pop();
        }
    }

}

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

using namespace std;

int main(){
    map<string,set<int> >m;
    set<string>s;
    string w;
    int p;
    while(cin>>w>>p){
        if(w==">")break;
        m[w].insert(p);
        s.insert(w);
    }
    set<int>::iterator it;
    set<string>::iterator st;
    for (st = s.begin(); st != s.end(); ++st){
        cout<<*st<<endl;
        it = m[*st].begin();
        if(m[*st].size()>1)
            for (; it != prev(m[*st].end(), 1); ++it)
                cout<<*it<<" ";
        cout<<*it<<endl;
    }
}

C++: #include<bits/stdc++.h>
using namespace std;
int main()
{
    int sen=0,num,page[1000][100]={},nu[1000]={};
    memset(nu,0,sizeof(nu));
    string str[1000],s;
    while(cin>>s>>num){
        for(int i=0;i<sen;i++){
            if(str[i]==s){
                nu[i]++;
                page[i][nu[i]]=num;
                num=0;
                break;
            }
        }
        if(num!=0){
            str[sen]=s;
            page[sen][0]=num;
            sen++;
        }
    }
    int kawa;
    for(int i=0;i<sen;i++){
        for(int j=0;j<sen;j++)if(str[num]>str[j])num=j;
        cout<<str[num]<<endl;
        str[num]="zzzzzzzzzzzzz";
        for(int j=0;j<nu[num];j++){
            for(int k=nu[num];k>0;k--){
                if(page[num][k]<page[num][k-1]){
                    kawa=page[num][k-1];
                    page[num][k-1]=page[num][k];
                    page[num][k]=kawa;
                }
            }
        }
        cout<<page[num][0];
        for(int j=1;j<=nu[num];j++)cout<<" "<<page[num][j];
        cout<<endl;
    }
}

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

int main()
{
	map<string, vector<int>>s;
	string a; int b;
	cin >> a >> b;
	if (cin.fail()) {}
	else {
		vector<int>r(0);
		s.insert(pair<string, vector<int>>(a, r));
		s[a].push_back(b);
		while (1) {
			cin >> a >> b;
			if (cin.fail())break;
			for (auto c = s.begin(); c != s.end(); c++) {
				if (a == c->first) { c->second.push_back(b); break; }
				auto d = c;
				d++;
				if (d == s.end()) { vector<int>r(0); s.insert(pair<string, vector<int>>(a, r));  s[a].push_back(b); break; }
			}
		}
		for (auto e = s.begin(); e != s.end(); e++) {
			sort(e->second.begin(), e->second.end());
			cout << e->first << endl;
			for (int f = 0; f < e->second.size()-1; f++) {
				cout << e->second[f] <<" ";
			}
			cout << e->second[e->second.size() - 1] << endl;
		}
	}
}