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>
#include <string>
#include <map>
#include <vector>
#include <algorithm>
using namespace std;

int main(){
	map<string, vector<int>> m;
	string str;
	int n;
	while(cin >> str >> n){
		m[str].push_back(n);
	}
	map<string, vector<int>>::iterator it;
	for(it = m.begin();it != m.end();it++){
		cout << it -> first << endl;
		sort(it -> second.begin(), it -> second.end());
		int i;
		for(i = 0;i < it -> second.size()-1;i++)
			cout << it -> second[i] << " ";
		cout << it -> second[i] << endl;
	}
	return 0;
}

C++: #include <iostream>
#include <string>
#define MAX_N 101
using namespace std;

typedef struct{
string name;
int page;
}index;
index a[MAX_N];
index temp;
int n;
int main(){
	n=0;
	while(cin >> a[n].name >> a[n].page){
		n++;
	}

	for(int i=0;i<n-1;i++){
		for(int j=0;j<n-1-i;j++){
			if(a[j].name>a[j+1].name){
				temp=a[j];
				a[j]=a[j+1];
				a[j+1]=temp;
			}else if(a[j].name==a[j+1].name&&a[j].page>a[j+1].page){
				temp=a[j];
				a[j]=a[j+1];
				a[j+1]=temp;
			}
		}
	}
	cout << a[0].name << endl;
	cout << a[0].page;
	for(int i=1;i<n;i++){
		if(a[i-1].name!=a[i].name){
			cout <<endl << a[i].name << endl;
			cout <<a[i].page;
		}else if(a[i-1].name==a[i].name){
			cout << " "<<a[i].page;
		}
	}
	return 0;
}

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};
typedef pair<string,int> P;
int n;
int main(){
	string str;
	map<string,std::vector<int> > data;
	while(cin>>str>>n){
		data[str].push_back(n);
	}
	map<string,vector<int> >::iterator it =data.begin();
	for(;it!=data.end();it++){
		cout <<(*it).first<<endl;
		vector<int>v =(*it).second;
		sort(v.begin(),v.end());
		for(int i = 0;i <v.size();i++){
			if(i)cout <<" ";
			cout <<v[i];
		}
		cout <<endl;
	}
	return 0;
}

C++: #include <iostream>
#include <algorithm>
#include <vector>
#include <map>
using namespace std;

int main() {
  string str;
  int t;
  map<string, vector<int>, less<string> > mp;
  
  for(;cin>>str>>t;mp[str].push_back(t));
  
  for(map<string, vector<int> >::iterator it=mp.begin();it!=mp.end();it++) {
      cout << (*it).first << endl;
      sort((*it).second.begin(), (*it).second.end());
      for(int i=0;i<(*it).second.size()-1;i++) {
	cout << (*it).second[i] << " ";
      }
      cout << (*it).second[(*it).second.size()-1] << endl;
    }
	
  return 0;
}

C++: #include <utility>
#include <vector>
#include <math.h>
#include <algorithm>
#include <string>
#include <iostream>
using namespace std;

vector<pair<string, int>> v;
vector<pair<string, vector<int>>> l;
vector<string> w;

bool fa(int index) {
	for (int i = 0; i < l.size(); i++) {
		if (l[i].first == v[index].first) {
			l[i].second.push_back(v[index].second);
			return true;
		}
	}
	l.push_back({ v[index].first,vector<int>(1,v[index].second) });
	w.push_back(v[index].first);
	return false;
}

int search(int index) {
	for (int i = 0; i < l.size(); i++) {
		if (w[index] == l[i].first)
			return i;
	}
	return -1;
}

int main(){
	string s;
	int p;
	while (cin >> s >> p && p != 0) {
		v.push_back(pair<string, int>({ s,p }));
	}
	for (int i = 0; i < v.size(); i++) {
		fa(i);
	}
	sort(w.begin(), w.end());
	for (int i = 0; i < l.size(); i++) {
		sort(l[i].second.begin(), l[i].second.end());
	}
	for (int i = 0; i < w.size(); i++) {
		int index = search(i);
		cout << w[i] << endl;
		cout << l[index].second[0];
		for (int j = 1; j < l[index].second.size(); j++) {
			cout << " " << l[index].second[j];
		}
		cout << endl;
	}

	return 0;
}

C++: #include <cstdio>
#include <string>
#include <utility>
#include <iostream>
using namespace std;

typedef pair<string, int> P;

P words[110];

int main() {
  int i=0;

  string name; int page;
  while(cin >> name >> page) {
    words[i].first = name;
    words[i].second = page;

    i++;
    // cout << name << page << endl;
  }

  int n = i;

  
  for (int j=0; j<n-1; j++) {
    for (int k=0; k<n-1-j; k++) {
      if (words[k].first > words[k+1].first ||
	  (words[k].first == words[k+1].first &&
	   words[k].second > words[k+1].second)) {
	P temp = words[k];
	words[k] = words[k+1];
	words[k+1] = temp;
      }
    }
  }


  for (int j=0; j<n; j++) {
    cout << words[j].first << " " << words[j].second << endl;
  }
  
  /*
  bool cont = false;
  for (int j=0; j<n; j++) {
    if (words[j].first == words[j+1].first) {
      if (!cont) {
	cout << words[j].first << endl;
	cont = true;
      }
    }
  }
  */
  
  
}

C++: #include <bits/stdc++.h>
using namespace std;pair<string,int> a[1];int main(){int t=0,g,i;while(cin>>a[t].first>>a[t].second)t++;sort(a,a+t);string f,b=a[0].first;cout<<b<<endl<<a[0].second;for(i=1;i<t;i++){bool n=0;f=a[i].first,g=a[i].second;if(f==b)n=1;if(n)cout<<" "<<g;else cout<<endl<<f<<endl<<g;b=f;}cout<<endl;return 0;}

C++: #include<iostream>
#include<string>
#include<vector>
#include<map>
#include<algorithm>
using namespace std;
int main(){
  map<string, vector<int> > word;
  string s;
  int n;
  while(cin >>s>>n){
    word[s].push_back(n);
  }
  for(map<string, vector<int> >::iterator i=word.begin(); i!=word.end(); i++){
    sort(i->second.begin(),i->second.end());
    cout <<i->first<<endl<<i->second[0];
    for(int j=1; j<i->second.size(); j++){
      cout <<" "<<i->second[j];
    }
    cout <<endl;
  }
  return 0;
}

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

using namespace std;

int main()
{
	string key;
	int page;
	map< string, set<int> > dic;

	while (cin >> key >> page)
	{
		dic[key].insert(page);
	}

	for (map< string, set<int> >::iterator it_dic = dic.begin(); it_dic != dic.end(); ++it_dic)
	{
		cout << it_dic->first << endl;
		for (set<int>::iterator it = it_dic->second.begin(); it != it_dic->second.end(); ++it)
		{
			if (it != it_dic->second.begin())
			{
				cout << " ";
			}
			cout << *it;
		}
		cout << endl;
	}

	return 0;
}