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 <vector>
#include <algorithm>
#include <string>
#include <cmath>
#include <map>

using namespace std;

typedef vector<int> vi;
typedef vector<vi> vii;
typedef vector<string> vs;
typedef vector<bool> vb;
typedef vector<vb> vbb;
typedef pair<int, int> pii;
typedef long long ll;
typedef unsigned long long ull;

#define all(a)  (a).begin(),(a).end()
#define rall(a) (a).rbegin(), (a).rend()
#define pb push_back
#define mp make_pair

#define loop(i,a,b) for(int i=(a);i<ull(b);++i)
#define rep(i,n) loop(i,0,n)

const double eps = 1e-10;
const double pi  = acos(-1.0);
const double inf = (int)1e8;

int main(){
    map<string, vector<int> > m;
    string str; int n;
    while(cin >> str >> n){
        m[str].pb(n);
    }
    map<string, vector<int> >::iterator it = m.begin();
    for(; it != m.end(); it++){
        sort(all((*it).second));
        cout << (*it).first << endl;
        rep(i, (*it).second.size()) cout << (i?" ":"") << (*it).second[i];
        cout << endl;
    }
}

C++: #include <iostream>
#include <string>
#include <algorithm>
using namespace std;
class data{
public:
  string words;  
  int page;
  bool operator < (const data&s)const{
    if(words < s.words) return true;
    else if(words > s.words) return false;
    else{
      if(page < s.page) return true;
      else return false;
    }
  }
};
int main(){
  int i=0;
  data in[1000];
  while(cin >> in[i].words){
    cin >> in[i].page;
    i++;
  }
  
  sort(in,in+i);

  cout << in[0].words << endl << in[0].page;
  for(int j=1;j<i;j++){
    if(in[j-1].words != in[j].words){
      cout << endl;
      cout << in[j].words << endl << in[j].page;
    }
    else{
      cout << ' ' << in[j].page;
    }
  }
  cout << endl;
  return 0;
}

C++: #include <iostream>
#include <cstring>
#include <cstdlib>
using namespace std;

struct dic{
	string s;
	int page[1001];
};

int comp(const void *a, const void *b){
if(((dic*)a)->s > ((dic*)b)->s) return 1;
else return -1;
}

int main(void){
	int i,j,p,tail=0;
	string str;
	dic d[100];
	memset(d, 0, sizeof(d));
	while((cin >> str) != NULL){
		for(i=0;i<tail;i++){
			if(str == d[i].s){
				cin >> p;
				d[i].page[p]=1;
				break;
			}
		}
		if(i == tail){
			d[tail].s = str;
			cin >> p;
			d[tail].page[p]=1;
			tail++;
		}
	}

	qsort(&d,tail,sizeof(dic),comp);
	int f=0;
	for(i=0;i<tail;i++){
		f=0;
		cout << d[i].s << endl;
		for(j=0;j<1001;j++){
			if(d[i].page[j] == 1){
				if(f) cout << " " << j;
				else{ cout << j; f++;}
			}
		}
		cout << endl;
	}
	return 0;
}

C++: style 12
even 25
introduction 3
easy 9
style 7
document 13
style 21
even 18

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

class tWord{
public:
	string word;
	vector<int> page;
	tWord( string w );
	bool operator <( const tWord& r ){
		return (strcmp(word.c_str(), r.word.c_str())<0);
	}
};
tWord::tWord( string w ){
	word = w;
	page.clear();
}

int main(){
	vector<tWord> words;
	string line;
	int n;
	char w[31];

	// input
	while(1){
		getline( cin, line );
		if( line.size()==0 ) break;
		sscanf(line.c_str(), "%s %d", w, &n);
		int i;
		for( i=0; i<words.size(); i++ ){
			if( words[i].word == w ){
				break;
			}
		}
		if( i == words.size() ){
			string ww = w;
			words.push_back(ww);
		}
		words[i].page.push_back(n);
	}

	// output
	sort( words.begin(), words.end() );
	for( int i=0; i<words.size(); i++ ){
		if( words[i].word != "" ){
			cout << words[i].word << endl;
			sort( words[i].page.begin(), words[i].page.end() );
			cout << words[i].page[0];
			for( int j=1; j<words[i].page.size(); j++ ){
				cout << " " << words[i].page[j];
			}
			cout << endl;
		}
	}
	return 0;
}

C++: #include <bits/stdc++.h>
using namespace std;
#define REP(i,n) for(int i=0; i<(n); i++)
#define REP2(i,x,n) for(int i=x; i<(n); i++) 
#define ALL(n) begin(n),end(n)
struct cww{cww(){ios::sync_with_stdio(false);cin.tie(0);}}star;
int main()
{
	string S;
	int N;
	multimap<int, string> mp;
	while( cin >> S >> N )
	{
		mp.emplace( make_pair( N, S ) );
	}
	multimap<string, int> mp2;
	for( auto &x: mp ){
		mp2.emplace( make_pair( x.second, x.first ) );
	}
	string tmp;
	for( auto x : mp2 )
	{
		if( x.first == tmp )cout << " ";
		if( x.first != tmp )
		{
			if( !tmp.empty() )
			{
				cout << endl;
			}
			tmp = x.first;
			cout << x.first << endl;
		}
		cout << x.second;
	}
	cout << endl;
	return 0;
}

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

using namespace std;


int main() {

  string word;
  int page;

  map<string, set<int> > index;
  

  index.clear();

  while(cin >> word >> page) {

    index[word].insert(page);
    /*
     for(map<string, set<int> >::iterator it=index.begin();it!=index.end();it++) {

      cout << (*it).first << endl;

      for(set<int>::iterator it2=(*it).second.begin();it2!=(*it).second.end();it2++) {

	if(it2==(*it).second.begin()) cout << *it2;

	else cout << " " << *it2;

      }
      
      cout << endl;
    
      }
    */
  }

  for(map<string, set<int> >::iterator it=index.begin();it!=index.end();it++) {

      cout << (*it).first << endl;

      for(set<int>::iterator it2=(*it).second.begin();it2!=(*it).second.end();it2++) {

	if(it2==(*it).second.begin()) cout << *it2;

	else cout << " " << *it2;

      }
      
      cout << endl;

  }

  return 0;

}

C++: #include <map>
#include <string>
#include <iostream>
#include <algorithm>
using namespace std;
string S[100], T[100]; int val, cnt, size_;
map<string, vector<int> > M;
int main() {
	while(cin >> S[cnt++]) {
		scanf("%d", &val);
		M[S[cnt - 1]].push_back(val);
	}
	sort(S, S + cnt);
	T[size_++] = S[0];
	for(int i = 1; i < cnt; i++) {
		if(S[i - 1] != S[i]) {
			T[size_++] = S[i];
		}
	}
	for(int i = 0; i < size_; i++) {
		printf("%s\n", T[i].c_str());
		sort(M[T[i]].begin(), M[T[i]].end());
		for(int j = 0; j < M[T[i]].size(); j++) {
			if(j) printf(" ");
			printf("%d", M[T[i]][j]);
		}
		printf("\n");
	}
	return 0;
}

C++: #include<stdio.h>
#include<string>
#include<stdlib.h>
#include<math.h>
#include<iostream>
#include<vector>
#include<algorithm>
#include<numeric>
#include<string.h>
#include<map>

using namespace std;

typedef pair<int,int> pii;

#define rep(i,j) for(int i=0;i<(j);i++)
#define reps(i,j,k) for(int i=j;i<=k;i++)


int main(){
	map<string,vector<int> > m;
	string s;
	vector<string> v;
	char c[1000];
	int n;
	while(~scanf("%s%d",c,&n)){
		s=string(c);
		if(m[s].size()==0)v.push_back(s);
		m[s].push_back(n);
	}
	sort(v.begin(),v.end());
	rep(i,v.size()){
		cout << v[i] << endl;
		int l=m[v[i]].size();
		sort(m[v[i]].begin(),m[v[i]].end());
		rep(j,l)
			printf("%d%c",m[v[i]][j],j==l-1?'\n':' ');
	}
	return 0;
}