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 <vector>
#include <map>
#include <set>
#include <stack>
#include <queue>
#include <deque>
#include <algorithm>
#include <utility>
#include <functional>
#include <sstream>
#include <iostream>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <cctype>
#include <string>
#include <cstring>
#include <ctime>
#include <climits>
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();}
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 EACH(t,i,c) for(t::iretator i=(c).begin(); i!=(c).end(); ++i)
#define EXIST(s,e) ((s).find(e)!=(s).end())
#define FOR(i,a,b) for(int i=(a);i<=(b);++i)
#define REP(i,n) FOR(i,0,n-1)
const double EPS = 1e-10;
const double PI = acos(-1.0);

int main() {
	string s;
	map<int, string> table;
	vs name;
	vi page;

	while(cin >> s) {
		int p;
		cin >> p;
		name.push_back(s);
		page.push_back(p);
		table[p] = s;
	}

	sort(ALL(name));
	sort(ALL(page));

	REP(i, name.size()) {
		cout << name[i] << endl;
		REP(j, page.size()) {
			if(table[page[j]] == name[i]) {
				cout << page[j] << " ";
			}
			cout << endl;
		}
	}

	return 0;
}

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

int main(){
  map<string,vector<int> >m;
  string s;int x,f;
  for(;cin>>s>>x;)
    m[s].push_back(x);
  map<string,vector<int> >::iterator it=m.begin();
  for(;it!=m.end();it++){
    cout<<(*it).first<<endl;
    for(f=0;f<(*it).second.size();f++){
      if(f)cout<<' ';
      cout<<(*it).second[f];
    }
    cout<<endl;
  }
}

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

int main()
{
    map<string,set<int>> p;
    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 <string>
#include <vector>
#include <algorithm>
#include <map>
using namespace std;

int main(){
  map<string,vector<int> >m;
  string s;int x,f;
  for(;cin>>s>>x;)
    m[s].push_back(x);
  map<string,vector<int> >::iterator it=m.begin();
  for(;it!=m.end();it++){
    cout<<(*it).first<<endl;
    vector<int>v=(*it).second;
    sort(v.begin(),v.end());
    for(f=0;f<v.size();f++){
      if(f)cout<<' ';
      cout<<v[f];
    }
    cout<<endl;
  }
}

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

using namespace std;

typedef map<string, vector<int> > M;

int main() {
  M pairs;
  string word;
  while (cin >> word) {
    int page;
    cin >> page;
    pairs[word].push_back(page);
  }
  for (M::iterator i = pairs.begin(); i != pairs.end(); ++i) {
    cout << i->first << endl;
    sort(i->second.begin(), i->second.end());
    for (vector<int>::iterator j = i->second.begin(); j != i->second.end(); ++j)
      cout << *j << ' ';
    cout << endl;
  }
  return 0;
}

C++: #include<bits/stdc++.h>
using namespace std;
map<string,priority_queue<int,vector<int>,greater<int> > > Map;
signed main(void){
	ios::sync_with_stdio(false);
	string s;int page;
	while(cin>>s>>page)	Map[s].push(page);
	for(map<string,priority_queue<int,vector<int>,greater<int> > >::iterator it=Map.begin();it!=Map.end();++it,cout<<endl){
		cout<<it->first<<endl;
		for(int fst=1;!it->second.empty();it->second.pop(),fst=0){
			if(!fst)cout<<" ";
			cout<<it->second.top();
		}
	}
}

C++: int main(){
  string a;
  int b;
  map<string,set<int> > kok;
  map<string,set<int> >::iterator it;
  while(cin >> a >> b){
    it = kok.find(a);
    if(it != kok.end())
      it->second.insert(b);
    else{
      set<int> p;
      p.insert(b);
      kok[a] = p;
    }
  }
  for(it=kok.begin(); it!=kok.end(); ++it){
    cout << it->first << endl;
    set<int>::iterator i;
    int u = 0;
    for(i=it->second.begin(); i!=it->second.end(); ++i){
      cout << *i;
      if(u != it->second.size()-1)
	cout << " ";
      u++;
    }
    cout << endl;
  }

  return 0;
}

C++: #include<iostream>
#include<algorithm>
#include<vector>
#include<string>
#include<map>
 
using namespace std;
#define rep(i,j) for(int i = 0; i < (j); i++)
int main(){
    map< string, vector<int> > data;
    string str;
    int page;
    while(cin >> str >> page){
        data[str].push_back(page);
    }
    map< string, vector<int> >::iterator it = data.begin();
    while(it != data.end()){
        cout << (*it).first << endl;
        int len = (*it).second.size();
        if(len == 1)cout << (*it).second[0] << endl;
        else{
            sort((*it).second.begin(),(*it).second.end());
            rep(i,len-1){
                cout << (*it).second[i] << " ";
            }
            cout << (*it).second[len-1] << endl;
        }
        it++;
    }
    return 0;
}

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

#define f first
#define s second
#define mp make_pair

#define REP(i,n) for(int i=0; i<(int)(n); i++)
#define FOR(i,c) for(__typeof((c).begin()) i=(c).begin(); i!=(c).end(); i++)
#define ALL(c) (c).begin(), (c).end()

using namespace std;

typedef unsigned int uint;
typedef long long ll;

int main(){
  map<string,set<int> > m;
  string str;
  int n;
  while(cin>>str>>n) m[str].insert(n);
  FOR(mit,m){
    bool f = false;
    cout << mit->first << endl;
    FOR(sit,mit->second){
      if(!f){
        f = true;
      }else{
        cout << " ";
      }
      cout << *sit;
    }
    cout << endl;
  }
  return 0;
}

C++: #include <iostream>
#include <iomanip>
#include <algorithm>
#include <vector>
#include <stack>
#include <queue>
#include <map>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>

using namespace std;

int main() {
	map<string, vector<int> > index;
	string word;
	int page;
	while (cin >> word >> page) {
		index[word].push_back(page);
	}
	map<string, vector<int> >::iterator it = index.begin();
	while (it != index.end()) {
		cout << it->first << endl;
		vector<int> v = it->second;
		sort(v.begin(), v.end());
		int ifs = 1;
		vector<int>::iterator itv = v.begin();
		while (itv != v.end()) {
			if (ifs == 0)
				cout << " ";
			cout << *itv;
			ifs = 0;
			itv++;
		}
		cout << endl;
		it++;
	}

	return 0;
}