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 <bits/stdc++.h>
using namespace std;
int main(void){
    pair<string, int> t[1010];
    int i;
    for(i=0; cin >> t[i].first >> t[i].second; i++);
    sort(t, t+i);
    cout << t[0].first << "\n";
    cout << t[1].second << "\n";
    for(int j=1; j<i; j++){
        if(t[j-1].first==t[j].first){
            cout << " " << t[j].second;
        }
        else{
            cout << "\n";
            cout << t[j].first << "\n";
            cout << t[j].second;
        }
    }
    cout << "\n";
}

C++: #include<stdio.h>
#include<string.h>
typedef struct{
  char name[35];
  int page[1001];
  int flg;
}P;

main(){
  int i=0,j,k,pa,flg2,cnt=0,l,tmp;
  char str[35];
  P index[1000];
  P temp;
  while(scanf("%s %d",str,&pa)!=EOF){
    flg2=0;
    for(j=0;j<cnt;j++){
      if(strcmp(str,index[j].name)==0){
	index[j].page[pa]=1;
	flg2++;
	index[j].flg++;
	break;
      }
    }
    if(flg2==0){
      strcpy(index[cnt].name,str);
      index[cnt].page[pa]=1;
      cnt++;
      index[cnt].flg=1;
    }
  }
  for(i=0;i<cnt-1;i++){
    for(j=cnt-1;j>i;j--){
      if(strcmp(index[j].name,index[j-1].name)<0){
	temp=index[j];
	index[j]=index[j-1];
	index[j-1]=temp;
      }
    }
  }

  for(i=0;i<cnt;i++){
    printf("%s\n",index[i].name);
    for(j=1,tmp=0;j<=1000;j++){
      if(index[i].page[j]==1){
	if(tmp!=0)printf(" ");
	printf("%d",j);
	tmp=1;
      }
    }
    printf("\n");
  }
    
  return 0;
}

C++: #include <bits/stdc++.h>

using namespace std;
using ll = long long;
using pii = pair<int, int>;

int main() {
  cin.tie(0);
  ios_base::sync_with_stdio(false);
  cout << fixed << setprecision(10);
  
  string s;
  int n;
  map<string, vector<int>> mp;
  while (cin >> s >> n) {
    mp[s].emplace_back(n);
  }
  for (auto i : mp) {
    cout << i.first << endl;
    auto v = i.second;
    int vz = v.size();
    sort(v.begin(), v.end());
    for (int j = 0; j < vz; j++) {
      cout << v[j] << " \n"[j + 1 == vz];
    }
  }

  return 0;
}

C++: #include "bits/stdc++.h"

#define REP(i,num) for(int i=0;i<(num);++i)
#define LOOP(i) while(i--)
#define ALL(c) c.begin(),c.end()
#define PRINTALL(c) for(auto pitr=c.begin();pitr!=c.end();++pitr){cout<<*pitr;if(next(pitr,1)!=c.end())cout<<' ';}cout<<endl;
#define PAIRCOMP(c,comp) [](const pair<ll,ll>& lhs,const pair<ll,ll>& rhs){return lhs.c comp rhs.c;}

using namespace std;
using ll = long long;

constexpr ll atcoder_mod = 1e9+7;

template<typename T=int>
T in(){T x; cin >> x; return (x);}
template<typename T=int,typename C=vector<T>>
C vecin(int N){C x(N);REP(i,N){x[i]=in<T>();}return move(x);}

void vout(){cout << endl;}
template<typename Head,typename... Tail>
void vout(Head&& h,Tail&&... t){cout << ' ' << h;vout(forward<Tail>(t)...);}
void out(){cout << endl;}
template<typename Head,typename... Tail>
void out(Head&& h,Tail&&... t){cout << h;vout(forward<Tail>(t)...);}

int main(){
	cin.tie(0);
	ios::sync_with_stdio(false);
	cout<<fixed<<setprecision(10);

	string S;
	multimap<string,set<int>> M;
	while(cin>>S){
		int V=in();
		auto itr=M.find(S);
		if(itr!=M.end()){
			itr->second.emplace(V);
		}
		else{
			M.emplace(S,set<int>{V});
		}
	}
	
	for(auto& x:M){
		out(x.first);
		PRINTALL(x.second);
	}
	return 0;
}

C++: #include <iostream>
#include <string>
#include <algorithm>
#include <vector>
#include <set>
#include <stack>
#include <queue>
#include <cstdio>
#include <cmath>
#include <cstring>
#include <cstdlib>
#include <map>
using namespace std;
typedef long long LL;
static const double EPS = 1e-9;

#define FOR(i,k,n) for (int i=(k); i<(int)(n); ++i)
#define REP(i,n) FOR(i,0,n)

int main(void){
  map<string, set<int> > sakuin;
  string word;
  int page;
  map<string, set<int> >::iterator it;
  set<int>::iterator it2;
  while(cin>>word){
    cin>>page;
    if((it=sakuin.find(word))!=sakuin.end()){
      (*it).second.insert(page);
    }else{
      set<int> tmp;
      tmp.insert(page);
      sakuin[word]=tmp;
    }
  }
  for(it=sakuin.begin();it!=sakuin.end();it++){
    cout<<(*it).first<<endl;
    for(it2=(*it).second.begin();it2!=(*it).second.end();it2++){
      if(it2!=(*it).second.begin()){
        printf(" ");
      }
      printf("%d",(*it2));
    }
    cout<<endl;
  }
  return 0;
}

C++: #include<iostream>
#include<algorithm>

using namespace std;

struct Data{
  string name;
  int num;
  bool operator < ( const Data &data) const {
    return (name < data.name);
  }
};

int main(){
  
  Data a[100000];
  int n=0;
  string str;
  int id;
  while( cin>>str>>id ){
    a[n]= (Data){ str, id };
    n++;
  }
  sort(a,a+n);

  string key="";
  
  for(int i=0;i<n;i++){
    if(key!=a[i].name){
      key=a[i].name;
      if(i>0){
        cout<<endl;
      }
      cout<<key<<endl;
      cout<<a[i].num;
    }else{
      cout<<' '<<a[i].num;
    }
  }

  cout<<endl;
  
  return 0;
}

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

using namespace std;

int main(){
  map<string,set<int> >idx;
  string s;
  int i;
  while(cin>>s>>i){
    idx[s].insert(i);
  }
  for(map<string,set<int> >::iterator it=idx.begin();it!=idx.end();it++){
    cout<<it->first<<endl;
    bool out=false;
    for(set<int>::iterator itt=it->second.begin();itt!=it->second.end();itt++){
      if(out){
	cout<<' ';
      }
      out=true;
      cout<<*itt;
    }
    cout<<endl;
  }
  return 0;
}

C++: #include <iostream>
#include <list>
#include <vector>
#include <map>
#include <string>
#include <algorithm>

using namespace std;

int main(){
	string strInput;
	map< string,vector<int> > index;
	int intInput = 0;
	while(cin >> strInput >> intInput){
		index[strInput].push_back(intInput);
	}
	
	for(map< string,vector<int> >::iterator it = index.begin(); it != index.end() ; it++){
		sort( index[(*it).first].begin(),index[(*it).first].end() );
		cout << (*it).first << endl;
		for(int i = 0; i < index[(*it).first].size(); i++){
			if(i == index[(*it).first].size() - 1){
				cout <<  index[(*it).first][i];
			}
			cout <<  index[(*it).first][i] << ' ';
		}
		cout << endl;
	}

	return 0;
}

C++: #include <bits/stdc++.h>

using namespace std;

typedef unsigned long long ull;
#define loop(i,a,b) for(int i=(a);i<ull(b);++i)
#define rep(i,n) loop(i,0,n)
#define all(a) (a).begin(), (a).end()

const double eps = 1e-10;
const double pi  = acos(-1.0);
const double inf = (int)1e8;

bool pairCompare(const std::pair<string, priority_queue<int, vector<int>, greater<int> > >& firstElem, const std::pair<string, priority_queue<int, vector<int>, greater<int> > >& secondElem) {
  return firstElem.first < secondElem.first;
}


int main(){
	vector<pair<string, priority_queue<int, vector<int>, greater<int> > > > v;
	string s;int n;
	while(cin >> s >> n){
		bool b = false;
		for(int i=0; i < v.size(); i++) if(v[i].first == s){b = true; v[i].second.push(n); break;}
		if(!b){
			priority_queue<int, vector<int>, greater<int> > q;
			q.push(n);
			v.push_back(make_pair(s, q));
		}
	}
	sort(v.begin(), v.end(), pairCompare);
	for(int i=0; i< v.size(); i++){
		cout << v[i].first << endl;
		bool b = false;
		while(!v[i].second.empty()){
			cout << (b ? " " : "") << v[i].second.top(); b = true;
			v[i].second.pop();
		}
		cout << endl;
	}
}