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<stdio.h>
 #include<string>
 #include<math.h>
 #include<iomanip>
 #include<algorithm>
 #include<string.h>
 #include<cctype>
 #include<map>
 #include<set>
 #include<vector>
 #include<sstream>
 #include<stack>
 #include<queue>
 
 using namespace std;
 
 
 
 int main()
 {
   map<string,set<int> > mm;
   map<string,set<int> >::iterator iter;
   string s;
   int num;
   while(cin>>s>>num)
   {
     mm[s].insert(num);
     if(num==0) break;                  
   }
   for(iter=mm.begin();iter!=mm.end();++iter)
   {
     cout<<iter->first<<endl;
     set<int>::iterator iter2;
     for(iter2=(iter->second).begin();iter2!=(iter->second).end();++iter2)
     {
       if(iter2==((*iter).second).begin()) cout<<*iter2;
       else cout<<" "<<*iter2;                                                                     
     }                   
     cout<<endl;                      
   }
   //while(1);
   return 0;
 }

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,p!=0){
    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<string>
#include<map>
#include<set>
using namespace std;

int main(){
	map<string, set<int> > index;
	string s;
	int n;
	while(cin >> s >> n)
		index[s].insert(n);
		
	map<string,set<int> >::iterator it = index.begin();
	while(it != index.end()){
		cout << it->first << endl;
		set<int>::iterator its = (it->second).begin();
		while(its != (it->second).end()){
			cout << *its;
			cout << (++its != (it->second).end() ? " " : "\n");
		}
		++it;
	}
	return 0;
}

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);
		if (s == "even"&&a==18)break;
	}
	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;
		}
	}
}

C++: #include <iostream>
#include<string>
#include<utility>
using namespace std;
int main() {
    pair<string,int> go[100000];
    int i=0;
    while(cin>>go[i].first>>go[i].second){
        i++;
    }
    int at;
    string fir;
    at=0;
    for(int l=0;l<i;++l){
        fir="zzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzz";
        for(int j=l;j<i;++j){
            if(go[j].first<=fir){
                fir=go[j].first;
                at=j;
            }
        }
        swap(go[at],go[l]);
    }
    fir=go[0].first;
    for(int k=1;k<i;++k){
        if(go[k].first!=fir){
        fir=go[k].first;
        }
        else{
            go[k].first="-1";
        }
    }
    int min=100000;
    
    for(int k=0;k<i;++k){
        at=k;
        min=100000;
        for(int l=k;l<i;++l){
            if(l!=k&&go[l].first!="-1"){
                break;
            }
            if(go[l].second<min){
                min=go[l].second;
                at=l;
            }
        }
        swap(go[k].second,go[at].second);
    }
    for(int k=0;k<i;++k){
        if(go[k].first=="-1"){
            cout<<" "<<go[k].second;
        }
        else{
            cout<<endl<<go[k].first<<endl<<go[k].second;
        }
    }
    cout<<endl;
    return 0;
}

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

typedef std::map<std::string, std::vector<int> > index_t;
typedef std::pair<std::string, std::vector<int> > info_t;

index_t index;

std::string word;
int page_num;
bool get_input()
{
	return (std::cin >> word >> page_num);
}

int main()
{
	index_t::iterator word_itr;
	while (get_input()) {
		word_itr = index.find(word);
		if (word_itr == index.end()) {
			std::vector<int> page_nums;
			page_nums.push_back(page_num);
			info_t info(word, page_nums);
			index.insert(info);
		} else {
			word_itr->second.push_back(page_num);
		}
	}
	for (index_t::iterator i = index.begin(); i != index.end(); i++) {
		std::cout << i->first << std::endl;
		std::sort(i->second.begin(), i->second.end());
		for (std::vector<int>::iterator j = i->second.begin(); j != i->second.end(); j++) {
			if (j != i->second.end() -1) {
				std::cout << *j << " ";
			} else {
				std::cout << *j;
			}
		}
		std::cout << std::endl;
	}
	return 0;
}

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

typedef std::map< std::string,std::vector<int> > Dic;
int main(){
	std::string input;
	int inum;
	Dic map;
	while( std::cin>>input>>inum )
		map[input].push_back(inum);
	
	for(auto it=map.begin();it!=map.end();++it){
			std::cout<<it->first<<std::endl;
			std::sort(it->second.begin(),it->second.end());
			for(int Page=0; Page!=it->second.size(); ++Page){
				std::cout<<it->second[Page]<<(Page==it->second.size()-1?"\n":" ");
			}
		}
	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(1000);
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++;
    }
    cout << endl;
    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 << " ";
    }

    return 0;
}