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 cnt=0;
	while(cnt==0||kbhit()){
		getline(cin,str);
		string t1="",t2="";
		int i;
		for(i=0;str[i]!=' ';i++){
			t1+=str[i];
		}
		i++;
		for(;i<SZ(str);i++){
			t2+=str[i];
		}
		int num=toInt(t2);
		sp.PB(MP(t1,num));
		cnt++;
	}
	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 <iostream>
#include <vector>
#include <map>
#include <string>
#include <algorithm>
using namespace std;
typedef map<string,int> M;

int main(){
	M words;
	vector<int> pages[100];
	string word;
	int page,idx=0;

	while(cin>>word){
		cin>>page;
		if(words.empty() || words.find(word)==words.end()) words[word]=idx++;
		pages[words[word]].push_back(page);
	}

	for(M::iterator it=words.begin();it!=words.end();it++){
		cout<<(*it).first<<endl;
		sort(pages[(*it).second].begin(),pages[(*it).second].end());
		for(int i=0;i<pages[(*it).second].size();i++){
			cout<<pages[(*it).second][i];
			if(i!=pages[(*it).second].size()-1) cout<<" ";
		}
		cout<<endl;
	}
	return 0;
}

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 );
  }
  map< string, set<int> >::iterator it1 = index.begin();
  set<int>::iterator it2;
  while( it1 != index.end() ){
    cout << (*it1).first << endl;
    it2 = index[(*it1).first].begin();
    cout << *it2;
    it2++;
    while( it2 != index[(*it1).first].end() ){
      cout << ' ' << *it2;
      it2++;
    }
    cout << endl;
    it1++;
  }
  return 0;
}

C++: #include <iostream>
#include <map>
#include <utility>
#include <vector>
#include <algorithm>
using namespace std;
#define F first
#define S second
#define MP make_pair
#define PB push_back
int main(){
    string s;
    int n;
    vector<int> emp;
    map<string,vector<int>> m;
    while(cin>>s){
        cin>>n;
        if(m.find(s)==m.end())m.insert(MP(s,emp));
        m[s].PB(n);
    }
    for(auto u:m){
        sort(u.S.begin(),u.S.end());
        cout<<u.F<<endl<<u.S[0];
        for(int j=1;j<u.S.size();j++)cout<<" "<<u.S[j];
        cout<<endl;
    }
}

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

using namespace std;
  
typedef long long ll;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef pair<int,int> pii;
#define REP(i,n) for(ll i=0;i<n;++i)
#define REPR(i,n) for(ll i=1;i<n;++i)
#define FOR(i,a,b) for(ll i=a;i<b;++i)
  
#define DEBUG(x) cout<<#x<<": "<<x<<endl
#define DEBUG_VEC(v) cout<<#v<<":";REP(i,v.size())cout<<" "<<v[i];cout<<endl
#define ALL(a) (a).begin(),(a).end()
  
#define MOD (ll)(1e9+7)
#define ADD(a,b) a=((a)+(b))%MOD
#define FIX(a) ((a)%MOD+MOD)%MOD

typedef long double Real;
#define EPS 1e-13
#define EQ(x) (-EPS<x && x<EPS)
typedef complex<Real> P;
Real dot(P a,P b){return real(conj(a)*b);}
Real cross(P a,P b){return imag(conj(a)*b);}

#define MP make_pair<int,int>

int main(){
  map<string,vi> M;
  char __s[2521];
  while(~scanf("%s",__s)){
    int a;
    cin>>a;
    if(a==1145141919)break;
    M[string(__s)].push_back(a);
  }
  map<string,vi>::iterator iter = M.begin();
  while(iter!=M.end()){
    vi V = iter->second;
    sort(ALL(V));
    cout<<(iter->first)<<endl;
    cout<<V[0];
    REPR(i,V.size())cout<<" "<<V[i];
    cout<<endl;
    ++iter;
  }
  return 0;
}

C++: #include<iostream>
#include<sstream>
#include<fstream>
#include<cstdio>
#include<vector>
#include<list>
#include<stack>
#include<queue>
#include<deque>
#include<string>
#include<map>
#include<set>
#include<algorithm>
#include<cmath>
#include<cstdlib>
using namespace std;

int main(){
	map< string, map<int,int> > table;
	char mat[50];
	int n;
	while(scanf("%s %d",mat,&n)==2){
		string word(mat);
		table[word][n]++;
	}
	for(map<string, map<int,int> >::iterator it = table.begin();it!=table.end();++it){
		cout<<it->first<<endl;
		map<int,int> w = it->second;
		for(map<int,int>::iterator it2 = w.begin();it2!=w.end();++it2){
			cout<<it2->first<<" ";
		}
		cout<<endl;
	
	}
	return 0;		
}

C++: #include<iostream>
#pragma warning(disable:4786)
#include<map>
#include<vector>
#include<string>
#include<algorithm>
using namespace std;
int main() {
	string a;
	map<string, vector<int>> d;
	while(getline(cin,a)){
		string b, h = "";
		int c, sum = 0;
		a += " ";
		for (int i = 0; i < a.length(); i++) {
			if (a[i] == ' ') {
				if (sum == 0)
					b = h;
				else
					c = atoi(h.c_str());
				sum++;
				h = "";
			}
			else
				h += a[i];
		}
		d[b].push_back(c);
		d[b].clear();
		d[b].push_back(c);
	}
	map<string, vector<int>>::iterator t = d.begin();
	while (t != d.end()) {
		string k = (*t).first;
		sort(d[k].begin(), d[k].end());
		cout << k;
		for (int i = 0; i != d[k].size(); i++) {
			cout << " " << d[k][i];
		}
		cout << endl;
		t++;
	}
	for (int i = 0; i < 100000000000; i++) {
		for (int j = 0; j < 1000000000000000; j++) {
			for (int z = 0; z < 100000000000; z++) {

			}
		}
	}
}