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<string>
using namespace std;

int main() {
	vector<string> words;
	vector<vector<int>> pages;
	string word; int page;
	while(cin>>word>>page) {
		bool is_there = false; int word_place;
		for (int i = 0; i < words.size(); i++) {
			if (word == words[i]) {
				is_there = true;
				word_place = i;
			}
		}
		if (is_there) {
			pages[word_place].push_back(page);
		}
		else {
			words.push_back(word);
			vector<int>* x = new vector<int>;
			pages.push_back(*x);
			pages[pages.size() - 1].push_back(page);
		}
	}
	for (int i = 0; i < words.size() - 1; i++) {
		for (int j = 0; j < words.size() - 1; j++) {
			if (words[j] > words[j + 1]) {
				string tmp_w=words[j];
				words[j] = words[j + 1];
				words[j + 1] = tmp_w;
				vector<int> tmp_p=pages[j];
				pages[j] = pages[j + 1];
				pages[j + 1] = tmp_p;
			}
		}
	}
	for (int i = 0; i < words.size(); i++) {
		for (int j = 0; j < pages[i].size()-1; j++) {
			for (int c = 0; c < pages[i].size()-1; c++) {
				if (pages[i][c] > pages[i][c + 1]) {
					int tmp=pages[i][c];
					pages[i][c] = pages[i][c + 1];
					pages[i][c + 1] = tmp;
					}
			}
		}
	}
	for (int i = 0; i < words.size(); i++) {
		cout << words[i] << endl;
		for (int m = 0; m < pages[i].size(); m++) {
			cout << pages[i][m]<<' ';
		}
		cout << endl;
	}
}

C++: #include<iostream>
#include<string>
#include<cstdio>
#include<algorithm>
#include<stack>
#include<queue>
#include<vector>
#include<cmath>
#include<utility>
#include<set>
#include<complex>
#include<map>
#define vi vector<int>
#define vvi vector<vector<int> >
#define ll long long int
#define vl vector<ll>
#define vvl vector<vector<ll>>
#define vb vector<bool>
#define vc vector<char>
#define vs vector<string>
#define ld long double
#define INF 1e9
#define EPS 0.0000000001
#define rep(i,n) for(int i=0;i<n;i++)
#define loop(i,s,n) for(int i=s;i<n;i++)
#define all(in) in.begin(), in.end()
#define MAX 9999999
using namespace std;
typedef pair<int, int> pii;
typedef pair<double,double>pdd;
typedef pair<ll,ll>pll;
int main(){
    string temp;
    map<string,vi>mp;
    
    while(cin>>temp){
        int n; cin>>n;
        mp[temp].push_back(n);
        sort(all(mp[temp]));
    }
    for(auto itr=mp.begin();itr!=mp.end();itr++){
        cout<<itr->first<<" ";
        rep(i,mp[itr->first].size()){if(i)cout<<" ";cout<<mp[itr->first][i];}
        cout<<endl;
    }
}

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

struct data {
  char id[30];
  int stk[100];
  int sp;
} d[1000];

int main() {
  char id[30];
  int val;
  int i, j, k, dp = 0, f, t;
  struct data tmp;
  while (scanf("%s %d", id, &val) != EOF) {
    f = 0;
    for (i = 0; i < dp; i++) {
      if (strcmp(id, d[i].id) == 0) {
        f = 1;
        break;
      }
    }
    if (f == 1) {
      d[i].stk[d[i].sp++] = val;
    } else {
      strcpy(d[dp].id, id);
      d[dp].stk[d[dp].sp++] = val;
      dp++;
    }
  }
  for (i = 0; i < dp; i++)
    for (j = dp - 1; j > 0; j--)
      if (strcmp(d[j - 1].id, d[j].id) > 0) {
        tmp = d[j - 1];
        d[j - 1] = d[j];
        d[j] = tmp;
      }
  for (i = 0; i < dp; i++) {
    printf("%s\n", d[i].id);
    for (j = 0; j < d[i].sp; j++)
      for (k = d[i].sp - 1; k > 0; k--)
        if (d[i].stk[k - 1] > d[i].stk[k]) {
          t = d[i].stk[k - 1];
          d[i].stk[k - 1] = d[i].stk[k];
          d[i].stk[k] = t;
        }
    for (j = 0; j < d[i].sp; j++)
      printf("%d ", d[i].stk[j]);
    printf("\n");
  }

  return 0;
}

C++: #include <iostream>
#include <string>
#include <map>
#include <vector>
#include <algorithm>
using namespace std;
int main()
{
	string str; int n;
	multimap<string,int> ans;
	while(cin>>str>>n)
		ans.insert(pair<string,int>(str,n));
	multimap<string,int>::iterator p;
	for(p=ans.begin();p!=ans.end(); )
	{
		string tmp= p->first;
		cout << tmp << endl;
		int cnt=0;
		vector<int> v;
		do
		{
			v.push_back(p->second); p++;
		}while(p!=ans.upper_bound(tmp));
		sort(v.begin(),v.end());
		for(int i=0;i<v.size();i++)
		{
			if(i) cout << ' ' ;
			cout << v[i] ;
		}
		cout << endl;
	}
}

C++: #include <iostream>
#include <iomanip>
#include <vector>
#include <map>
#include <algorithm>
#include <string>
#include <sstream>
 
#define INPUT_FROM_FILE (0) 
#if INPUT_FROM_FILE
#include <fstream>
#endif

int main(int argc, char **argv){
	std::string buf;
	int p;
	std::map<std::string, std::vector<int> > map;

#if INPUT_FROM_FILE
	std::ifstream ifs("test.txt");
	std::cin.rdbuf(ifs.rdbuf());
#endif

	while(std::cin >> buf >> p){
		map[buf].push_back(p);
	}

	for(std::map<std::string, std::vector<int> >::const_iterator it = map.begin(); it != map.end(); it++){
		std::vector<int> pages = it->second;
		std::sort(pages.begin(), pages.end());

		std::cout << it->first << std::endl;
		std::cout << pages[0];
		for(int i = 1; i < pages.size(); i++){
			std::cout << " " << pages[i];
		}
		std::cout << std::endl;
	}


#if INPUT_FROM_FILE
		//fclose(fp);
#endif
	return 0;
}

C++: #include <iostream>
#include <vector>
#include <map>
#include <queue>
#include <string>
#include <functional>

using namespace std;

void solve()
{
	map<string, priority_queue<int, vector<int>, greater<int>> > Map;
	string str;
	int page;
	while(cin >> str >> page)
	{
		Map[str].push(page);
	}
	for(map<string, priority_queue<int, vector<int>, greater<int>> >::iterator Ite = Map.begin(); Ite != Map.end(); ++Ite)
	{
		cout << Ite->first << endl;
		bool FirstFlag = true;
		while(!Ite->second.empty())
		{
			if(FirstFlag)
			{
				cout << Ite->second.top();
				FirstFlag = false;
			}
			else
			{
				cout << " " << Ite->second.top();
			}
			Ite->second.pop();
		}
		cout << endl;
	}
}

int main()
{
	solve();
	return(0);
}

C++: #include <bits/stdc++.h>
#define x first
#define y second
using namespace std;pair<string,int> a[100];int main(){int t=0,g,i;while(cin>>a[t].x>>a[t].y)t++;sort(a,a+t);string f,b=a[0].x;cout<<b<<endl<<a[0].y;for(i=1;i<t;i++){bool n=0;f=a[i].x,g=a[i].y;if(f==b)n=1;if(n)cout<<" "<<g;else cout<<endl<<f<<endl<<g;b=f;}cout<<endl;return 0;}

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

class data{
public:
	vector<int> num;
	string s;
};

int main(){
	int n;
	string str;
	vector<data> vec;
	while(cin>>str){
		cin>>n;
		data dt;
		dt.num.push_back(n);
		dt.s=str;
		int cnt=0;
		for(int i=0;i<vec.size();i++){
			if(str==vec[i].s){
				vec[i].num.push_back(n);
				cnt++;
			}
		}
		if(cnt==0)vec.push_back(dt);
	}
	//rep(i,vec.size())cout<<vec[i].s<<" ";
	//cout<<endl;
	//for(int i=0;i<vec.size();i++)cout<<vec[i].s<<" ";
	//cout<<endl;
	for(int i=0;i<vec.size();i++){
		//cout<<i<<endl;
		for(int j=vec.size()-1;j>=1;j--){
			//cout<<j<<" ";
			if(vec[j-1].s>vec[j].s){
				data alt=vec[j];
				vec[j]=vec[j-1];
				vec[j-1]=alt;
			}
			//rep(i,vec.size())cout<<vec[i].s<<" ";
			//cout<<endl;
		}
		//cout<<endl;
	}
	for(int i=0;i<vec.size();i++){
		int volume=vec[i].num.size();
		sort(vec[i].num.begin(),vec[i].num.end());
	}
	for(int i=0;i<vec.size();i++){
		cout<<vec[i].s<<endl;
		cout<<vec[i].num[0];
		for(int j=1;j<vec[i].num.size();j++){
			cout<<" "<<vec[i].num[j];
		}
		cout<<endl;
	}
	return 0;
}