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<string>
#include<algorithm>
using namespace std;
pair<string,int> d[101];
int ptop[101];
int p[101][101];
int main(){
	string a;
	int q,top;
	top=0;
	while(cin>>a>>q){
		bool news=true;
		for(int i=0;i<top;i++){
			if(d[i].first==a){
				p[i][ptop[i]]=q;
				ptop[i]++;
				news=false;
			}
		}
		if(news){
			d[top].first=a;
			d[top].second=top;
			ptop[top]=1;
			p[top][0]=q;
			top++;
		}
	}
	sort(d,d+top);
	for(int i=0;i<top;i++)sort(p[i],p[i]+ptop[i]);
	for(int i=0;i<top;i++){
		cout<<d[i].first<<endl;
		cout<<p[d[i].second][0];
		for(int j=1;j<ptop[d[i].second];j++){
			cout<<" "<<p[d[i].second][j];
		}
		cout<<endl;
	}
	return 0;
}

C++: #define _CRT_SECURE_NO_WARNINGS
#define _USE_MATH_DEFINES

#include <iostream>
#include <algorithm>
#include <functional>
#include <string>
#include <queue>
#include <cmath>
#include <stack>
#include <numeric>
#include <ctime>
#include <algorithm>
#include <set>
#include <map>
#include <stdio.h>

using namespace std;
typedef long long int lint;

int main()
{
	map<string, vector<int> > page;
	set<string> word;

	string str;
	int p;
	while(cin >> str >> p){
		word.insert(str);
		page[str].push_back(p);
	}
	
	set<string>::iterator it = word.begin();
	while(it != word.end()){
		cout << *it;
		sort(page[*it].begin(), page[*it].end());
		for(int i = 0; i < page[*it].size(); i++){
			if(i == 0) cout << endl;
			else cout << " ";
			cout << page[*it][i];
		}
		cout << endl;
		it++;
	}

	return 0;
}

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

using namespace std;

int main(){
	int n;
	string str;	
	map<string, set<int> > m;

	while(cin >> str >> n){
		m[str].insert(n);
	}
	for(auto it = m.begin(); it != m.end(); it++){
		cout << it->first << endl;
		for(auto its =  it->second.begin(); its != it->second.end(); its++){
			cout << *its << " ";
		}
		cout << endl;
	}
}

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

int main()
{
	string s;
	int n;
	map< string, set<int> > index;
	map< string, set<int> >::iterator it;
	set<int>::iterator its;
	while (cin>>s>>n)
		index[s].insert(n);
	for (it = index.begin(); it != index.end(); it++) {
		cout<<(*it).first<<endl;
		for (its = index[(*it).first].begin(); its != index[(*it).first].end(); its++) {
			if (its != index[(*it).first].begin()) cout<<" ";
			cout<<*its;
		}
		cout<<endl;
	}
	return 0;
}

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

using namespace std;

int main()
{
	vector<pair<string, int>> data;

	string str;
	int a;
	while (cin >> str >> a) {
		data.push_back(pair<string, int>(str, a));
    }
	sort(data.begin(), data.end());
	
	pair<string, int> preData;
	for (pair<string, int> e: data) {
		if (preData.first == e.first) {
			cout << " " << e.second;
		} else {
			cout << endl << e.first << endl << e.second;
		}
		preData = e;
	}

    return 0;
}

C++: #include<iostream>
#include<algorithm>
#include<cstdio>
#include<cmath>
#include<math.h>
#include<string>
#include<string.h>
#include<stack>
#include<queue>
#include<vector>
#include<utility>
#include<set>
#include<map>
#include<stdlib.h>
#include<iomanip>

using namespace std;

#define ll long long
#define ld long double
#define EPS 0.0000000001
#define INF 1e9
#define MOD 1000000007
#define rep(i,n) for(i=0;i<n;i++)
#define loop(i,a,n) for(i=a;i<n;i++)
#define all(in) in.begin(),in.end()
#define shosu(x) fixed<<setprecision(x)

typedef vector<int> vi;
typedef pair<int,int> pii;

int main(void) {
  int i,j;
  int n,num=0;
  char s[50]={};
  vector<pair<string,int> > p;
  while(scanf("%s %d",s,&n)!=EOF){
      p.push_back(pair<string,int>(s,n));
      num++;
    }
  sort(all(p));
  cout<<p[0].first<<endl;
  cout<<p[0].second;
  for(i=1;i<num;i++){
    if(p[i].first!=p[i-1].first){
      cout<<endl;
      cout<<p[i].first<<endl;
      cout<<p[i].second;
    }
    else
      cout<<" "<<p[i].second;
  }
  cout<<endl;
}

C++: #include<iostream>
#include<math.h>
#include<string>
#include<vector>
#include<algorithm>
#include<queue>
#include<map>
using namespace std;
#define INF 1<<20

struct edge{
	int to;
	int cost;
	edge() {};
	edge(int a, int b) {
		to = a;
		cost = b;
	}
};

struct Node {
	int pos;
	int cost;
	Node() {};
	Node(int a, int b) {
		pos = a;
		cost = b;
	}
	bool operator <(const Node& rhs) const {
		return cost > rhs.cost;
	}
};

void dijkistra(int st, int TO,int V,vector<vector<edge> > graph) {
	priority_queue<Node> q;
	vector<int> d(V);
	for (int i = 0;i < V;i++) {
		d[i] = INF;
	}
	d[st] = 0;
	q.push(Node(st, 0));
	while (!q.empty()) {
		Node s = q.top(); q.pop();
		int pos = s.pos;
		for (int i = 0;i < graph[pos].size();i++) {
			int to = graph[pos][i].to;
			int cost = graph[pos][i].cost;
			if (d[pos] + cost < d[to]) {
				d[to] = d[pos] + cost;
				q.push(Node(to, d[to]));
			}

		}
	}
	cout << d[TO] << endl;
}
int partition(int A[],int p, int r) {
	int x = A[r];
	int i = p - 1;
	for (int j = p;j < r;j++) {
		if (x >= A[j]) {
			i = i + 1;
			swap(A[i], A[j]);
		}
	}
		swap(A[i + 1], A[r]);
		return i + 1;
}
void quicksort(int A[], int p, int r) {
	if (p < r) {
		int q = partition(A, p, r);
		quicksort(A, p, q-1);
		quicksort(A, q + 1, r);
	}
}

int getNumberOfCoin(int C[],int n,int m) {
	int T[50000];
	for (int j = 0;j <= n;j++) {
		T[j] = INF;
	}
	T[0] = 0;
	for (int i = 0;i < m;i++) {
		for (int j = 0;j <= n;j++) {
			if (j - C[i] >=0  ) {
				T[j] = min(T[j], T[j - C[i]] + 1);
			}
		}
	}
	return T[n];
}
int knapsack(int w, int n,int* v,int* ww) {
	int W[101][10001];
		for (int j = 0;j <= w;j++) {
			W[0][j] = 0;
		}
	for (int i = 0;i < n;i++) {
		for (int k = 0;k < n;k++){
			for (int j = 0;j <= w;j++) {
				if (j - ww[k] < 0) {
					W[i + 1][j] = W[i][j];
				}
				if (j - ww[i] >= 0) {
					W[i + 1][j] = max(W[i][j], W[i][j - ww[k]] + v[k]);

				}
			}
		}
	}
	return W[n][w];
}
int fib(int n) {
	vector<int> v(n+1);
	v[0] = 1;
	v[1] = 1;
	for (int i = 2;i < n+1;i++) {
		v[i] = v[i - 2] + v[i - 1];
	}
	return v[n];
}
int main(){
	map<string, vector<int> > dic;
	string voc;
	int page;
	while (cin >> voc >> page) {
		dic[voc].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 (int i = 0;i < (*it).second.size();i++) {
			cout << (*it).second[i] << " ";
		}
		cout << endl;
		it++;
	}
	
}

int isPrime(int x) {
	if (x <= 1) return false;
	if (x>2 && x % 2 == 0) return false;
	for (int i = 2;i <= sqrt(x);i++) {
		if (x%i == 0) {
			return false;
		}
	}
	if (x == 2) return true;
	return true;
}

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

int main() {
  string s;
  int p;
  map<string,set<int> > m;
  while(cin >> s >> p) {
    m[s].insert(p);
  }
  for(map<string,set<int> >::iterator i = m.begin();
      i != m.end(); ++i) {
    cout << i->first << endl;
    bool first = true;
    for(set<int>::iterator j = i->second.begin();
        j != i->second.end(); ++j) {
      if(first) first = false;
      else cout << " ";
      cout << *j;
    }
    cout << endl;
  }
  return 0;
}