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 <algorithm>
#include <cmath>
#include <climits>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <fstream>
#include <iostream>
#include <list>
#include <map>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <vector>
#include <cassert>
#include <functional>

using namespace std;

#define LOG(...) printf(__VA_ARGS__)
//#define LOG(...)
#define FOR(i,a,b) for(int i=(int)(a);i<(int)(b);++i)
#define REP(i,n) for(int i=0;i<(int)(n);++i)
#define ALL(a) (a).begin(),(a).end()
#define RALL(a) (a).rbegin(),(a).rend()
#define EXIST(s,e) ((s).find(e)!=(s).end())
#define SORT(c) sort((c).begin(),(c).end())
#define RSORT(c) sort((c).rbegin(),(c).rend())
#define CLR(a) memset((a), 0 ,sizeof(a))

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

const int dx[] = { -1, 0, 1, 0 }; const int dy[] = { 0, 1, 0, -1 };
struct ind{
	string s;
	int p;
	bool operator<(const ind &right) const{
		return right.s != s ? right.s > s :right.p > p;
	}

};
int main() {
	vector<ind> book;
	string s;
	int n;
	while (cin >> s >> n)
		book.push_back({ s, n });
	SORT(book);
	s = "";
	REP(i, book.size()){
		if (book[i].s != s){
			if (i != 0)cout << endl;
			cout << book[i].s << endl;
			cout << book[i].p;
		}
		else{
			cout << ' ' << book[i].p;
		}
		s = book[i].s;
	}
	cout << endl;
}

C++: #include <cstdio>
#include <cstdlib>
#include <cmath>
#include <climits>
#include <cfloat>
#include <map>
#include <utility>
#include <set>
#include <iostream>
#include <memory>
#include <string>
#include <vector>
#include <algorithm>
#include <functional>
#include <sstream>
#include <complex>
#include <stack>
#include <queue>
#include <cstring>
using namespace std;
static const double EPS = 1e-5;
typedef long long ll;

map<string,vector<int> > idx;


main(){
	string name;
	int page;
	
	while(cin>>name>>page){
		idx[name].push_back(page);
	}
	
	for(map<string,vector<int> >::iterator p=idx.begin();p!=idx.end();++p){
		
		cout<<p->first<<endl;
		sort(p->second.begin(),p->second.end());
		int sf=0;
		for(vector<int>::iterator vp=p->second.begin();vp!=p->second.end();vp++){
			if(sf==1)cout<<" ";
			sf=1;
			cout<<*vp;
		}
		cout<<endl;
	}
}

C++: #include <iostream>
#include <cstdio>
#include <vector>
#include <list>
#include <algorithm>
#include <cmath>
#include <stack>
#include <map>
#include <numeric>
#include <sstream>
#include <queue>
#include <iomanip>
using namespace std;

#define REP(i,n) for(int (i)=0; (i)<(n); (i)++)
#define FOR(i,a,b) for(int (i)=(a); (i)<(b); (i)++)
#define PUSH(n,v) for(int i=0; i<(n); i++) {int j; cin >> j; v.push_back(j);}
#define ALL(v) v.begin(), v.end()
#define print(s) cout << (s) << endl
#define printV(v) for(int zxc=0;zxc<v.size()-1;zxc++){cout << v[zxc] << " ";} cout << v.back() << endl;

int main() {
    map<string, vector<int>> dic;
    string s;
    int page;
    while (cin >> s) {
        cin >> page;
        dic[s].push_back(page);
    }
    vector<pair<string, vector<int>>> dic_s;
    for (auto itr = dic.begin(); itr != dic.end(); itr++) {
        dic_s.push_back(make_pair(itr->first, itr->second));
    }
    sort(ALL(dic_s));
    REP(i, dic_s.size()) {
        vector<int> v = dic_s[i].second;
        cout << dic_s[i].first << endl;
        sort(ALL(v));
        printV(v);
    }
    return 0;
}

C++: #include <iostream>
#include <cstdio>
#include <vector>
#include <list>
#include <algorithm>
#include <cmath>
#include <stack>
#include <map>
#include <numeric>
#include <sstream>
#include <queue>
#include <iomanip>
using namespace std;

#define REP(i,n) for(int (i)=0; (i)<(n); (i)++)
#define FOR(i,a,b) for(int (i)=(a); (i)<(b); (i)++)
#define PUSH(n,v) for(int i=0; i<(n); i++) {int j; cin >> j; v.push_back(j);}
#define ALL(v) v.begin(), v.end()
#define print(s) cout << (s) << endl
#define printV(v) for(int zxc=0;zxc<v.size()-1;zxc++){cout << v[zxc] << " ";} cout << v.back() << endl;

int main() {
    map<string, vector<int>> dic;
    string s;
    int page;
    while (cin >> s) {
        cin >> page;
        dic[s].push_back(page);
    }
    vector<pair<string, vector<int>>> dic_s;
    for (auto itr = dic.begin(); itr != dic.end(); itr++) {
        dic_s.push_back(make_pair(itr->first, itr->second));
    }
    sort(ALL(dic_s));
    REP(i, dic_s.size()) {
        cout << dic_s[i].first << endl;
        printV(dic_s[i].second);
    }
    return 0;
}

C++: 
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <climits>
#include <cfloat>
#include <map>
#include <utility>
#include <set>
#include <iostream>
#include <fstream>
#include <memory>
#include <string>
#include <vector>
#include <algorithm>
#include <functional>
#include <sstream>
#include <complex>
#include <stack>
#include <queue>
#include <cstring>
#include <assert.h>

#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n)  FOR(i,0,n)
#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 ALL(s) (s).begin(),(s).end()
#define ITE(c) typeof((c).begin())

#define clr(a) memset((a),0,sizeof(a))
#define nclr(a) memset((a),-1,sizeof(a))
#define pb push_back
#define INRANGE(x,s,e) ((s)<=(x) && (x)<(e))
#define MP(a,b) make_pair((a),(b))

using namespace std;

int main(){
	bool flag=true;
	multimap<string,int> dat;
	pair<string,int>  temp;
	vector<string>    memo;
	vector<int>       page;
	
	while(cin>>temp.first>>temp.second){
		dat.insert(temp);
	}
	EACH(i,dat){
		if(!(*i).first.empty()){
			pair<typeof((dat).begin()),typeof((dat).begin())> tdat=dat.equal_range((*i).first);
			ITE(memo) find_it =find(memo.begin(),memo.end(),(*i).first);
			if( find_it == memo.end()){
				if(flag){
					cout<<(*i).first<<endl;
					flag=false;
				}else{
					cout<<"\n"<<(*i).first<<endl;
				}
				memo.push_back((*i).first);
				page.clear();
			    for (typeof((dat).begin()) it = tdat.first; it != tdat.second; ++it){
		        	page.push_back((*it).second);
		        }
		        sort(ALL(page));
		        int j=0;
		        EACH(i,page){
		        	j++;
		        	if(j<page.size()){
						cout<<(*i)<<" ";
					}else{
						cout<<(*i);
					}
		        }
		    }
		}
	}
	
	
	cout<<endl;
	
	return 0;
}

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

using namespace std;

int main(void){
  map<string, set<int> > m;
  map<string, set<int> >::iterator it;
  set<int>::iterator itr;
  string s;
  int n;

  while(cin>>s>>n){
    m[s].insert(n);
  }
  for(it=m.begin();it!=m.end();it++,cout<<endl){
    cout <<(*it).first<<endl;
    for(itr=(*it).second.begin();itr!=(*it).second.end();itr++,cout<<" "){
      cout<< *itr;
    }
  }
  
}