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 <sstream>
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <ctime>
#include <cstring>
#include <string>
#include <vector>
#include <stack>
#include <queue>
#include <deque>
#include <map>
#include <set>
#include <bitset>
#include <numeric>
#include <utility>
#include <iomanip>
#include <algorithm>
#include <functional>
using namespace std;

typedef long long ll;
typedef vector<int> vint;
typedef vector<long long> vll;
typedef pair<int,int> pint;
typedef pair<long long, long long> pll;

#define MP make_pair
#define PB push_back
#define ALL(s) (s).begin(),(s).end()
#define EACH(i, s) for (__typeof__((s).begin()) i = (s).begin(); i != (s).end(); ++i)
#define COUT(x) cout << #x << " = " << (x) << " (L" << __LINE__ << ")" << endl

template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }
template<class T1, class T2> ostream& operator << (ostream &s, pair<T1,T2> P) 
{ return s << '<' << P.first << ", " << P.second << '>'; }
template<class T> ostream& operator << (ostream &s, vector<T> P) 
{ for (int i = 0; i < P.size(); ++i) { if (i > 0) { s << " "; } s << P[i]; } return s; }
template<class T> ostream& operator << (ostream &s, vector<vector<T> > P) 
{ for (int i = 0; i < P.size(); ++i) { s << endl << P[i]; } return s << endl; }
template<class T1, class T2> ostream& operator << (ostream &s, map<T1,T2> P) 
{ EACH(it, P) { s << "<" << it->first << "->" << it->second << "> "; } return s; }

string str;
int num;
map<string,vint> ma;

int main() {
    ma.clear();
    while (cin >> str >> num) {
        ma[str].PB(num);
    }
    EACH(it,ma) {
        cout << it->first << endl;
        vint res = it->second;
        sort(ALL(res));
        for (int i = 0; i < res.size(); ++i) {
            cout << res[i];
            if (i != res.size()-1) cout << " ";
        }
        cout << endl;
    }
    return 0;
}

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

using namespace std;

int main(){

	map<string,set<int> > ls;
	string s;
	int num;
	while(cin>>s>>num){
		ls[s].insert(num);
	}
	for(map<string,set<int> >::iterator it = ls.begin(); it != ls.end(); it++){
		cout<<it->first<<endl;
		for(set<int>::iterator iit = (it->second).begin(); iit != (it->second).end();){
			cout<<*iit;
			if(++iit==(it->second.end())){
				cout<<endl;
			}
			else
				cout<<" ";
		}
	}

	return 0;
}

C++: #include <iostream>
#include <cstdio>
#include <cstdlib>
#include <time.h>
#include <math.h>
#include <vector>
#include <queue>
#include <map>
#include <set>
#include <algorithm>
#include <iterator>
#include <sstream>
#include <string>
#include <bitset>
using namespace std;
#define FOR(I,F,N) for(int I = F; I < (int)(N); I++)
#define rep(i, n) FOR(i, 0, n)
#define FIN(V) cout<<V<<endl
#define pb push_back
#define INF (1 << 28)

template<typename T>
void remove(vector<T>& vector, unsigned int index){
vector.erase(vector.begin() + index);
}

typedef pair<int, int> P;
typedef long long ll;
typedef priority_queue<int> pq;
int StrToInt(string);
string IntToStr(int);
int dx[4] = {1, -1, 0, 0};
int dy[4] = {0, 0, 1, -1};

map<string, vector<int> > list;

int main(void){
	string S;
	int n;
	while(cin >> S >> n){
		list[S].push_back(n);
	}
	while(cin >> S){
		sort(list[S].begin(), list[S].end());
		rep(i, list[S].size()){
			if(i != 0)cout << " ";
			cout << list[S][i];
		}
		cout << endl;
	}
	

	return 0;
}



int StrToInt(string s){
	stringstream ss;
	ss << s;
	int val;
	ss >> val;
	return val;
}
string IntToStr(int i){
	stringstream ss;
	ss << i;
	return ss.str();
}

C++: #include <bits/stdc++.h>using namespace std;pair<string,int> a[100];int main(){int t=0,g,i;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(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;
struct A{
  string s;
  int n;
  bool operator<(const A&a)const{
    return s==a.s?n<a.n:s<a.s;
  }
};
int x,i;
string s;
main(){
  A a[1000];
  while(cin>>s>>x){
    a[i++]={s,x};
  }
  sort(a,a+i);
  
  cout<<a[0].s<<'\n'<<a[0].n;
  for(int j=1;j<i;++j){
    if(a[j].s==a[j-1].s)cout<<' '<<a[j].n;
    else cout<<'\n'<<a[j].s<<endl<<a[j].n;
  }
  cout<<endl;
}

C++: #include <bits/stdc++.h>
using namespace std;
#define FOR(i, s, n) for(int i = s; i < (int)n; i++)
#define per(i, n) for(int i = n; i >= 0; i--)
#define ROF(i, s, n) for(int i = s; i >= (int)n; i--)
#define FORIT(i, A) for (auto i : A)
#define PRINT(x) cout << (x) << "\n"
#define ALL(a) (a).begin(),(a).end()
#define RALL(a) (a).rbegin(), (a).rend()
#define MP make_pair
#define EACH(i, n) for (__typeof((n).begin()) i = (n).begin(); i != (n).end(); ++i)
#define SZ(a) int((a).size())
#define EXIST(s,e) ((s).find(e)!=(s).end())
#define SORT(c) sort((c).begin(),(c).end())
#define CLR(a) memset((a), 0 ,sizeof(a))
#define dump(x) cout << #x << " = " << (x) << "\n";
#define debug(x) cout << #x << " = " << (x) << " (L" << __LINE__ << ")" << " " << __FILE__ << "\n";
#define sq(n) (n) * (n)
typedef vector<int> VI;
typedef vector<VI> VVI;
typedef vector<string> VS;
typedef pair<int, int> PII;
typedef long long LL;
typedef vector<LL> VLL;
typedef vector<VLL> VVLL;
typedef unsigned int uint;
typedef unsigned long long ull;
typedef priority_queue<int> maxpq;
typedef priority_queue< int, vector<int>, greater<int> > minpq;
static const double EPS = 1e-10;
static const double PI = acos( -1.0 );
static const int mod = 10007;
static const int INF = 1 << 25;
static const LL LL_INF = 1152921504606846976;
static const int dx[] = { -1, 0, 1, 0,  1, -1,  1, -1 };
static const int dy[] = { 0, -1, 0, 1 , 1,  1, -1, -1 };

int page;
string word;
map<string, VI> mp;

int main() {
	while ( !!( cin >> word >> page ) ) {
		mp[ word ].push_back( page );
	}
	for( map<string, VI>::iterator it = mp.begin(); it != mp.end(); ++it ) {
		printf( "%s\n", it->first.c_str() );
		VI pages = it->second;
		sort( pages.begin(), pages.end() );
		for ( int i = 0; i < pages.size() - 1; i++ ) {
			printf( "%d ", pages[ i ] );
		}
		printf( "%d\n", pages[ pages.size() - 1 ] );
	}
	return 0;
}

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

int main(){
  vector<string>s;
  vector<int>in[100];
  string tmp;
  int num;
  int co=0;  
  while(cin>>tmp>>num){
    int n=-1;
    rep(i,s.size())if(s[i]==tmp)n=i;
    if(n+1){
      in[n].pb(num);
    }else{
      s.pb(tmp);
      in[co].pb(num);
      co++;
    }
  }
  vector<int>order(s.size());
  rep(i,s.size())order[i]=i;
  rep(i,s.size()){
    rep(j,s.size()-i-1){
      if(s[order[j]]>s[order[j+1]]){
	swap(order[j],order[j+1]);
      }
    }
  }
  rep(i,s.size()){
    cout<<s[order[i]]<<endl;
    sort(in[order[i]].begin(),in[order[i]].end());
    cout<<in[order[i]][0];
    rep(j,in[order[i]].size()-1)cout<<" "<<in[order[i]][j+1];
    cout<<endl;
  }
}