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++: 
#define _CRT_SECURE_NO_WARNINGS
#define _USE_MATH_DEFINES
#include <cfloat>
#include <climits>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>
#include <iostream>
#include <memory>
#include <string>

#include <algorithm>
#include <complex>
#include <list>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <stack>
#include <vector>
#include <bitset>

using namespace std;

#ifdef _MSC_VER
#define __typeof__ decltype
#define strtok_r strtok_s
#endif

#define ITER(c)             __typeof__((c).begin())
#define FOREACH(it, c)      for (ITER(c) it=(c).begin(); it != (c).end(); ++it)
#define RITER(c)            __typeof__((c).rbegin())
#define RFOREACH(it, c)     for (RITER(c) it=(c).rbegin(); it != (c).rend(); ++it)
#define REP(i, n)           REPEAT(i, 0, n)
#define RREP(i, n)          RREPEAT(i, 0, n)
#define REPEAT(i, k, n)     for(int i = (k); i < (k+n); ++i)
#define RREPEAT(i, k, n)    for(int i = (k)+(n)-1; i >= (k); --i)
#define FROMTO(i,f,t)       for(int i = f; i < t; i++)
#define ALL(c)              (c).begin(), (c).end()
#define LLPOW(p1,p2)        ((ll)pow((double)(p1), (int)p2))
#define ESIZEOF(A)          (sizeof(A)/sizeof((A)[0]))
#define CIN_NO_SYNC         do { cin.tie(0); ios_base::sync_with_stdio(false); } while(0)
#define GETSTR(p)           fgets((p), sizeof(p), stdin)
#define CHOMP(p)            do{ char *_q = (p) + strlen(p)-1; if(*_q == '\n' || *_q == '\r') *_q = 0; } while(0)
#define FILL(m,v)           memset(m, v, sizeof(m))
#define mp                  make_pair
#define pb                  push_back
template<class _T> _T MAX(_T p1,_T p2){return (p1>p2)?p1:p2;} 
template<class _T> _T MIN(_T p1,_T p2){return (p1<p2)?p1:p2;} 

typedef long long ll;
typedef unsigned long long ull;

#define X real()
#define Y imag()
typedef double D;
typedef complex<D> P;
#define EPS (1e-9)

#ifdef _DEBUG
template<class _T>
inline void _prfe(const char *_n, _T _c, bool _p = false){
    ITER(_c) _it=_c.begin();
    if(_p){ cout<<_n<<" = ["<<endl;for(;_it!=_c.end();++_it)cout<<"    "<<*_it<<endl;cout<<"]"<<endl; }
    else{ cout<<_n<<" = [ "<<*_it++;for(;_it!=_c.end();++_it)cout<<", "<<*_it;cout<<" ]"<<endl; }
}
#define pf printf
#define pr(n) do{cout<<#n" = "<<(n)<<endl;}while(0)
#define prfe(n) _prfe(#n, n)
#define prfep(n) _prfe(#n, n, true)
#define dbgchk(n) do{if(n)throw;}while(0)
#else
#define pf(...) /* */
#define pr(...) /* */
#define prfe(...) /* */
#define prfep(...) /* */
#define dbgchk(...) /* */
#endif

int main(){
    string s;
    int n;
    map<string,set<int> > m;
    while(cin >> s >> n){
        m[s].insert(n);
    }
    FOREACH(it,m){
        cout << it->first << endl;
        bool flag = true;
        FOREACH(jt, it->second){
            if(!flag) cout << " ";
            cout << *jt;
            flag = false;
        }
        cout << endl;
    }
    return 0;
}

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

#define rep(i, n) REP(i, 0, n)
#define ALL(v) v.begin(), v.end()
#define MSG(a) cout << #a << " " << a << endl;
#define REP(i, x, n) for (int i = x; i < n; i++)
#define OP(m) cout << m << endl
typedef long long ll;
typedef unsigned long long ull;

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

    string s;
    int n;
    while (cin >> s >> n)
    {
        mp[s].push_back(n);
    }

    for (auto a : mp)
    {
        OP(a.first);
        sort(ALL(a.second));
        rep(i, a.second.size())
        {
            i != a.second.size() - 1 ? cout << a.second[i] << " " : OP(a.second[i]);
        }
    }

    return 0;
}

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

int main() {
	map<string, vector<int> > book;
	string title;
	int page;
	while(cin >> title >> page) {
		book[title].push_back(page);
	}
	for(map<string, vector<int> >::iterator itr = book.begin(); itr != book.end(); itr++) {
		printf("%s\n", (*itr).first.c_str());
		sort((*itr).second.begin(), (*itr).second.end());
		vector<int>::iterator sc = (*itr).second.begin();
		printf("%d", *sc);
		sc++;
		for(; sc != (*itr).second.end(); sc++) {
			printf(" %d", *sc);
		}
		printf("\n");
	}
	return 0;
}

C++: #include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define rep(i,n) for( int i = 0; i < n; i++ )
#define dump(x)  cerr << #x << " = " << (x) << endl;
#define INF 2000000000
#define mod 1000000007
#define INF2 1000000000000000000

vector<pair<string,int>> str(100000);
int main(void)
{
    cin.tie(0);
    ios::sync_with_stdio(false);
    int count = 0;
    int c_n = 0;
    while (cin >> str[count].first) {
        cin >> str[count].second;
        count++;
    }
    sort(str.begin(), str.begin() + count);
    cout << str[0].first << endl;
    cout << str[0].second;
    for (int i = 1; i < count; i++) {
        if (str[i].first != str[i-1].first) {
            cout << endl << str[i].first << endl;           
        }
        cout << str[i].second << " ";
    }

    return 0;
}

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

int main(){
  string s;
  int n;
  map<string,vector<int>> list;
  while(cin>>s>>n){
    list[s].push_back(n);
  }
  for(auto &i: list){
    cout<<i.first<<endl;
    auto &list = i.second;
    sort(list.begin(),list.end());
    for(int j=0;j<list.size()-1;j++){
      cout<<list[j]<<" ";
    }cout<<list[list.size()-1]<<endl;
  }
}

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

void echo_index(std::multimap<std::string,int> &index);
void echo_page(std::vector<int> &chunk_page);

//------------------------------main----------------------------------
int main()
{
	using namespace std;
	
	string ward;
	int page;
	
	multimap<string,int> index;
	
	for(;1;)
	{
		cin>>ward>>page;
		if(cin.eof())
		{
			echo_index(index);
			break;
		}
		index.insert(pair<string,int>(ward,page));
	}
	
	return 0;
}
//------------------------------------------------------------

void echo_index(std::multimap<std::string,int> &index)
{
	using namespace std;
	
	multimap<string,int>::iterator itr;
	vector<int> chunk_page;
	
	itr=index.begin();
	string pre_ward=itr->first;
	cout<<itr->first<<endl;
	chunk_page.push_back(itr->second);
	++itr;
	
	for(;itr!=index.end();++itr)
	{
		if(pre_ward==itr->first)
		{
			chunk_page.push_back(itr->second);
		}
		else
		{
			echo_page(chunk_page);
			cout<<itr->first<<endl;
			chunk_page.push_back(itr->second);
		}
		pre_ward=itr->first;
	}
	
	echo_page(chunk_page);
}

void echo_page(std::vector<int> &chunk_page)
{
	using namespace std;
	
	sort(chunk_page.begin(),chunk_page.end());
	
	vector<int>::iterator itr;
	itr=chunk_page.begin();
	cout<<*itr;
	++itr;
	
	for(;itr!=chunk_page.end();++itr)
	{
		cout<<" "<<*itr;
	}
	cout<<endl;
	
	chunk_page.clear();
}