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 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() {
	map<string, vi> table;
	string s;
	int p;

	while(cin >> s) {
		cin >> p;
		table[s].push_back(p);
	}

	map<string, vi>::iterator it = table.begin();
	while(it != table.end()) {
		cout << (*it).first << endl;
		sort(ALL((*it).second));
		bool flag = false;
		REP(i, (*it).second.size()) {
			if(flag)
				cout << " ";
			cout << (*it).second[i];
			flag = true;
		}
		cout << endl;
		++it;
	}

	return 0;
}

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

int main(){
  std::string s;
  int p;
  std::map<std::string,std::vector<int> > m;
  while(std::cin>>s>>p,p!=0){
    m[s].push_back(p);
  }
  std::map<std::string,std::vector<int> >::iterator m_it = m.begin();
  while(m_it!=m.end()){
    std::cout<<(*m_it).first<<std::endl;
    std::sort((*m_it).second.begin(),(*m_it).second.end());
    std::vector<int>::iterator v_it = (*m_it).second.begin();
    while(v_it!=(*m_it).second.end()){
      std::cout<<*v_it;
      v_it++;
      (v_it==(*m_it).second.end())?std::cout<<std::endl:std::cout<<" ";
    }
    m_it++;
  }
  return 0;
}

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

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

int main()
{
    P p;
    string str[MAX];
    int i = 0;
    while (cin >> str[i]) {
        int t;
        cin >> t;
        p[str[i]].push_back(t);
        i++;
    }
    for (int k = 0; k < i; k++) {
        sort(p.at(str[k]).begin(), p.at(str[k]).end());
    }
    sort(str, str + i);
    string s = str[0];
    for (int k = 0; k < i; k++) {
        s = str[k];
        cout << s << endl << p[s][0];
        for (int j = 1; j < p[s].size(); j++) {
            cout << " " << p[s][j];
        }
        cout << endl;
        while (i > k && str[k] == s) k++;
        k--;
    }

    return 0;
}

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

using namespace std;

typedef map< string, set<int> > Dic;
Dic dic;

int main(){
  //map<string, int> dic;
  int num;
  string s;
  while(cin >> s >> num)
  {
    dic[s].insert(num);
  }
  
  for(Dic::iterator it = dic.begin() ; it != dic.end() ; it++)
  {
  	cout << it->first << endl;
  	for(set<int>::iterator set_it = it->second.begin() ; set_it != it->second.end() ; set_it++)
  	{
  		cout << *set_it << " ";
  	}
  	cout << endl;
  }

  return 0;
}

C++: #include<cstdio>
#include<cmath>
#include<string>
#include<vector>
#include<queue>

using namespace std;

#define PSI pair<string,int>

vector<PSI> book;

int main(void){
	int x;
	char tmp[1024];
	while(scanf("%s%d",tmp,&x)!=EOF){
		string a;
		a = tmp;
		book.push_back(PSI(a,x));
	}
	
	sort(book.begin(),book.end());
	
	for(int i = 0; i < book.size(); i++){
		vector<int> ans;
		puts(book[i].first.c_str());
		ans.push_back(book[i].second);
		while(i+1<book.size() && book[i+1].first==book[i].first){
			i++;
			ans.push_back(book[i].second);	
		}
		sort(ans.begin(),ans.end());
		for(int j = 0; j < ans.size(); j++){
			if(j != 0)printf(" ");
			printf("%d",ans[j]);
		}puts("");
		
	}
	return 0;
}

C++: #define _CRT_SECURE_NO_WARNINGS

#include <iostream>
#include <stdio.h>
#include <string>
#include <string.h>
#include <queue>
#include <cmath>
#include <stack>
#include <map>
#include <vector>
#include <algorithm>

#define int64 long long int

using namespace std;

int main()
{
	int page, c, flag;
	string buf, word[1001];
	string index[100];
	
	c = 0;
	while(cin >> buf >> page){
		if(index[0].empty()) {
			index[0] = buf;
			c++;
		} else {
			flag = 0;
			for(int i=0; i<c; i++){
				if(index[i] == buf){
					flag = 1;
					break;
				}
			}
			if(flag == 0){
				index[c] = buf;
				c++;
			}
		}
		word[page] = buf;
	}

	for(int i=0; i<=c-2; i++){
		for(int j=c-2; j>=i; j--){
			if(index[j] > index[j+1]){
				buf = index[j];
				index[j] = index[j+1];
				index[j+1] = buf;
			}
		}
	}

	for(int i=0; i<c; i++){
		cout << index[i] << endl;
		flag = 0;
		for(int j=1; j<=1000; j++){
			if(index[i] == word[j]){
				if(flag == 1) cout << ' ';
				flag = 1;
				cout << j;
			}
		}
		cout << endl;
	}

	return 0;
}

C++: #include <iostream>   
#include <string>   
#include <set>   
#include <map>   
using namespace std;   
  
int main()   
{   
    int n;   
    string str;   
    map<string, set<int> > m;   
    map<string, set<int> >::iterator p;   
  
    while (cin >> str>> n)   
        m[str].insert(n);   
  
    for (p = m.begin(); p != m.end(); p++)   
    {   
        cout << p->first << endl;   
        set<int>::iterator q = (p->second).begin();   
        for (; q != (p->second).end(); )   
        {   
            cout << *q;   
            cout << (++q != (p->second).end() ? ' ' : '\n');   
        }   
    }   
  
    return 0;   
}

C++: #define _CRT_SECURE_NO_WARNINGS
#include "bits/stdc++.h"
using namespace std;
#define rep(i, n) for(int i=0; i<(n); ++i)
#define FOR(i, m, n) for(int i=(m); i<(n); ++i)
#define sz(x) ((int)(x).size())
#define all(x) (x).begin(),(x).end()
#define mp make_pair
#define pb push_back
#define Cout(x) cout << (x) << endl
#define Cout2(x, y) cout << (x) << " " << (y) << endl
#define dump(x) cout << #x << " = " << (x) << endl;
#define forauto(i, a) for(auto i : a)cout << i << " "; puts("");
typedef long long LL;
typedef vector<int> VI;
typedef vector<LL> VL;
typedef vector<string> VS;
typedef vector<bool> VB;
typedef vector<vector<int>> VVI;
typedef pair<int, int> PII;
const int inf = 1e9;
const double pi = acos(-1.0);

int main() {
	map<string, vector<int>> m;
	string s; int p;
	while (cin >> s >> p) {
		m[s].pb(p);
	}

	for (auto a : m) {
		string str = a.first;
		VI vec = a.second;
		sort(all(vec));

		Cout(str);
		rep(i, sz(vec))cout << vec[i] << (i == sz(vec) - 1 ? "\n" : " ");
	}
}