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(){
	string s;
	int p;
	multimap<string,int> mp;
	while(cin >> s >> p){
		mp.insert(multimap<string,int>::value_type(s , p));
	}
	for(multimap<string,int>::iterator it=mp.begin();it!=mp.end();){
		vector<int> v;
		string tmp=(*(it)).first;
		cout << tmp << endl;
		do {
			v.push_back((*(it)).second);
			++it;
		} while(it!=mp.upper_bound(tmp));
			sort(v.begin() , v.end());
			for(int i=0;i<v.size()-1;++i){
				cout << v[i] << " ";
			}
			cout << v[v.size()-1] << endl;
	}
	return 0;
}

C++: //============================================================================
// Name        : aoj0105.cpp
// Author      : afterCmidday
// Version     :
// Copyright   : Your copyright notice
// Description : Hello World in C++, Ansi-style
//============================================================================

#include <cstdio>
#include <cstring>
#include <cstdlib>
using namespace std;

typedef struct{
	char word[31];
	int page;
}Quate;

int compare(const void *a,const void *b){
	Quate qa, qb;
	qa = *(Quate *)a;
	qb = *(Quate *)b;
	if(strcmp(qa.word,qb.word) != 0){
		return strcmp(qa.word,qb.word);
	}else{
		return qa.page - qb.page;
	}
}


int main() {
	char tmp[31] = "";
	Quate q[1000];
	int n = 0, i;
	while(scanf("%s%d%*c",q[n].word,&q[n].page) != EOF){
		n++;
	}
	qsort(q,n,sizeof(q[0]),compare);
	for(i = 0;i < n;i++){
		if(strcmp(tmp,q[i].word) == 0){
			printf(" %d",q[i].page);
		}else{
			if(strcmp(tmp,"") != 0){
				printf("\n");
			}
			printf("%s\n%d",q[i].word,q[i].page);
		}
		strcpy(tmp,q[i].word);
	}

	return 0;
}

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

typedef pair<string,int> P;

int main(){
  string str;
  int page,cnt=0;
  vector<P> v;

  while(cin >> str >> page){
    v.push_back(P(str,page));
    cnt++;
  }

  sort(v.begin(),v.end());
  for(int i = 0 ; i < cnt; i++){
    if(i==0){
      cout << v[i].first << endl;
      cout << v[i].second;
      continue;
    }

    if(v[i].first == v[i-1].first && v[i].second!=v[i-1].second){
      cout << ' ' << v[i].second;
      continue;
    }
   
    puts("");
    puts("");
    cout << v[i].first << endl;
    cout << v[i].second;
    }

  return 0;
}

C++: #include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define rep(i,n) for( int i = 0; i < n; i++ )
#define dump(x)  cerr << #x << " = " << (x) << endl;
#define INF 2000000000
#define mod 1000000007
#define INF2 1000000000000000000

vector<pair<string,int>> str(100000);
int main(void)
{
    cin.tie(0);
    ios::sync_with_stdio(false);
    int count = 0;
    int c_n = 0;
    while (cin >> str[count].first) {
        cin >> str[count].second;
        count++;
    }
    sort(str.begin(), str.begin() + count);
    cout << str[0].first << endl;
    cout << str[0].second;
    for (int i = 1; i < count; i++) {
        if (str[i].first != str[i-1].first) {
            cout << endl << str[i].first << endl;
            cout << str[i].second;           
        } else {
            cout << " " << str[i].second;
        }
    }
    cout << endl;
    return 0;
}

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

class WP {
public:
	std::string word;
	int page;
public:
	WP() {
		this->word = "";
		this->page = 0;
	}
	WP( std::string word, int page ) {
		this->word = word;
		this->page = page;
	}
	bool operator>=(const WP& rhs) {
		if (this->word.compare(rhs.word) > 0) return true;
		else if (this->word.compare(rhs.word) < 0) return false;
		else {
			return (this->page >= rhs.page);
		}
	}
	bool operator>(const WP& rhs) {
		if (this->word.compare(rhs.word) > 0) return true;
		else if (this->word.compare(rhs.word) < 0) return false;
		else {
			return (this->page > rhs.page);
		}
	}
	bool operator<=(const WP& rhs) {
		if (this->word.compare(rhs.word) < 0) return true;
		else if (this->word.compare(rhs.word) > 0) return false;
		else {
			return (this->page <= rhs.page);
		}
	}
	bool operator<(const WP& rhs) {
		if (this->word.compare(rhs.word) < 0) return true;
		else if (this->word.compare(rhs.word) > 0) return false;
		else {
			return (this->page < rhs.page);
		}
	}
	bool operator==(const WP& rhs) {
		if (this->word.compare(rhs.word) != 0) return false;
		else {
			return (this->page == rhs.page);
		}
	}
	bool operator!=(const WP& rhs) {
		if (this->word.compare(rhs.word) != 0) return true;
		else {
			return (this->page != rhs.page);
		}
	}
	~WP() {}
};

int main()
{
	WP words_list[100];
	std::string word;
	int page;
	int input_size = 0;
	while (std::cin >> word >> page) {
		words_list[input_size] = WP(word, page);
		input_size++;
	}
	
	std::sort(words_list, words_list + input_size);
	
	for (int i=0; i<input_size; i++) {
		std::cout << words_list[i].word << std::endl;
		std::cout << words_list[i].page;
		while (words_list[i].word == words_list[i+1].word) {
			i++;
			std::cout << " " << words_list[i].page;
		}
		std::cout << std::endl;
	}

	return 0;
}

C++: #include<bits/stdc++.h>
using namespace std;
map<string,priority_queue<int,vector<int>,greater<int> > > Map;
signed main(void){
	ios::sync_with_stdio(false);
	string s;
	int page;
	while(cin>>s>>page)
		Map[s].push(page);
	for(map<string,priority_queue<int,vector<int>,greater<int> > >::iterator it=Map.begin();it!=Map.end();++it){
		if(it!=Map.begin())	cout<<endl;
		cout<<it->first<<endl;
		while(!it->second.empty()){
			cout<<it->second.top()<<" ";
			it->second.pop();
		}
	}
}

C++: # include <iostream>
# include <algorithm>
# include <vector>
# include <string>
# include <set>
# include <map>
# include <cmath>
# include <iomanip>
# include <functional>
# include <utility>
# include <stack>
# include <queue>
# include <list>
constexpr int MOD = 1000000000 + 7;
constexpr int INF = 2000000000;
using namespace std;

int main() {
	map<string, vector<int>> mp;
	string s;
	int a;
	while (cin >> s >> a) {
		mp[s].emplace_back(a);
	}
	sort(mp[s].begin(), mp[s].end());
	for (auto itr = mp.begin(); itr != mp.end(); ++itr) {
		cout << itr->first<< endl;
		sort(mp[itr->first].begin(), mp[itr->first].end());
		for (int i = 0; i < mp[itr->first].size(); i++) {
			cout << mp[itr->first][i];
			if (i != mp[itr->first].size() - 1)cout << " ";
			else cout << endl;
		}
	}
}