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

using namespace std;

int print_vec(const vector<int>& v)
{
	for (int i = 0; i < v.size(); i++){
		printf("%d%c", v[i], " \n"[i == v.size() - 1]);
	}
	return 0;
}

int main()
{
	map<string, vector<int> > dict;
	string word;
	int page;
	while (cin >> word >> page){
		if (!dict.count(word)){
			vector<int> v;
			v.push_back(page);
			dict[word] = v;
		}
		else dict[word].push_back(page);
	}
	for (map<string, vector<int> >::iterator it = dict.begin(); it != dict.end(); ++it){
		sort(it->second.begin(), it->second.end());
		cout << it->first << "\n";
		print_vec(it->second);
	}
}

C++: #include <bits/stdc++.h>
using namespace std;
pair<string,int> a[100];
int main(){
	int t=0,g;
	string f,b;
	while(cin>>a[t].first>>a[t].second)t++;
	sort(a,a+t);
	b=a[0].first
	cout<<b<<endl<<a[0].second;
	for(int i=1;i<t;i++){
		bool n=0;
		f=a[i].first,g=a[i].second;
		if(i)if(f==b)n=1;
		if(n)cout<<" "<<g;
		else cout<<endl<<f<<endl<<g;
		b=f;
	}
	cout<<endl;
	return 0;
}

C++: #include <iostream>
#include <algorithm>
#include <map>
#include <set>
#include <queue>
#include <stack>
#include <numeric>
#include <bitset>
#include <cmath>

static const int MOD = 1000000007;
using ll = long long;
using u32 = unsigned;
using u64 = unsigned long long;
using namespace std;

template<class T> constexpr T INF = ::numeric_limits<T>::max()/32*15+208;

int main(){
    string s; int x;
    map<string, vector<int>> m;
    while(cin >> s >> x){
        m[s].emplace_back(x);
    }
    for (auto &&i : m) {
        sort(i.second.begin(),i.second.end());
        cout << i.first << "\n";
        for (int j = 0; j < i.second.size(); ++j) {
            if(j) printf(" ");
            printf("%d", i.second[j]);
        }
        puts("");
    }
    return 0;
}

C++: #define	_USE_MATH_DEFINES
#include <iostream>
#include <algorithm>
#include <functional>
#include <vector>
#include <cstdio>
#include <cstring>
#include <cmath>
#include <cfloat>
#include <map>
#include <queue>
#include <stack>
#include <list>
#include <string>
using namespace std;
int main(){
	
	string str;
	int a;
	int k=0;
	map<string,int> data;
	vector<string> s;
	vector< vector<int> > p(1000); 
	
	while(cin>>str>>a){
		if(data.find(str)==data.end()){
			data[str]=k++;
			s.push_back(str);
		}
		p[data[str]].push_back(a);
		
	}
	sort(s.begin(),s.end());
	
	for(int i=0;i<s.size();i++){
		cout<<s[i]<<endl;
		sort(p[data[s[i]]].begin(),p[data[s[i]]].end());
		cout<<p[data[s[i]]][0];
		for(int j=1;j<p[data[s[i]]].size();j++)
			cout<<" "<<p[data[s[i]]][j];
		cout<<endl;
	}
}

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

template< class T >
void exchange( T &a, T &b )
{
    T c  = a;
    a = b;
    b = c;
}

int main()
{
    string str, words[100];
    int p, d[100];

    int i = 0;
    while( cin >> str )
    {
        cin >> p;
        words[i] = str;
        d[i] = p;
        i++;
    }

    for( int j = 0; j < i - 1; j++ )
        for( int k = j + 1; k < i; k++ )
            if( words[j] > words[k] )
            {
                exchange( words[j], words[k] );
                exchange( d[j], d[k] );
            }

    for( int j = 0; j < i - 1; j++ )
        for( int k = j + 1; k < i; k++ )
            if( words[j] == words[k] && d[j] > d[k] )
                exchange( d[j], d[k] );

    cout << words[0] << endl << d[0];
    for( int j = 1; j < i; j++ )
        if( words[j-1] == words[j] )
            cout << " " << d[j];
        else
            cout << endl << words[j] << endl << d[j];
    
    cout << endl;

    return 0;
}

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

int main()
{
	vector< pair<string,int> > v;
	pair<string,int> w;
	while(cin>>w.first>>w.second)
	{
		v.push_back(w);
	}
	sort(v.begin(),v.end());
	for(int i=0;i<v.size();i++)
	{
		if(i==0)
		{
			cout<<v[i].first<<endl<<v[i].second;
		}
		else if(v[i].first!=v[i-1].first||i==0)
		{
			cout<<endl<<v[i].first<<endl<<v[i].second;
		}
		else
		{
			cout<<" "<<v[i].second;
		}
	}
}

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

using namespace std;

int main(int argc, char const *argv[]){
    vector<int> pages;
    map<string, vector<int> > books; 
    string name;
    int page;

    while (cin>>name>>page){
        auto it = books.find(name);
        if (it != books.end()){
            books[name].push_back(page);
        }
        else{
            vector<int> pages = {page};
            books.insert(make_pair(name, pages));
        }
    }

    for (auto& book : books){
        cout<<book.first<<endl;

        sort(book.second.begin(), book.second.end());

        for (const auto& page : book.second){
            cout<<page<<" ";
        }
        cout<<'\n';
    }
    return 0;
}

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

using namespace std;

int main(void){

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

C++: #include<iostream>
#include<algorithm>
#include<string>
#include<map>
#include<vector>
using namespace std;
int main()
{
	multimap<string,int> ans;
	string in; int num;
	while(cin>>in>>num) 
	{
		ans.insert(multimap<string,int>::value_type(in,num));
	}

	multimap<string,int>::iterator it=ans.begin();
	while(1) 
	{
		int cnt=ans.count((*it).first);
		cout<<(*it).first<<endl;
		bool f=false;
		vector<int> nums;
		while(cnt--) 
		{
			nums.push_back((*it).second);
			it++;
		}
		sort(nums.begin(),nums.end());
		for(int i = 0; i < nums.size(); ++i)
		{
			if(f) cout<<" ";
			cout<<nums[i];
			f=true;
		}
		if(it==ans.end()) break;
		cout<<endl;
	}
  return 0;
}

C++: #include <iostream>
#include <vector>
#include <fstream>
#include <algorithm>
#include <iomanip>
#include <map>
#include <queue>
#include <stack>
#include <set>
#include <ctime>
#include <iterator>
#include <sstream>
#include <cstdio>
#include <cstdlib>
#include <cmath>
using namespace std;


int main()
{
    map<string,set<int> > m;
    while(!cin.eof())
    {
        string s;
        int p;
        cin>>s>>p;
        m[s].insert(p);
    }
    for(map<string,set<int> >::iterator it = m.begin();it!=m.end();it++)
    {
        cout<<(it->first)<<endl;
        bool first = true;
        for(set<int>::iterator it2 = it->second.begin();it2 != it->second.end();it2++)
        {
            cout<<(first?"":" ")<<(*it2);
            first=false;
        }
        cout<<endl;
    }
}