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++: #define _CRT_SECURE_NO_WARNINGS
#define _USE_MATH_DEFINES

#include <iostream>
#include <algorithm>
#include <functional>
#include <string>
#include <queue>
#include <cmath>
#include <stack>
#include <numeric>
#include <ctime>
#include <algorithm>
#include <set>
#include <map>
#include <stdio.h>

using namespace std;
typedef long long int lint;

int main()
{
	map<string, vector<int> > page;
	set<string> word;

	string str;
	int p;
	while(cin >> str >> p){
		word.insert(str);
		page[str].push_back(p);
	}
	
	set<string>::iterator it = word.begin();
	while(it != word.end()){
		cout << *it;
		for(int i = 0; i < page[*it].size(); i++){
			if(i == 0) cout << endl;
			else cout << " ";
			cout << page[*it][i];
		}
		cout << endl;
		it++;
	}

	return 0;
}

C++: #include<iostream>
#include<vector>
#include<string>

using namespace std;

char returnc(char c){
  if('a'<=c && c<='z'){
    if(c=='z')return 'a';
    return ++c;
  }
  return c;
}
int main(void){
  string s;
  int n;
  vector<string> ss;
  vector<vector<int> > nn;
  while(cin>>s>>n){
    if(ss.empty()){
      ss.push_back(s);
      nn.push_back(vector<int>(1,n));
    }
    bool ok = true;
    for(int i = 0 ; i < ss.size() ; i ++){
      if(ss[i] == s){
	nn[i].push_back(n);
	ok = false;
      }
    }
    if(ok){
      ss.push_back(s);
      nn.push_back(vector<int>(1,n));
      
    }
  }
  for(int i = ss.size() - 1 ; i >= 0 ; i --){
    for(int j = 0 ; j < i ; j ++){
      if(ss[i] < ss[j]){
	string w = ss[i];
	ss[i] = ss[j];
	ss[j] = w;
	vector<int> ws = nn[i];
	nn[i] = nn[j];
	nn[j] = ws;
      }
    }
  }
  
  for(int i = 0 ; i < ss.size() ; i ++){
    cout<<ss[i]<<endl;
    for(int j = 0 ; j < nn[i].size()-1 ; j ++){
      cout<<nn[i][j]<<" ";
    }
    cout<<nn[i][nn[i].size() - 1 ]<<endl;
  }
}

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

using namespace std;

int main(){
	int n;
	string str;	
	map<string, set<int> > m;

	while(cin >> str >> n){
		m[str].insert(n);
	}
	for(auto it = m.begin(); it != m.end(); it++){
		cout << it->first << endl;
		int i = 0;
		for(auto its =  it->second.begin(); its != it->second.end(); its++){
			if(i != it->second.size() - 1) cout << *its << " ";
			else cout << *its;
			i++;
		}
		cout << endl;
	}
}

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

class set{
public:
  set(string w){word = w;}
  
  string word;
  vector<int> page;
};


int find(vector<set> a , string key){
  for(int i=0; i<a.size(); i++)if(a[i].word == key)return i;
  return -1;
}
bool comp(const set& a, const set& b){
  return a.word < b.word;
}

int main(){
  
  vector<set> ls;
  string w;
  int p;

  
  while(cin>>w>>p){
    int indx;
    if( (indx=find(ls,w)) == -1){
      set tmp(w);tmp.page.push_back(p);ls.push_back(tmp);
    }
    else{
      ls[indx].page.push_back(p);
    }
  }

  sort(ls.begin() , ls.end() , comp);

  for(int i=0; i<ls.size(); i++){
    sort(ls[i].page.begin() , ls[i].page.end());

    cout << ls[i].word << endl << ls[i].page[0];
    for(int j=1; j<ls[i].page.size(); j++)cout << ' ' << ls[i].page[j];
    cout << endl;
  }
  
  return 0;
}

C++: #define _USE_MATH_DEFINES
#include <iostream>
#include <sstream>
#include <cmath>
#include <algorithm>
#include <queue>
#include <stack>
#include <limits>
#include <map>
#include <string>
#include <cstring>
#include <set>

using namespace std;

typedef long long ll;
typedef pair<int,int> P;

int main(){

	string str;
	int idx;
	char buf[64];
	map<string,set<int> > pages;
	while(~scanf("%s %d",buf,&idx)){
		pages[buf].insert(idx);
	}

	for(map<string,set<int> >::iterator it = pages.begin(); it != pages.end(); it++){
		printf("%s\n",it->first.c_str());

		int i=0;
		for(set<int>::iterator it2 = it->second.begin(); it2 != it->second.end(); it2++){

			printf("%d%s",*it2,i==it->second.size()-1 ? "\n" : " ");
			i++;
		}
	}
}

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

class cob{
public:
	string str;
	vector<int> num;
	cob(string str):str(str){}

	bool operator < (const cob &ano){
		return str < ano.str;
	}

	void S()
	{
		sort(num.begin(), num.end());
	}
};



int main(void)
{
	string instr;
	int num;
	vector<cob> index;

	bool f = false;
	while(cin >> instr >> num, !cin.eof()){
		for(int i = 0; i < index.size(); i++){
			if(index[i].str == instr){			
				index[i].num.push_back(num);
				f = true;
				break;
			}
		}
		if(!f){
			index.push_back(cob(instr));
			index.back().num.push_back(num);
		}
	}

	sort(index.begin(), index.end() );
	for(int i = 0; i < index.size(); i++){
		index[i].S();

		cout << index[i].str << endl;
		cout << index[i].num[0];
		for(int j = 1; j < index[i].num.size(); j++)
			cout << ' ' << index[i].num[j];
		cout << endl;
	}

	return 0;
}

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(odwd != "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++: #include<iostream>
#include<map>
#include<string>
#include<vector>
#include<algorithm>
using namespace std;

int main(){
  int value;
  string str;
  int flag;
  map<string,vector<int>> book;

  while(cin>>str>>value){
    book[str].push_back(value);
  }
  for(map<string,vector<int>>::iterator it=book.begin();it!=book.end();++it){
    cout<<it->first<<endl;
    sort(it->second.begin(),it->second.end());
    flag=0;
    for(auto i:it->second){
      if(flag) cout<<" ";
      flag=1;
      cout<<i;
	}
    cout<<endl;
  }
}

C++: #include<bits/stdc++.h>
#define rep(i,n)for(int i=0;i<n;i++)
using namespace std;
typedef long long ll;
typedef pair<string, int>P;

int main() {
	vector<P>v;
	string s; int n;
	rep(i, 8) {
		cin >> s >> n;
		v.push_back(P(s, n));
	}
	sort(v.begin(), v.end(), [](P a, P b) {return a.second < b.second; });
	stable_sort(v.begin(), v.end());
	rep(i, v.size()) {
		if (i&&v[i - 1].first == v[i].first) {
			cout << ' ' << v[i].second;
			continue;
		}
		if (i)cout << endl;
		cout << v[i].first << endl << v[i].second;
	}
	cout << endl;
}