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 <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++) {
        cout << it->first  << endl << it->second[0];
        for (int j = 1; j < it->second.size(); j++)
            cout << " " << it->second[j];
        cout << endl;
    }

    return 0;
}

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

#define loop(v, f, l) for(int v = (f), v##_ = (l); v < v##_; ++v)

using namespace std;

typedef long long int lint;
static inline int in(){ int x; scanf("%d", &x); return (x); }
static inline lint inl(){ lint x; scanf("%lld", &x); return (x); }

int main()
{
	map<string, vector<int> > index;
	pair<string, vector<int> > word_page;
	string word;
	int page;
	while( cin >> word >> page )
	{
		index[word].push_back(page);
	}

	for(map<string, vector<int> >::iterator it = index.begin(); it != index.end(); it++)
	{
		vector<int> v = it->second;
		sort(v.begin(), v.end());

		cout << it->first << endl;
		vector<int>::iterator itv = v.begin();
		for(; itv + 1 != v.end(); itv++)
		{
			cout << *itv << " ";
		}
		cout << *itv << endl;
	}

	return (0);
}

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

int main(){
    string str;
    int page;
    map<string, vector<int> > dict;
    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(int i=0; i<(int)it->second.size(); i++){
            cout << it->second[i] ;
            cout << ((i<(int)it->second.size()-1)?' ':'\n');
         }
    }
    return 0;
}

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



int main(){
	map<string,vector< int > > data;
	vector<string> words;
	string tmpWord;
	int tmpPage;
	while(cin>>tmpWord>>tmpPage){
		words.push_back(tmpWord);
		data[tmpWord].push_back(tmpPage);
	}
	int s=words.size();
	sort(words.begin(),words.end());
	for(int i=0;i<s;i++){
		if(i!=0)if(words[i]==words[i-1])continue;
		cout<<words[i]<<endl;
		sort(data[words[i]].begin(),data[words[i]].end());
		int si=data[words[i]].size();
		for(int j=0;j<si;j++){
			if(j!=0)cout<<" ";
			cout<<data[words[i]][j];
		}
		cout<<endl;
	}
}

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

typedef pair<string,int> P;

int main(){
  string str;
  int page,cnt=0;
  vector<P> v;

  while(cin >> str >> page){
    v.push_back(P(str,page));
    cnt++;
  }

  sort(v.begin(),v.end());
  for(int i = 0 ; i < cnt; i++){
    if(i==0){
      cout << v[i].first << endl;
      cout << v[i].second;
      continue;
    }

    if(v[i].first == v[i-1].first && v[i].second!=v[i-1].second){
      cout << ' ' << v[i].second;
      continue;
    }
    else cout << endl;

    cout << v[i].first << endl;
    cout << v[i].second;
    }

  puts("");

  return 0;
}

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

using namespace std;

#define dump(n) cout<<"# "<<#n<<"="<<(n)<<endl
#define debug(n) cout<<__FILE__<<","<<__LINE__<<": #"<<#n<<"="<<(n)<<endl
#define repi(i,a,b) for(int i=int(a);i<int(b);i++)
#define rep(i,n) repi(i,0,n)
#define iter(c) __typeof((c).begin())
#define foreach(i,c) for(iter(c) i=(c).begin();i!=(c).end();i++)
#define allof(c) (c).begin(),(c).end()
#define mp make_pair

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

int main()
{
	string s;
	int n;
	map<string,vi> res;
	while(cin>>s>>n)
		res[s].push_back(n);
	
	foreach(i,res){
		cout<<i->first<<endl;
		sort(allof(i->second));
		rep(j,i->second.size())
			cout<<i->second[j]<<(j==i->second.size()-1?'\n':' ');
	}
	
	return 0;
}

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

using namespace std;

int main(void){
  map<string, set<int> > m;
  map<string, set<int> >::iterator it;
  set<int>::iterator itr;
  string s;
  int n;

  while(cin>>s>>n){
    m[s].insert(n);
  }
  for(it=m.begin();it!=m.end();it++){
    cout <<(*it).first<<endl;
    for(itr=(*it).second.begin();itr!=(*it).second.end();itr++,cout<<" "){
      cout<< *itr;
    }
    cout <<endl;
  }
  
}

C++: #include <bits/stdc++.h>
using namespace std;

#define iota(i,n,b,s) for(int i=int(b);i!=int((b)+(s)*(n));i+=(s))
#define range(i,n,m) iota(i,(((n)>(m))?((n)-(m)+1):((m)-(n)+1)),(n),((n)>(m)?-1:1))
#define rep(i,n) iota(i,(n),0,1)

#define INF (1e9)
#define EPS (1e-9)
#define cons(a,b) (make_pair(a,b))
#define car(a) (a.first)
#define cdr(a) (a.second)
#define cadr(a) (car(cdr(a)))
#define cddr(a) (cdr(cdr(a)))
#define all(a) a.begin(), a.end()
#define trace(var) cerr<<">>> "<<#var<<" = "<<var<<endl;

typedef long long Integer;
typedef double Real;

template<class S, class T>
ostream& operator<<(ostream& os, pair<S,T> p) {
  os << '(' << car(p) << ", " << cdr(p) << ')';
  return os;
}

template<class T>
ostream& operator<<(ostream& os, vector<T> v) {
  os << v[0];
  for (int i=1, len=v.size(); i<len; ++i) os << ' ' << v[i];
  return os;
}

int dx[] = { -1, 0, 1, 0 };
int dy[] = {  0, -1, 0, 1 };

int cost_a (int n) {
  int r = (n % 5) * 380;
  r += (n - (n%5)) * 38 * 8;
  return r;
}

int cost_b (int n) {
  int r = (n % 4) * 550;
  r += (n - (n % 4)) * 55 * 85 / 10;
  return r;
}

int cost_c (int n) {
  int r = (n%3)*850;
  r += (n-(n%3)) * 88 * 85 / 10;
  return r;
}

int main() {
  map<string, vector<int>> s;
  for (;;) {
    string w; cin >> w;
    if (!cin) break;
    int p; cin >> p;
    s[w].push_back(p);
  }
  for (auto&x : s) {
    cout << car(x) << endl;
    sort(all(cdr(x)));
    cout << cdr(x)[0];
    iota (i, cdr(x).size() - 1, 1, 1) cout << ' ' << cdr(x)[i];
    cout << endl;
  }
    
  return 0;
}