Go: package main

import (
	"bufio"
	"fmt"
	"os"
	"sort"
)

var scanner = bufio.NewScanner(os.Stdin)

func main() {
	dictionary := make(map[string][]int)

	for {
		var word string
		var page int
		fmt.Scanf("%s %d", &word, &page)

		if word == "" || page == 0 {
			break
		}

		pages := dictionary[word]
		pages = append(pages, page)
		dictionary[word] = pages
	}

	words := make([]string, 0)
	for i := range dictionary {
		words = append(words, i)
	}

	sort.Strings(words)

	for _, v := range words {
		sort.Ints(dictionary[v])
		fmt.Println(v)
		for i, page := range dictionary[v] {
			if i == len(dictionary[v])-1 {
				fmt.Printf("%d\n", page)
			} else {
				fmt.Printf("%d ", page)
			}
		}
	}
}

C++: //#define __USE_MINGW_ANSI_STDIO 0
#include <bits/stdc++.h>

using namespace std;
typedef long long ll;
typedef vector<int> VI;
typedef vector<VI> VVI;
typedef vector<ll> VL;
typedef vector<VL> VVL;
typedef pair<int, int> PII;

#define FOR(i, a, n) for (ll i = (ll)a; i < (ll)n; ++i)
#define REP(i, n) FOR(i, 0, n)
#define ALL(x) x.begin(), x.end()
#define IN(a, b, x) (a<=x&&x<b)
#define MP make_pair
#define PB push_back
#define INF (1LL<<30)
#define LLINF (1LL<<60)
#define PI 3.14159265359
#define EPS 1e-12
//#define int ll

template <typename T> T &chmin(T &a, const T &b) { return a = min(a, b); }
template <typename T> T &chmax(T &a, const T &b) { return a = max(a, b); }

int dx[] = {0, 1, 0, -1}, dy[] = {1, 0, -1, 0};

map<string, VI> idx;
signed main(void)
{
  string s;
  int num;
  while(cin>>s>>num) {
    idx[s].PB(num);
  }

  for(auto i: idx) {
    cout << i.first << endl;
    sort(ALL(i.second));
    REP(j, i.second.size()) {
      cout << i.second[j];
      if(j != i.second.size()-1) cout << " ";
    }
    cout << endl;
  }

  return 0;
}

C++: #include<iostream>
#include<string>
#include<cstdio>
#include<algorithm>
#include<stack>
#include<queue>
#include<vector>
#include<cmath>
#include<utility>
#include<set>
#include<complex>
#include<map>
#define vi vector<int>
#define vvi vector<vector<int> >
#define ll long long int
#define vl vector<ll>
#define vvl vector<vector<ll>>
#define vb vector<bool>
#define vc vector<char>
#define vs vector<string>
#define ld long double
#define INF 1e9
#define EPS 0.0000000001
#define rep(i,n) for(int i=0;i<n;i++)
#define loop(i,s,n) for(int i=s;i<n;i++)
#define all(in) in.begin(), in.end()
#define MAX 9999999
using namespace std;
typedef pair<int, int> pii;
typedef pair<double,double>pdd;
typedef pair<ll,ll>pll;
int main(){
    string temp;
    map<string,vi>mp;
    
    while(cin>>temp){
        int n; cin>>n;
        mp[temp].push_back(n);
        sort(all(mp[temp]));
    }
    for(auto itr=mp.begin();itr!=mp.end();itr++){
        cout<<itr->first<<endl;
        rep(i,mp[itr->first].size()){if(i)cout<<" ";cout<<mp[itr->first][i];}
        cout<<endl;
    }
}

C++: #include<iostream>
#pragma warning(disable:4786)
#include<map>
#include<vector>
#include<string>
#include<algorithm>
using namespace std;
int main() {
	string a;
	map<string, vector<int>> d;
	while(getline(cin,a)){
		string b, h = "";
		int c, sum = 0;
		a += " ";
		for (int i = 0; i < a.length(); i++) {
			if (a[i] == ' ') {
				if (sum == 0)
					b = h;
				else
					c = atoi(h.c_str());
				sum++;
				h = "";
			}
			else
				h += a[i];
		}
		d[b].push_back(c);
		d[b].clear();
		d[b].push_back(c);
	}
	map<string, vector<int>>::iterator t = d.begin();
	while (t != d.end()) {
		string k = (*t).first;
		sort(d[k].begin(), d[k].end());
		cout << k;
		for (int i = 0; i != d[k].size(); i++) {
			cout << " " << d[k][i];
		}
		cout << endl;
		t++;
	}
}

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

using namespace std;

// ??????????????§??????????????¢?´¢?????????????????????

int main(){
	
	map<string, vector<int> > m;
	map<string, vector<int> >::iterator ite;
	
	string str;
	int p;
	
	while(true){
		cin >> str;
		if(cin.eof()){
			break;
		}
		cin >> p;
		vector<int> v;
		ite = m.find(str);
		if(ite != m.end()){
			(ite -> second).push_back(p);
		}else{
			v.push_back(p);
			m.insert(make_pair(str, v));
			v.erase(v.begin(), v.end());
		}
	}
	
	for(ite = m.begin(); ite != m.end(); ite++){
		cout << ite -> first << endl;
		sort((ite -> second).begin(), (ite -> second).end());
		printf("%d", (ite -> second).at(0));
		for(int i = 1; i < (ite -> second).size(); i++){
			printf(" %d", (ite -> second).at(i));
		}
		printf("\n");
	}
	
	return 0;
}

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

typedef struct{
	int jun;
	string tango;
	vector<int> page;
}sakuin;

int main(){
	vector<string> words;
	sakuin pages[100];
	string word;
	int num;
	int all;
	bool flag;

	cin >> word >> num;
	words.push_back(word);
	pages[0].jun = 0;
	pages[0].tango = word;
	pages[0].page.push_back(num);
	all = 1;

	while(cin >> word >> num){
		flag = true;
		for(int j=0;j<all;j++){
			if(pages[j].tango == word){
				pages[j].page.push_back(num);
				sort(pages[j].page.begin(),pages[j].page.end());
				flag = false;
				break;
			}
		}
		if(flag){
			words.push_back(word);
			sort(words.begin(),words.end());
			all++;
			for(int i=0;i<all;i++){
				if(words[i] == word){
					pages[all-1].jun = i;
					pages[all-1].tango = word;
					pages[all-1].page.push_back(num);

					for(int j=i+1;j<all;j++){
						for(int k=0;k<all;k++){
							if(words[j] == pages[k].tango)
								pages[k].jun += 1;
						}
					}
					break;
				}
			}
		}
	}

	for(int i=0;i<all;i++){
		for(int j=0;j<all;j++){
			if(pages[j].jun == i){
				cout << pages[j].tango << endl;
				for(unsigned int k=0;k<pages[j].page.size();k++)
					cout << pages[j].page[k] << ' ';
				cout << endl;
				break;
			}
		}
	}
	return 0;
}

C++: #include <bits/stdc++.h>

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;
	} else {
            cout << endl;
        }
	cout << v[i].first << endl;
	cout << v[i].second;
    }
    puts("");
    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("");
    cout << v[i].first << endl;
    cout << v[i].second;
    }

  return 0;
}