Go: package main

import (
	"bufio"
	"fmt"
	"os"
	"sort"
)

var scanner = bufio.NewScanner(os.Stdin)

func main() {
	dictionary := make(map[string][]int)

	for {
		var word string
		var page int
		fmt.Scanf("%s %d", &word, &page)

		if word == "" || page == 0 {
			break
		}

		pages := dictionary[word]
		pages = append(pages, page)
		dictionary[word] = pages
	}

	words := make([]string, 0)
	for i := range dictionary {
		words = append(words, i)
	}

	sort.Strings(words)

	for _, v := range words {
		sort.Ints(dictionary[v])
		fmt.Println(v)
		for i, page := range dictionary[v] {
			if i == len(dictionary[v])-1 {
				fmt.Printf("%d\n", page)
			} else {
				fmt.Printf("%d ", page)
			}
		}
	}
}

C++: #include<map>
#include<set>
#include<list>
#include<cmath>
#include<queue>
#include<stack>
#include<cstdio>
#include<string>
#include<vector>
#include<complex>
#include<cstdlib>
#include<cstring>
#include<numeric>
#include<sstream>
#include<iostream>
#include<algorithm>
#include<functional>

#define mp       make_pair
#define pb       push_back
#define all(x)   (x).begin(),(x).end()
#define rep(i,n) for(int i=0;i<(n);i++)
#define repi(i,a,b) for(int i = (a); i < (b); i++)

using namespace std;

typedef    long long          ll;
typedef    unsigned long long ull;
typedef    vector<bool>       vb;
typedef    vector<int>        vi;
typedef    vector<vb>         vvb;
typedef    vector<vi>         vvi;
typedef    pair<int,int>      pii;

const int INF=1<<29;
const double EPS=1e-9;

const int dx[]={1,0,-1,0},dy[]={0,-1,0,1};
int n;
int main(){
	string str;
	map<string,int> data;
	while(cin>>str>>n){
		data[str]=n;
	}
	map<string,int>::iterator it =data.begin();
	while(it!=data.end()){
		cout <<(*it).first<<endl;
		cout <<(*it).second<<endl;
		it++;
	}
	return 0;
}

C++: #include<iostream>
#include<stdio.h>
#include<math.h>
#include    <iomanip>
#include    <map>
#include    <set>
#include    <deque>
#include    <vector>
#include    <stack>
using namespace std;
template <class X>
void prr(X test) {
    for(auto it:test){
        cout<<it;
    }
    cout<<endl;
}
int main(){
    map<string, set<int>> ma;
    string a;
    int aa;
    vector<int> b;
    while((cin>>a >>aa)&&(a!="0")){
        ma[a].insert(aa);
    }
    
    for(auto it:ma){
        cout<<it.first<<endl;
        for(auto itt:it.second){
            cout<<itt<<" ";
        }
        cout<<endl;
    }
    
    return 0;
}

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

int main() {
	int k=0,n,f;
	string s;
	map<string,int> mp;
	set<int> st[1001];
	map<string,int>::iterator it;
	set<int>::iterator si;  
	while(cin >> s >> n) {
		it=mp.find(s);
		if (it==mp.end()) {st[k].insert(n); mp.insert(map<string,int>::value_type(s,k++));}
		else st[(*it).second].insert(n);
	}
	for (it=mp.begin(); it!=mp.end(); it++) {
		cout << (*it).first << endl;
		f=0;
		for (si=st[(*it).second].begin();si!=st[(*it).second].end();si++) if (f==0) {f=1;cout << *si;} else cout << ' ' << *si;
		cout << endl;    
	}
    return 0;
	}

C++: #include <bits/stdc++.h>
#define _USE_MATH_DEFINES
using namespace std;
 
 
#define li			long long int
#define rep(i,to)	for(li i=0;i<((li)(to));i++)
#define repp(i,start,to)	for(li i=(li)(start);i<((li)(to));i++)
#define pb			push_back
#define sz(v)		((li)(v).size())
#define bgn(v)		((v).begin())
#define eend(v)		((v).end())
#define allof(v)	(v).begin(), (v).end()
#define dodp(v,n)		memset(v,(li)n,sizeof(v))
#define bit(n)		(1ll<<(li)(n))
#define mp(a,b)		make_pair(a,b)
#define rin	rep(i,n)
#define rjm	rep(j,m)


#define DBGP 1


#define idp if(DBGP)
#define F first
#define S second
#define p2(a,b)		idp cout<<a<<"\t"<<b<<endl
#define p3(a,b,c)		idp cout<<a<<"\t"<<b<<"\t"<<c<<endl
#define p4(a,b,c,d)		idp cout<<a<<"\t"<<b<<"\t"<<c<<"\t"<<d<<endl
#define p5(a,b,c,d,e)		idp cout<<a<<"\t"<<b<<"\t"<<c<<"\t"<<d<<"\t"<<e<<endl
#define p6(a,b,c,d,e,f)		idp cout<<a<<"\t"<<b<<"\t"<<c<<"\t"<<d<<"\t"<<e<<"\t"<<f<<endl
#define p7(a,b,c,d,e,f,g)		idp cout<<a<<"\t"<<b<<"\t"<<c<<"\t"<<d<<"\t"<<e<<"\t"<<f<<"\t"<<g<<endl
#define p8(a,b,c,d,e,f,g,h)		idp cout<<a<<"\t"<<b<<"\t"<<c<<"\t"<<d<<"\t"<<e<<"\t"<<f<<"\t"<<g<<"\t"<<h<<endl
#define p9(a,b,c,d,e,f,g,h,i)		idp cout<<a<<"\t"<<b<<"\t"<<c<<"\t"<<d<<"\t"<<e<<"\t"<<f<<"\t"<<g<<"\t"<<h<<"\t"<<i<<endl
#define p10(a,b,c,d,e,f,g,h,i,j)		idp cout<<a<<"\t"<<b<<"\t"<<c<<"\t"<<d<<"\t"<<e<<"\t"<<f<<"\t"<<g<<"\t"<<h<<"\t"<<i<<"\t"<<j<<endl
#define foreach(it,v)	for(__typeof((v).begin()) it=(v).begin(); it!=(v).end(); ++it)
#define p2p(x)		idp p2((x).F, (x).S)
#define dump(x,n)	idp{rep(i,n){cout<<x[i]<<" ";}puts("");}
#define dump2(x,n)	idp{rep(i,n){cout<<"["<<x[i].F<<" , "<<x[i].S<<"] ";}puts("");}
#define dumpi(x)	idp{foreach(it, x){cout<<(*it)<<" ";}puts("");}
#define dumpi2(x)	idp{foreach(it, x){cout<<"["<<(it)->F<<" , "<<(it)->S<<"] ";}puts("");}

#define read2d(a,w,h)	rep(i,h)rep(j,w)cin>>a[i][j]
#define dump2d(a,w,h)	rep(i,h){rep(j,w)cout<<a[i][j]<<" ";puts("");}


#define EPS 1e-10
#define ETOL 1e-8
#define MOD 1000000007
#define INF bit(60)

typedef pair<li, li> PI;

vector<pair<string, li>> book;

int main(int argc, char *argv[]){
	string s;
	li page;
	while(cin>>s){
		if(s=="hogehogehogehogehogehogehogehogehogehoge")break;
		cin>>page;
		book.pb({s, page});
	}
	sort(allof(book));

	string prev="";
	foreach(it, book){
		if(it->F!=prev){
			if(prev!="")cout<<endl;
			prev=it->F;
			cout<<prev<<endl;
		}
		cout<<it->S;
		vector<pair<string, li>>::iterator next=it;
		next++;
		if(next!=book.end() && next->F==it->F)cout<<" ";
	}
	puts("");


	return 0;
}

C++: /* -- 0105:Book Index -- */

#include	<iostream>
#include	<string>
#include	<vector>
#include	<utility>
#include	<algorithm>

using namespace std;

typedef pair< string, int > P;
typedef vector< P > Vec_S_I;

int main(void) {
	Vec_S_I Indexes;
	int buf_i, c;
	string buf_s;
	bool mstFirst = true, i_First = true;
	
	while(1) {
		cin >> buf_s >> buf_i;
		
		if( cin.eof() ) { break; }
		Indexes.push_back(P(buf_s, buf_i));
	}
	sort(Indexes.begin(), Indexes.end());
	Vec_S_I::iterator it = Indexes.begin();
	buf_s.erase();
	while(it != Indexes.end()) {
		if(buf_s != it->first) {
			if(!mstFirst) { cout << endl; }
			cout << it->first << endl;
			buf_s = it->first;
			i_First = true;
		}
		if(!i_First) { cout << ' '; }
		cout << it->second;
		i_First = false;
		mstFirst = false;
		it++;
	}
	cout << endl;
	return 0;
}

C++: #include <iostream>
#include <string>
#include <map>
#include <queue>
using namespace std;
 
int main() {
	map<string, priority_queue<int,vector<int>,greater<int>>> index;
	string word;
	int page;
 
	while(cin>>word>>page){
		index[word].push(page);
	}
 
	for(multimap<string,priority_queue<int,vector<int>,greater<int>>>::iterator it = index.begin(); it != index.end(); ++it){
		cout << it->first << endl;
 
		priority_queue<int,vector<int>,greater<int>> temp = it->second;
		while(1){
			cout << temp.top();
			temp.pop();
			if(!temp.empty()){cout<<" ";continue;}
			break;
		}
		cout << endl;
 	}
 
	return 0;
}

C++: #include<iostream>
#include<map>
#include<vector>
#include<string>
#include<algorithm>
using namespace std;
int main() {
	string a;
	map<string, vector<int>> d;
	while (cin >> a) {
		string b, h = "";
		int c, sum = 0;
		a += " ";
		for (int i = 0; i < a.length(); i++) {
			if (a[i] == ' ') {
				if (sum == 0)
					b = h;
				else
					c = atoi(h.c_str());
				sum++;
				h = "";
			}
			else
				h += a[i];
		}
		d[b].push_back(c);
	}
	map<string, vector<int>>::iterator t = d.begin();
	while (t != d.end()) {
		string k = (*t).first;
		sort(d[k].begin(), d[k].end());
		cout << k;
		for (int i = 0; i != d[k].size(); i++) {
			cout << " " << d[k][i];
		}
		cout << endl;
		t++;
	}
}