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<algorithm>
#include<map>
#include<unordered_map>
#include<string>
#include<utility>
using namespace std;
int main() {
	vector<pair<string, int>> p;
	string str;
	vector<int>num(10000);
	int n,pos=0;
	while (cin >> str) {
		cin >> n;
		p.push_back(pair<string, int>(str, n));
	}
	sort(p.begin(),p.end());
	auto itr = p.begin();
	cout << itr->first << endl << itr->second;
	itr++;
	while (itr!=p.end()) {
		if ( (itr - 1)->first == itr->first) {
			cout << " " << itr->second ;
		}
		else {
			cout <<endl<< itr->first << endl<<itr->second;
		}
		itr++;
	}cout << endl;
	return 0;
}

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

struct data{
	string s;
	vector<int> vi;
};

bool comp(data d1, data d2){
	return d1.s < d2.s;
}

int main(){
	int n;
	vector<data> vd;
	string s;
	while(cin >> s >> n){
		int i = 0;
		while(i < vd.size() && vd[i].s != s) i++;
		if(i == vd.size()){
			data d;
			d.s = s;
			vd.push_back(d);
		}	
		vd[i].vi.push_back(i);
		sort(vd[i].vi.begin(), vd[i].vi.end());
	}
	sort(vd.begin(), vd.end(), comp);
	for(int i = 0; i < vd.size(); i++){
		cout << vd[i].s << endl;
		for(int j = 0; j < vd[i].vi.size(); j++){
			if(j != 0) cout << " ";
			cout << vd[i].vi[j];
		}
		cout << endl;
	}
	return 0;
}

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

int main(void) {
	string str;
	multimap<string, int> m;
	multimap<string, int>::iterator iter;
	int n;

	while(cin >> str >> n)
		m.insert(pair<string, int>(str, n));

	iter = m.begin();
	while(iter != m.end()) {
		pair<multimap<string, int>::iterator, multimap<string, int>::iterator> p;
		p = m.equal_range(iter->first);

		vector<pair<string,int> > v(p.first, p.second);
		sort(v.begin(), v.end());
		cout << v[0].first << endl;
		for(int i = 0; i < v.size() - 1; i++) {
			cout << v[i].second << " ";
		}
		cout << v[v.size() - 1].second << endl;
		iter = p.second;
	}
}

C++: #include <iostream>
#include <cstdio>
#include <string>
#include <cstring>
#include <set>
#include <map>
#include <utility>
using namespace std;

#define rep2(x,from,to) for(int x=(from);(x)<(to);(x)++)
#define rep(x,to) rep2(x,0,to)
int main() {
	char s[35];
	map<string, set<int> > m;
	int x;
	while(1) {
		if(scanf("%s %d", s, &x) == EOF) break;
		if(m.count(s) == 0) {
			set<int> v;
			v.insert(x);
			m.insert(make_pair(s, v));
		} else {
			set<int> v = m[s];
			v.insert(x);
			m[s] = v;
		}
	}
	for(auto it = m.begin(); it != m.end(); ++it) {
		cout << (*it).first << endl;
		for(auto it2 = it->second.begin(); it2 != --(it->second).end(); ++it2) {
			cout << *it2 << " ";
		}
		cout << *--(it->second).end() << endl;
	}
	return 0;
}

C++: #include <iostream>
#include <map>
#include <vector>
#include <algorithm>
using namespace std;
int main(){
  map<string, vector<int> > in;

  string goku;
  int id;
  while( cin >> goku >> id ){
    in[goku].push_back(id);
  }
    for( map < string, vector<int> >::iterator it = in.begin() ; it != in.end() ; it++ ){

      cout << (*it).first << endl;
    vector <int>& go = (*it).second;
    sort(go.begin(),go.end());
    for(vector <int>::iterator  it_p = go.begin() ; it_p != go.end() ; it_p++ ){
      cout << (*it_p);
      if(it_p+1 != go.end() )cout << " ";
    }
    cout << endl;
    }

  return 0;
}

C++: #include<iostream>
//#include<pair>
#include<vector>
#include<algorithm>
#define loop(i,a,b) for(int i=a;i<b;i++)
#define rep(i,a) loop(i,0,a)
using namespace std;

class data{
public:
	vector<int> num;
	string s;
};

int main(){
	int n;
	string str;
	vector<data> vec;
	while(cin>>str){
		cin>>n;
		data dt;
		dt.num.push_back(n);
		dt.s=str;
		int cnt=0;
		for(int i=0;i<vec.size();i++){
			if(str==vec[i].s){
				vec[i].num.push_back(n);
				cnt++;
			}
		}
		if(cnt==0)vec.push_back(dt);
	}
	//for(int i=0;i<vec.size();i++)cout<<vec[i].s<<" ";
	//cout<<endl;
	for(int i=0;i<vec.size();i++){
		//cout<<i<<endl;
		for(int j=vec.size()-1-i;j>=1;j--){
			//cout<<j<<" ";
			if(vec[j-1].s>vec[j].s){
				data alt=vec[j];
				vec[j]=vec[j-1];
				vec[j-1]=alt;
			}
		}
		//cout<<endl;
	}
	for(int i=0;i<vec.size();i++){
		int volume=vec[i].num.size();
		sort(vec[i].num.begin(),vec[i].num.end());
	}
	for(int i=0;i<vec.size();i++){
		cout<<vec[i].s<<endl;
		cout<<vec[i].num[0];
		for(int j=1;j<vec[i].num.size();j++){
			cout<<" "<<vec[i].num[j];
		}
		cout<<endl;
	}
	return 0;
}

C++: #include<cstdio>
#include<map>
#include<vector>
#include<string>
#include<algorithm>
using namespace std;
int main(void)
{
	map < string, vector<int> > index;

	char cbuf[31];
	int ibuf;

	while (scanf("%s %d", cbuf, 31, &ibuf) != EOF)
	{
		index[cbuf].push_back(ibuf);
	}

	for (auto &elem : index)
	{
		sort(elem.second.begin(), elem.second.end());
		printf("%s\n", elem.first.c_str());
		for (auto &vecElem : elem.second)
		{
			printf("%d ", vecElem);
		}
		printf("\n");
	}

	return 0;
}

C++: //#include <bits/stdc++.h>
#include<iostream>
#include<algorithm>
#include<string>
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 <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].secosnd;
        }
    }
    cout << endl;
    return 0;
}