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<iostream>
#include<string>
#include<algorithm>
using namespace std;
string tn[1000];
int tp[1000][1000],tt[1000];
int main(){
	string a;
	int b,top=0;
	while(cin>>a>>b){
		bool t=true;
		for(int i=0;i<top;i++){
			if(tn[i]==a){
				t=false;
				tp[i][tt[i]]=b;
				tt[i]++;
			}
		}
		if(t==true){
			tn[top]=a;
			tp[top][0]=b;
			tt[top]=1;
			top++;
		}
	}
	for(int i=0;i<top-1;i++){
			for(int j=top-1;j>i;j--){
				bool w=true;
				int k=0;
				while(true){
					if(tn[j][k]>tn[j-1][k])
						break;
					if(tn[j][k]<tn[j-1][k]){
						w=false;
						break;
					}
					k++;
					if(k==tn[j].size())
						break;
					if(k==tn[j-1].size()){
						w=false;
						break;
					}
				}
				if(w==false){
					string tmps=tn[j];
					tn[j]=tn[j-1];
					tn[j-1]=tmps;
					int tmph[100];
					for(int k=0;k<tt[j];k++)
						tmph[k]=tp[j][k];
					for(int k=0;k<tt[j-1];k++)
						tp[j][k]=tp[j-1][k];
					for(int k=0;k<tt[j];k++)
						tp[j-1][k]=tmph[k];
					int tmp=tt[j];
					tt[j]=tt[j-1];
					tt[j-1]=tmp;
				}
			}
		}
		for(int i=0;i<top;i++)
			sort(tp[i],tp[i]+tt[i]);
		for(int i=0;i<top;i++){
			cout<<tn[i]<<endl;
			cout<<tp[i][0];
			for(int j=1;j<tt[i];j++)
				cout<<" "<<tp[i][j];
			cout<<endl;
		}
	return 0;
}

C++: l

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;
		}
	}
	cout<<endl;
}

C++: #include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <ctime>
#include <cassert>
#include <iostream>
#include <cctype>
#include <sstream>
#include <string>
#include <list>
#include <vector>
#include <queue>
#include <set>
#include <stack>
#include <map>
#include <utility>
#include <numeric>
#include <algorithm>
#include <iterator>
#include <bitset>
#include <complex>
#include <fstream>
#include <iomanip>
using namespace std;
typedef long long ll;
const double EPS = 1e-9;
typedef vector<int> vint;
typedef pair<int, int> pint;
#define rep(i, n) REP(i, 0, n)
#define ALL(v) v.begin(), v.end()
#define MSG(a) cout << #a << " " << a << endl;
#define REP(i, x, n) for(int i = x; i < n; i++)
template<class T, class C> void chmax(T& a, C b){ if(a < b) a = b; }
template<class T, class C> void chmin(T& a, C b){ if(b < a) a = b; }
template<class T, class C> pair<T, C> mp(T a, C b){ return make_pair(a, b); }

int main()
{
	string str;
	int num;

	map<string, set<int> > dic;
	
	while(cin >> str >> num)
		dic[str].insert(num);

	for(map<string, set<int> >::iterator it = dic.begin(); it != dic.end(); it++)
	{
		cout << it->first << endl;
		for(set<int>::iterator itt = it->second.begin(); itt != it->second.end(); itt++)
			cout << (itt != it->second.begin() ? " " : "") << (*itt);
		cout << endl;
	}
}

C++: #include<iostream>
#include<sstream>
#include<algorithm>
#include<climits>
#include<cmath>
#include<cstdio>
#include<cstdlib>
#include<ctime>
#include<cfloat>
#include<functional>
#include<map>
#include<string>
#include<cstring>
#include<vector>
#include<queue>
#include<stack>
#include<deque>
#include<set>
#include<bitset>
#include<list>
#include<numeric>
#include<complex>

using namespace std;

typedef long long ll;
typedef unsigned long long ull;
typedef pair<int, int> i_i;
typedef pair<long long, int> ll_i;
typedef pair<double, int> d_i;
typedef pair<long long, long long> ll_ll;
typedef pair<double, double> d_d;

#define PI 3.141592653589793238462643383279
#define mod 1000000007LL
#define rep(i, n) for(i = 0;i < n;++i)
#define rep1(i, n) for(i = 1;i < n;++i)
#define rep2d(i, j, n) for(i = 0;i < n;++i)for(j = i + 1;j < n;++j)
#define per(i, n) for(i = n - 1;i > -1;--i)
#define int(x) int x; scanf("%d",&x)
#define int2(x, y) int x, y; scanf("%d%d",&x, &y)
#define int3(x, y, z) int x, y, z; scanf("%d%d%d",&x, &y, &z)
#define scn(n, a) rep(i, n)cin >> a[i]
#define sc2n(n, a, b) rep(i, n)cin >> a[i] >> b[i]
#define pri(x) cout << x << "\n"
#define pri2(x, y) cout << x << " " << y << "\n"
#define pri3(x, y, z) cout << x << " " << y << " " << z << "\n"
#define pb push_back
#define mp make_pair
#define all(a) (a).begin(),(a).end()
#define endl "\n"
#define kabe puts("---------------------------")
#define kara puts("")
#define debug(x) cout << " --- " << x << "\n"
#define debug2(x, y) cout << " --- " << x << " " << y << "\n"
#define debug3(x, y, z) cout << " --- " << x << " " << y << " " << z << "\n"
#define X first
#define Y second
#define eps 0.0001
#define prid(x) printf("%.15lf\n", x)

struct wrd{
  string s;
  vector<int> pp;
  void prnt(void){
    cout << s << endl;
    sort(all(pp));
    printf("%d", pp[0]);
    for(int i = 1;i < pp.size();++i)printf(" %d", pp[i]);
    kara;
    return;
  }
};

bool cmp(wrd a, wrd b){
  for(int i = 0;i < min(a.s.size(), b.s.size());++i)if(a.s[i] != b.s[i])
    return a.s[i] < b.s[i];
  return a.s.size() < b.s.size();
}

signed main(void){
  int i, j, k;
  for(int testcase = 0;testcase < 1234567;testcase++){
    vector<wrd> lis;
    string tmp;
    for(;getline(cin, tmp);){
      for(i = 0;i < tmp.size();++i)if(tmp[i] == ' ')break;
      string t = tmp.substr(0, i);

      i++;
      int res = 0;
      for(;i < tmp.size();++i)res = res * 10 + (int)(tmp[i] - '0');

      rep(i, lis.size())if(lis[i].s == t)break;
      if(i != lis.size())lis[i].pp.pb(res);
      else{
        vector<int> qwe;
        qwe.pb(res);
        lis.pb((wrd){t, qwe});
      }
    }

    sort(all(lis), cmp);
    rep(i, lis.size())lis[i].prnt();

/*/

//*/ break;
  }
  return 0;
}

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


class S {
public:
  set<int> s;
};

int main() {
  map<string, S> data;
  set<string> word;
  string str;
  int page;
  while(cin >> str >> page) {
    word.insert(str);
    data[str].s.insert(page);
  }
  set<string>::iterator it = word.begin();
  while(it != word.end()) {
    cout << *it << endl;
    set<int>::iterator it2 = data[*it].s.begin();
    bool first = true;
    while(it2 != data[*it].s.end()) {
      if(first) first = false;
      else      cout << ' ';
      cout << *it2;
      it2++;
    }
    cout << endl;
    it++;
  }
  return 0;
}