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 <map>
#include <vector>
#include <algorithm>

int main(){
  std::string s;
  int p;
  std::map<std::string,std::vector<int> > m;
  while(std::cin>>s>>p,!std::cin.eof()){
    m[s].push_back(p);
  }
  std::map<std::string,std::vector<int> >::iterator m_it = m.begin();
  while(m_it!=m.end()){
    std::cout<<(*m_it).first<<std::endl;
    std::sort((*m_it).second.begin(),(*m_it).second.end());
    std::vector<int>::iterator v_it = (*m_it).second.begin();
    while(v_it!=(*m_it).second.end()){
      std::cout<<*v_it;
      v_it++;
      (v_it==(*m_it).second.end())?std::cout<<std::endl:std::cout<<" ";
    }
    m_it++;
  }
  return 0;
}
/*
Sample Input
style 12
even 25
introduction 3
easy 9
style 7
document 13
style 21
even 18
Output for the Sample Input
document
13
easy
9
even
18 25
introduction
3
style
7 12 21
*/

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

#define SWAP(A, B) {int tmp = (B); (B) = (A); (A) = (tmp);}

int main() {
	char word[100][31];
	int pagenum[100];
	int sortnum[100];
	int count;

	for (int i = 0; i < 100; i++)
		sortnum[i] = i;

	for (count = 0; cin >> word[count] >> pagenum[count] != NULL; count++);

	for (int i = 0; i < count; i++) {
		for (int j = 0; j < count - i - 1; j++) {
			if (strcmp(word[sortnum[j]], word[sortnum[j+1]]) > 0)
				SWAP(sortnum[j], sortnum[j+1]);
		}
	}

	for (int i = 0; i < count; i++) {
		if (strcmp(word[sortnum[i]], word[sortnum[i+1]]) == 0) {
			int j, flag = 0;
			for (j = i
				; j < count - 1 && strcmp(word[sortnum[j]], word[sortnum[j+1]]) == 0
				; j++) 
			{
				if (pagenum[sortnum[j]] > pagenum[sortnum[j+1]]) {
					SWAP(sortnum[j], sortnum[j+1]);
					flag = 1;
				}
			}
			if (flag)
				i--;
			else
				i = j;
		}
	}

	for (int i = 0; i < count; i++) {
		cout << word[sortnum[i]] << endl;
		if (strcmp(word[sortnum[i]], word[sortnum[i+1]]) == 0) {
			for (; i < count && strcmp(word[sortnum[i]], word[sortnum[i+1]]) == 0; i++) {
				cout << pagenum[sortnum[i]] << ' ';
			}
		}
		cout << pagenum[sortnum[i]] << endl;
	}
	return 0;
}

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

int main() {
	vector<string> words;
	vector<vector<int> > pages;
	string word; int page;
	while (cin>>word>>page) {
		bool is_there = false; int word_place;
		for (int i = 0; i < words.size(); i++) {
			if (word == words[i]) {
				is_there = true;
				word_place = i;
			}
		}
		if (is_there) {
			pages[word_place].push_back(page);
		}
		else {
			words.push_back(word);
			vector<int>* x = new vector<int>;
			pages.push_back(*x);
			pages[pages.size() - 1].push_back(page);
		}
	}
	for (int i = 0; i < words.size() - 1; i++) {
		for (int j = 0; j < words.size() - 1; j++) {
			if (words[j] > words[j + 1]) {
				string tmp_w=words[j];
				words[j] = words[j + 1];
				words[j + 1] = tmp_w;
				vector<int> tmp_p=pages[j];
				pages[j] = pages[j + 1];
				pages[j + 1] = tmp_p;
			}
		}
	}
	for (int i = 0; i < words.size(); i++) {
		for (int j = 0; j < pages[i].size()-1; j++) {
			for (int c = 0; c < pages[i].size()-1; c++) {
				if (pages[i][c] > pages[i][c + 1]) {
					int tmp=pages[i][c];
					pages[i][c] = pages[i][c + 1];
					pages[i][c + 1] = tmp;
					}
			}
		}
	}
	for (int i = 0; i < words.size(); i++) {
		cout << words[i] << endl;
		for (int m = 0; m < pages[i].size(); m++) {
			cout << pages[i][m]<<' ';
		}
		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;
int main(){
    pair<string,int> index[1000];
    int cnt;
    for(cnt=0;cin>>index[cnt].first>>index[cnt].second;cnt++);
    sort(index,index+cnt);
    cout << index[0].first << endl << index[0].second;
    rep(i,cnt){
        if(i == 0) continue;
        if(index[i].first == index[i-1].first) cout << " " << index[i].second;
        else cout << endl << index[i].first << endl << index[i].second;
    }
    cout << endl;
    return 0;
}

C++: #include <bits/stdc++.h>
using namespace std;

int main() {
	cin.tie(nullptr);
	ios::sync_with_stdio(false);

	map<string, vector<int>> idx;

	string word;
	int page;
	while(cin >> word >> page) {
		idx[word].emplace_back(page);
	}

	for(auto &word_info : idx) {
		cout << word_info.first << "\n";

		vector<int> &pages = word_info.second;
		sort(pages.begin(), pages.end());
		pages.erase(unique(pages.begin(), pages.end()), pages.end());

		for(unsigned i = 0; i < pages.size(); ++i) {
			cout << pages[i] << (i + 1 == pages.size() ? "\n" : " ");
		}
	}

	return 0;
}

C++: #include <iostream>
#include <vector>
#include <algorithm>
#include <numeric>
#include <set>
#include <map>
#include <string>
#include <stack>
#include <queue>
#include <cmath>
#include <cstdio>
#include <istream>
#include <sstream>
#include <iomanip>
#include <iterator>
#include <climits>
using namespace std;

typedef ostringstream OSS;
typedef istringstream ISS;

typedef vector<int> VI;
typedef vector< VI > VVI;

typedef long long LL;

typedef pair<int, int> PII;
typedef vector<PII> VPII;

#define X first
#define Y second

int main(void) {
	map<string, set<int>> m;
	string name;
	int num;

	while (cin >> name >> num) {
		if (m.count(name)) {
			m[name].insert(num);
		} else {
			m[name] = set<int>();
			m[name].insert(num);
		}
	}

	for (auto &one : m) {
		cout << one.first << endl;
		for (auto &index : one.second) {
			cout << index << (index == *(one.second.rbegin()) ? '\n' : ' ');
		}
	}

	return 0;
}

C++: #include<iostream>
#include<map>
#include<string>
using namespace std;
int main()
{
	int page, n;
	string word;
	typedef map<string, map<int,int> > Dic;
	Dic dic;
	Dic::iterator ite1;
	map<int,int>::iterator ite2;
	while(cin >> word >> page)
	{
		dic[word][page]++;
	}
	for(ite1=dic.begin();ite1!=dic.end();++ite1)
	{
		cout << ite1->first << endl;
		n = 0;
		for(ite2=ite1->second.begin(); ite2 != ite1->second.end(); ++ite2)
		{
			if(n++) cout<< ' ';
			cout << ite2->first;
		}
		cout << endl;
	}
	return 0;
}

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

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

C++: #include <algorithm>
#include <cstdio>
#include <map>
#include <string>
#include <vector>

using namespace std;

int main() {
  map<string, vector<int>> index;
  char *line = NULL;
  size_t buffer_size = 0;
  while (getline(&line, &buffer_size, stdin) > 0) {
    char word[40];
    int page;
    sscanf(line, "%s %d", word, &page);
    string key(word);
    index[key].push_back(page);
  }
  free(line);
  for (const auto& entry : index) {
    printf("%s\n", entry.first.c_str());
    vector<int> pages(entry.second);
    sort(pages.begin(), pages.end());
    for (auto iter = pages.cbegin(); iter != pages.cend(); ++iter) {
      printf("%d%c", *iter, (iter + 1 == pages.cend() ? '\n' : ' '));
    }
  }

  return 0;
}