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
//------------------------------------------
#include <vector>
#include <list>
#include <map>
#include <set>
#include <deque>
#include <stack>
#include <bitset>
#include <algorithm>
#include <functional>
#include <numeric>
#include <utility>
#include <sstream>
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <cctype>
#include <string>
#include <cstring>
#include <ctime>
#include <fstream>
#include <conio.h>
using namespace std;

//conversion
//------------------------------------------
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();}

//math
//-------------------------------------------
template<class T> inline T sqr(T x) {return x*x;}

//typedef
//------------------------------------------
typedef vector<int> VI;
typedef vector<VI> VVI;
typedef vector<string> VS;
typedef pair<int, int> PII;
typedef pair<long, long> PLL;
typedef long long LL;
//container util
//------------------------------------------
#define ALL(a)  (a).begin(),(a).end()
#define RALL(a) (a).rbegin(), (a).rend()
#define PB push_back
#define MP make_pair
#define SZ(a) int((a).size())
#define EACH(i,c) for(typeof((c).begin()) i=(c).begin(); i!=(c).end(); ++i)
#define EXIST(s,e) ((s).find(e)!=(s).end())
#define SORT(c) sort((c).begin(),(c).end())

//repetition
//------------------------------------------
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n)  FOR(i,0,n)

//constant
//--------------------------------------------
const double EPS = 1e-10;
const double PI  = acos(-1.0);

//clear memory
#define CLR(a) memset((a), 0 ,sizeof(a))




int main(){
	string str;
	vector<pair<string,int>>sp;
	int cnt=0;
	while(cnt==0||kbhit()){
		getline(cin,str);
		string t1="",t2="";
		int i;
		for(i=0;str[i]!=' ';i++){
			t1+=str[i];
		}
		i++;
		for(;i<SZ(str);i++){
			t2+=str[i];
		}
		int num=toInt(t2);
		sp.PB(MP(t1,num));
		cnt++;
	}
	bool c=false;
	SORT(sp);
	REP(i,SZ(sp)){
		if(!c)cout<<sp[i].first<<endl;
		if(i!=SZ(sp)-1&&sp[i].first==sp[i+1].first){
			cout<<sp[i].second<<" ";
			c=true;
		}else{
			c=false;
			cout<<sp[i].second<<endl;
		}
		
	}
	return 0;
}

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

using namespace std;

int main(int argc, char *argv[]) {
  string word;
  int page;
  multimap<string, int> mm;
  while (cin >> word >> page)
    mm.insert(pair<string, int>(word, page));

  set<int> pages;
  word = "";
  for (multimap<string, int>::iterator itr = mm.begin();
       itr != mm.end(); itr++) {
    if (word != itr->first && !pages.empty()) {
      for (set<int>::iterator jtr = pages.begin();
           jtr != pages.end(); jtr++) {
        if (jtr != pages.begin())
          cout << ' ';
        cout << *jtr;
      }
      cout << endl;
      pages.clear();
      cout << itr->first << endl;
    } else if (word != itr->first) {
      cout << itr->first << endl;
    }
    word = itr->first;
    pages.insert(itr->second);
  }
  if (!pages.empty())
    for (set<int>::iterator jtr = pages.begin();
         jtr != pages.end(); jtr++) {
      if (jtr != pages.begin())
        cout << ' ';
      cout << *jtr;
    }
  cout << endl;
  return 0;
}

C++: #include <iostream>
#include <queue>
#include <map>
#include <algorithm>
using namespace std;
int main(){
  string word;
  int num;
  map<string,vector<int> > index;
  while(cin >> word >> num){
    index[word].push_back( num );
  }

  for(map< string,vector<int> > ::iterator it = index.begin(); it != index.end() ; it++){
    vector<int>ve;
    ve = it->second;
    sort(ve.begin(),ve.end());
    cout << it->first << endl;
    for(vector<int>::iterator itt = ve.begin() ; itt != ve.end() ; itt++){
      if(ve.begin() == itt)cout << *itt;
      else  cout <<" "<< *itt;
    }
    cout << endl;
  }
  return 0;
}

C++: #include <stdio.h>
#include <string.h>

int main(void)
{
	char words[100][30] = {"\0"};
	char temp1[30];
	int number[100] = {0};
	int temp2;
	int i, j, k, n, m, t;

	for(i = 0; scanf("%s %d*c", words[i], &number[i]) != EOF; i++)
		;

	for (k = 0; k < 99; k++)
		for (i = 0; i < 100; i++)
			if (words[i + 1][0] != 0)
				for (j = 0; j < 30; j++)
					if (words[i][j] > words[i+1][j])
					{
						strcpy(temp1, words[i]);
					    strcpy(words[i], words[i+1]);
					    strcpy(words[i+1], temp1);

					    temp2 = number[i];
						number[i] = number[i+1];
						number[i+1] = temp2;

					    break;
					}
					else if (words[i][j] == words[i+1][j])
						continue;
					else
						break;
			else
				break;

	for (i = 0; i < 100; i++)
	{
		if (words[i][0] == NULL)
			break;
		if (strcmp(words[i], words[i+1]) != 0)
		{
			printf("%s\n", words[i]);
			printf("%d\n", number[i]);
		}
		else
		{
			for (n = 0; strcmp(words[i+n], words[i+n+1]) == 0; n++)
				;
			printf("%s\n", words[i]);

			for (t = 0; t < n; t++)
				for (m = 0; m < n; m++)
					if (number[i+m] > number[i+m+1])
					{
						temp2 = number[i+m];
						number[i+m] = number[i+m+1];
						number[i+m+1] = temp2;
					}

			for (m = 0; m <= n; m++)
			{
				printf("%d", number[i+m]);
				if (m == n)
					printf("\n");
				else
					printf(" ");
			}

			i += n;
		}
	}

	return 0;
}

C++: #include <vector>
#include <list>
#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>
#include <cassert>
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)
#define EACH(t,i,c) for(t::iterator i=(c).begin(); i!=(c).end(); ++i)
const double EPS = 1e-10;
const double PI  = acos(-1.0);

int main(){
	map<string,vi> se;
	string s;
	while(cin>>s){
		int n;
		cin>>n;
		if(!EXIST(se,s)){
			se[s]=vi();
		}
		se[s].push_back(n);
	}
	for(map<string,vi>::iterator it=se.begin();it!=se.end();it++){
		cout<<(*it).first<<endl;
		sort(ALL((*it).second));
		REP(i,(*it).second.size()){
			cout<<(i==0?"":" ")<<(*it).second[i];
		}
		cout<<endl;
	}
}