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 <bits/stdc++.h>
using namespace std;
#pragma GCC optimize("Ofast")
#define all(x) (x).begin(),(x).end()
#define rep(i,n) for(int (i)=0;i<(n);i++)
#define REP(i,m,n) for(int (i)=(m);(i)<(n);(i)++)
#define INF LLONG_MAX - 100
#define MOD 1000000007
#define fcout cout << fixed << setprecision(15)
#define int long long
#define yorn(f) puts((f)?"Yes":"No")
#define YORN(f) puts((f)?"YES":"NO")
#define lowb lower_bound
#define upb upper_bound
typedef long long ll;
typedef pair<int, int> P;
typedef priority_queue<int> pque;
int gcd(int a,int b){return b?gcd(b,a%b):a;};
int lcm(int a,int b){return a/gcd(a,b)*b;};
int mod(int a,int b){return (a+b-1)/b;};
int month[12] = {31,28,31,30,31,30,31,31,30,31,30,31};
template<typename A, size_t N, typename T>
void Fill(A(&array)[N],const T &val){std::fill((T*)array,(T*)(array+N),val);}
template<class T>inline bool chmax(T& a,T b){if(a<b){a=b;return true;}return false;};
template<class T>inline bool chmin(T& a,T b){if(a>b){a=b;return true;}return false;};



signed main() {
	cin.tie(0);
	cout.tie(0);
	ios::sync_with_stdio(false);

	string word;
	map< string, set<int> > m;
	while(cin >> word) {
		int page;
		cin >> page;
		m[word].insert(page);
	}

	for(auto& p: m) {
		cout << p.first << endl;
		for(auto it = p.second.begin(); it != p.second.end(); ++it) {
            if(it != p.second.begin()) {
                cout << ' ';
            }
            cout << *it;
        }
        cout << endl;
	}
	return 0;
}

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

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++: /*
	0105:book Index
*/
#include	<iostream>
#include	<vector>
#include	<utility>
#include	<string>
#include	<algorithm>

using namespace std;

typedef pair<string, int> P_SI;

int main(void) {
	string memstr = " ";
	vector<P_SI> words;
	
	while(1) {
		string buf_s;
		int buf_i;
		
		cin >> buf_s >> buf_i;
		if(cin.eof()) { break; }
		words.push_back( P_SI(buf_s, buf_i) );
	}
	sort( words.begin(), words.end() );
	
	vector<P_SI>::iterator it = words.begin();
	bool isFirst = true;
	while( it != words.end() ) {
		string buf_s = (*it).first;
		int buf_i = (*it).second;
		
		if(buf_s != memstr) {
			if(it != words.begin()) {
				cout << endl;
			}
			cout << buf_s << endl;
			memstr = buf_s;
			isFirst = true;
		}
		if(isFirst) {
			cout << buf_i;
			isFirst = false;
		} else {
			cout << ' ' << buf_i;
		}
		it++;
	}
	cout << endl;
	return 0;
}

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

int main() {
	vector<string> words;
	vector<vector<int> > pages;
	string word; int page;
	while(cin>>word>>page) {
		bool is_there = false; int word_place;
		for (int i = 0; i < words.size(); i++) {
			if (word == words[i]) {
				is_there = true;
				word_place = i;
			}
		}
		if (is_there) {
			pages[word_place].push_back(page);
		}
		else {
			words.push_back(word);
			vector<int>* x = new vector<int>;
			pages.push_back(*x);
			pages[pages.size() - 1].push_back(page);
		}
	}
	for (int i = 0; i < words.size() - 1; i++) {
		for (int j = 0; j < words.size() - 1; j++) {
			if (words[j] > words[j + 1]) {
				string tmp_w=words[j];
				words[j] = words[j + 1];
				words[j + 1] = tmp_w;
				vector<int> tmp_p=pages[j];
				pages[j] = pages[j + 1];
				pages[j + 1] = tmp_p;
			}
		}
	}
	for (int i = 0; i < words.size(); i++) {
		for (int j = 0; j < pages[i].size()-1; j++) {
			for (int c = 0; c < pages[i].size()-1; c++) {
				if (pages[i][c] > pages[i][c + 1]) {
					int tmp=pages[i][c];
					pages[i][c] = pages[i][c + 1];
					pages[i][c + 1] = tmp;
					}
			}
		}
	}
	for (int i = 0; i < words.size(); i++) {
		cout << words[i] << endl;
		for (int m = 0; m < pages[i].size(); m++) {
      if(pages[i].size()-1==m)cout<<pages[i][m];
			else cout << pages[i][m]<<' ';
		}
		cout << endl;
	}
}

C++: #include <iostream>
#include <iomanip>
#include <cstdio>
#include <string>
#include <cstring>
#include <deque>
#include <list>
#include <queue>
#include <stack>
#include <vector>
#include <utility>
#include <algorithm>
#include <map>
#include <set>
#include <complex>
#include <cmath>
#include <limits>
#include <cfloat>
#include <climits>
#include <ctime>
#include <cassert>
#include <numeric>
using namespace std;

#define rep(i,a,n) for(int (i)=(a); (i)<(n); (i)++)
#define repq(i,a,n) for(int (i)=(a); (i)<=(n); (i)++)
#define repr(i,a,n) for(int (i)=(a); (i)>=(n); (i)--)
#define all(v) begin(v), end(v)
#define pb(a) push_back(a)
#define fr first
#define sc second
#define INF 2000000000
#define int long long int

#define X real()
#define Y imag()
#define EPS (1e-10)
#define EQ(a,b) (abs((a) - (b)) < EPS)
#define EQV(a,b) ( EQ((a).X, (b).X) && EQ((a).Y, (b).Y) )
#define LE(n, m) ((n) < (m) + EPS)
#define LEQ(n, m) ((n) <= (m) + EPS)
#define GE(n, m) ((n) + EPS > (m))
#define GEQ(n, m) ((n) + EPS >= (m))

typedef vector<int> VI;
typedef vector<VI> MAT;
typedef pair<int, int> pii;
typedef long long ll;

typedef complex<double> P;
typedef pair<P, P> L;
typedef pair<P, double> C;

int dx[]={1, -1, 0, 0};
int dy[]={0, 0, 1, -1};
int const MOD = 1000000007;
ll mod_pow(ll x, ll n) {return (!n)?1:(mod_pow((x*x)%MOD,n/2)*((n&1)?x:1))%MOD;}
int madd(int a, int b) {return (a + b) % MOD;}
int msub(int a, int b) {return (a - b + MOD) % MOD;}
int mmul(int a, int b) {return (a * b) % MOD;}
int minv(int a) {return mod_pow(a, MOD-2);}
int mdiv(int a, int b) {return mmul(a, minv(b));}

namespace std {
    bool operator<(const P& a, const P& b) {
        return a.X != b.X ? a.X < b.X : a.Y < b.Y;
    }
}

typedef pair<string, int> psi;

signed main() {
    string s; int n;
    vector<psi> vs;
    while(cin >> s >> n) {
        cin.ignore();
        vs.push_back(make_pair(s, n));
    }
    sort(vs.begin(), vs.end());
    string prev = "A";
    rep(i,0,vs.size()) {
        if(prev != vs[i].first) {
            if(prev != "A") cout << endl;
            cout << vs[i].first << endl;
            printf("%lld", vs[i].second);
            prev = vs[i].first;
        }
        else printf(" %lld", vs[i].second);
    }
    cout << endl;
    return 0;
}