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<iostream>
#pragma warning(disable:4786)
#include<map>
#include<vector>
#include<string>
#include<algorithm>
using namespace std;
int main() {
	string a;
	map<string, vector<int>> d;
	for(int l=0;l<8;l++){
		getline(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 << endl;
		vector<int>::iterator ite = d[k].begin();
		for(ite=d[k].begin();ite!=d[k].end();++ite) {
			if (ite == d[k].begin())
				cout << *ite;
			else
				cout << " " << *ite;
		}
		cout << "\n";
		t++;
	}
}

C++: #include <bits/stdc++.h>
using namespace std;
int main(){
  map<string,vector<int> >A;
  string s;
  int n;
  while(cin>>s>>n){
    A[s].push_back(n);
  }
  map<string,vector<int> >::iterator t=A.begin();
  while(t!=A.end()){
    cout<<t->first<<endl;
    sort(t->second.begin(),t->second.end());
    for(int i=0;i<t->second.size()++){
      if(i)cout<<' '<<t->second[i];
      else cout<<t->second[i];
    }
    cout<<endl;
  }
}

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;
  	int counter = 0;
  	for(set<int>::iterator set_it = it->second.begin() ; set_it != it->second.end() ; set_it++)
  	{
  		if(counter!=0)cout <<" ";
  		cout << *set_it;
  	}
  	cout << endl;
  }

  return 0;
}

C++: #include<iostream>
#include<map>
#include<string>
#include<algorithm>
#include<sstream>

using namespace std;

string itos(int);


int main(){


  string s[1000];
  int n[1000];

  int sumin = 0;


  for(int i = 0; cin >> s[i] >> n[i]; i++){
    sumin++;
  }

  for(int i = 0; i < sumin-1; i++){
    for(int j = i; j < sumin; j++){
      if(n[i] > n[j]){
        int stock = n[i];
	n[i] = n[j];
	n[j] = stock;
	string stack = s[i];
	s[i] = s[j];
	s[j] = stack;
      }
    }
  }


  string num[1000];


  map<string, string> M;


  for(int i = 0; i < sumin; i++){
    for(int j = 0; j < i; j++){
      if(s[j] == s[i]){
	M[s[i]] += " ";
	break;
      }
    }

    M[s[i]] += itos(n[i]);

  }

  sort(s, s+sumin);


  for(int i = 0; i < sumin-1; i++){
    cout << s[i] << endl << M[s[i]] << endl;
  }


  
  return 0;
}

string itos(int x){
  ostringstream s;
  s << x;
  return s.str();
}

C++: #include <iostream>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <map>
#include <set>
#include <queue>
#include <algorithm>
#include <cstring>
#include <sstream>
#include <vector>
#include <string>
#include <iomanip>
#include <bitset>
using namespace std;
#define INF	100000000
#define MOD 1000000007
#define pb push_back
#define mp make_pair
#define fi first
#define sec second
#define lb lower_bound
#define ub upper_bound
#define SS stringstream
#define rep(i,n) for(int i = 0; i < n; i++)
#define sz(x) ((int)(x).size())
#define SORT(x) sort((x).begin(), (x).end())
#define RSORT(x) sort((x).begin(), (x).end(), greater<int>() )
#define clr(a,b) memset((a),(b),sizeof(a))
typedef long long int ll;
typedef pair<string, int> P;
typedef vector<int> Vi;
typedef vector<ll> Vll;
typedef vector<P> Vp;
typedef priority_queue<P, vector<P>, greater<P> > PQ;

string word;
int page;
Vp book;

int main(){
	ios::sync_with_stdio(false);
	cin.tie(0);
	while(cin >> word >> page) book.pb(P(word,page));
	SORT(book);
	cout << book[0].fi << endl << book[0].sec;
	for(int i = 1; i < book.size(); i++){
		if(book[i-1].fi == book[i].fi) cout << " " << book[i].sec;
		else cout << endl << book[i].fi << endl << book[i].sec;
	}
	cout << endl;
}

C++: #include <iostream>
#include <stack>
#include <algorithm>
#include <cstdio>
#include <sstream>
#include <vector>
#include <string>
#include <cmath>

#define rep(x,to) for(int x=0;x<to;x++)
#define rep2(x,from,to) for(int x=from;x<to;x++)

using namespace std;

typedef pair<string,int> mypair;

struct pair_sort {
  bool operator()(const  mypair& x, const mypair& y) const {
	return x.first < y.first || x.first ==  y.first && x.second < y.second;
  }
};


int main(void){

int pg;
string gk;
vector<mypair> sss;
	while(cin >> gk >> pg ){
		if( cin.eof() ) break;
		sss.push_back(mypair(gk,pg));
	}
	sort(sss.begin(),sss.end()); //,pair_sort());
	string odwd="zzz999";
	rep(i, sss.size()){
		if(sss[i].first != odwd){
			if(sss[i].first != "zzz999") cout << endl;
			cout << sss[i].first << endl;
			cout << sss[i].second;
		}else{
			cout << " " << sss[i].second;
		}
		odwd = sss[i].first;
	}
	cout << endl;
	
	return 0;
}

C++: /*
Accepted 7/19
*/
#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>


using namespace std;


#define typeof(X) std::identity<decltype(X)>::type
#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 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))

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);
	}
	for(auto i:dat){
		if(!(i.first.empty())){
			pair<multimap<string,int>::iterator,multimap<string,int>::iterator> tdat=dat.equal_range(i.first);
			auto find_it =find(begin(memo),end(memo),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 (auto it = tdat.first; it != tdat.second; ++it){
		        	page.push_back((*it).second);
		        }
		        sort(begin(page),end(page));
		        int j=0;
		        for(auto i:page){
		        	j++;
		        	if(j<page.size()){
						cout<<i<<" ";
					}else{
						cout<<i;
					}
		        }
		    }
		}
	}
	cout<<endl;
	
	return 0;
}