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++: #include <cstdio>
#include <string>
#include <vector>
#include <iostream>
#include <algorithm>
#include <map>
using namespace std;
map<string,vector<int> > m;
vector<string> v;
int main(void){
  string s;
  int p;
  while(cin >> s >> p){
    if(m.find(s) == m.end()){
      v.push_back(s);
    }
    m[s].push_back(p);
  }

  sort(v.begin(),v.end());
  for(int i = 0; i < (int)v.size(); i++){
    cout << v[i] << endl;
    sort(m[v[i]].begin(),m[v[i]].end());
    for(int j = 0; j < (int)m[v[i]].size(); j++){
      cout << m[v[i]][j] << ((j+1==(int)m[v[i]].size())?'\n':' ');
    }
  }
}

C++: #include<iostream>
#include<string>
#include<algorithm>
#include<map>
#include<set>
#include<utility>
#include<vector>
#include<cmath>
#include<cstring>
#include<cstdio>
#include<time.h>
#define loop(i,a,b) for(int i=a;i<b;i++) 
#define rep(i,a) loop(i,0,a)
#define pb push_back
#define mp make_pair
#define all(in) in.begin(),in.end()
const double PI=acos(-1);
const double EPS=1e-10;
using namespace std;
typedef long long ll;
typedef vector<int> vi;
int main(){
	string s;
	int n;
	map<string,vector<int> >in;
	while(cin>>s>>n)in[s].pb(n);
	map<string,vector<int> >::iterator it;
	for(it=in.begin();it!=in.end();it++){
		string d=it->first;
		sort(all(in[d]));
		cout<<d<<endl;
		rep(i,in[d].size()-1)cout<<in[d][i]<<" ";
		cout<<in[d][in[d].size()-1]<<endl;
	}
}

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

int main(){
  map<string,vector<int> > m;
  string s;
  int page;

  while(cin>>s>>page){
    m[s].push_back(page);
  }

  for(map<string,vector<int> >::iterator i=m.begin();i!=m.end();i++){
    vector<int> v = (i->second);
    cout<<(i->first)<<endl;
    sort(v.begin(),v.end());
    for(int i=0;i<v.size();i++){
      if(i != 0) cout<<" ";
      cout<<v[i];
    }
    cout<<endl;
  }
}

C++: #include <bits/stdc++.h>
using namespace std;
int main(){
  map<string,vector<int> >A;
  string s;
  int n;
  while(cin>>s>>n){
    A[s].push_back(n);
  }
  map<string,vector<int> >::iterator t=A.begin();
  while(t!=A.end()){
    cout<<t->first<<endl;
    sort(t->second.begin(),t->second.end());
    for(int i=0;i<t->second.size();i++){
      if(i)cout<<' '<<t->second[i];
      else cout<<t->second[i];
    }
    cout<<endl;t++;
  }
}

C++: #include <stdio.h>
#include <string.h>
#include <algorithm>

char voc[105][50], str[50];
int  page[105][105];

using namespace std;

int main(void)
{
	int n, i, j, k, c, ii;
	
	i = 0;
	while (scanf("%s %d", str, &n) != EOF){
		
		c = 0;
		
		for (j = 0; j < i; j++){
			if (strcmp(str, voc[j]) == 0){
				
				k = 0;
				while (page[j][k] != 0){
					k++;
				}
				page[j][k] = n;
				c = 1;
			}
		}
		
		if (c == 0){
			strcpy(voc[i], str);
			page[i][0] = n;
			i++;
		}
	}
	
	for (j = 0; j < i; j++){
		for (k = 0; k < i - j - 1; k++){
			
			if (strcmp(voc[k], voc[k + 1]) > 0){
				strcpy(str, voc[k]);
				strcpy(voc[k], voc[k + 1]);
				strcpy(voc[k + 1], str);
				
				ii = 0;
				while (page[k][ii] != 0 || page[k + 1][ii] != 0){
					page[k][ii] += page[k + 1][ii];
					page[k + 1][ii] = page[k][ii] - page[k + 1][ii];
					page[k][ii] -= page[k + 1][ii];
					
					ii++;
				}
			}
		}
	}
	
	for (j = 0;j < i; j++){
		k = 0;
		while (page[j][k] != 0){
			k++;
		}
		sort(&page[j][0], &page[j][0] + k);
	}
	
	for (j = 0; j < i; j++){
		printf("%s\n", voc[j]);
		k = 0;
		
		while (1){
			printf("%d", page[j][k]);
			k++;
			
			if (page[j][k] == 0){
				break;
			}
			else{
				printf(" ");
			}
		}
		printf("\n");
	}
	
	return (0);
}

C++: #define _USE_MATH_DEFINES
#include "bits/stdc++.h"
using namespace std;

//#define int long long
#define DBG 1
#define dump(o) if(DBG){cerr<<#o<<" "<<o<<endl;}
#define dumpc(o) if(DBG){cerr<<#o; for(auto &e:(o))cerr<<" "<<e;cerr<<endl;}
#define rep(i,a,b) for(int i=(a);i<(b);i++)
#define rrep(i,a,b) for(int i=(b)-1;i>=(a);i--)
#define each(it,c) for(auto it=(c).begin();it!=(c).end();it++)
#define all(c) c.begin(),c.end()
const int INF = sizeof(int) == sizeof(long long) ? 0x3f3f3f3f3f3f3f3fLL : 0x3f3f3f3f;
const int MOD = (int)(1e9 + 7);

signed main() {
	map<string, vector<int>>M;
	string s; int n;
	while (cin >> s >> n) {
		M[s].push_back(n);
	}
	each(it, M) {
		cout << it->first << endl;
		sort(it->second.begin(), it->second.end());
		int i(0);
		each(that, it->second) {
			if (i++)cout << " ";
			cout << *that;
		}
		cout << endl;
	}
	return 0;
}

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

using namespace std;

int main(void) {
	map<string, vector<int> > dic;
	string str;
	int page;
	int i;

	while(!cin.eof()) {
		cin >> str >> page;
		if(!cin.eof()) { dic[str].push_back( page ); }
	}

	map<string, vector<int> >::iterator it = dic.begin();
	while(it != dic.end() ) {
		cout << (*it).first << endl;
		sort((*it).second.begin(), (*it).second.end());
		for(i = 0; i < (int)(*it).second.size(); i++) {
			cout << (*it).second[i];
			if(i < (int)(*it).second.size()-1) { cout << " "; }
		}
		cout << endl;
		++it;
	}

	return 0;
}

C++: #include <iostream>
#include <vector>
#include <algorithm>
#include <string>
#include <map>
#include <cmath>
#include <queue>
#include <numeric>
#include <climits>
#include <iterator>
#include <iomanip>
#include <stack>
#include <set>
#include <cstdio>
#include <bitset>
#include <functional>
#include <tuple>
#include <list>
#include <deque>
#include <sstream>
using namespace std;
typedef pair<int, int> P;

#define FOR(i, a, n) for (ll i = (ll)a; i<(ll)n; ++i)
#define REP(i, n) FOR(i, 0, n)

typedef long long ll;
typedef vector<int> VI;

struct Less{
   bool operator()(const pair<string, int>&a, const pair<string, int>&b){
        if(a.first==b.first){
            return a.second < b.second;
        }
       return a.first < b.first;
    }
};
int GCD(int a, int b){
    if(b==0) return a;
    return GCD(b, a%b);
}

int main() {
    vector<pair<string, int> > vp;
    string s; int n;
    while(cin >> s >> n){
        vp.push_back({s, n});
    }
    
    sort(vp.begin(), vp.end(), Less());
    vp.push_back({"BANPEI", 1});
    string ss=vp[0].first;
    cout << ss << endl;
    for(int i=1; i<vp.size(); ++i){
        if(vp[i].first==ss){
            cout << vp[i-1].second << " ";
        }else{
            cout << vp[i-1].second << endl;
            if(i==vp.size()-1) break;
            ss = vp[i].first;
            cout << ss << endl;
        }
    }
	return 0;
}