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 <cstdio>
#include <iostream>
#include <vector>
#include <map>
#include <algorithm>
using namespace std;

int main()
{
  map<string, vector<int> > dic;
  vector<string> bin;
  string input;
  int n;

  while (cin >> input >> n){
    if (dic.find(input) == dic.end()){
      bin.push_back(input);
    }
    dic[input].push_back(n);
  }

  sort(bin.begin(), bin.end());
  for (int i = 0; i < bin.size(); i++){
    sort(dic[bin[i]].begin(), dic[bin[i]].end());
    cout << bin[i] << '\n';
    for (int j = 0; j < dic[bin[i]].size() - 1; j++){
      cout << dic[bin[i]][j] << " ";
    }
    cout << dic[bin[i]][dic[bin[i]].size() - 1] << '\n';
  }

  return (0);
}

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

struct data{
	string s;
	vector<int> vi;
};

bool comp(data d1, data d2){
	return d1.s < d2.s;
}

int main(){
	int n;
	vector<data> vd;
	string s;
	while(cin >> s >> n){
		int i = 0;
		while(i < vd.size() && vd[i].s != s) i++;
		if(i == vd.size()){
			data d;
			d.s = s;
			vd.push_back(d);
		}	
		vd[i].vi.push_back(n);
		sort(vd[i].vi.begin(), vd[i].vi.end());
	}
	sort(vd.begin(), vd.end(), comp);
	for(int i = 0; i < vd.size(); i++){
		cout << vd[i].s << endl;
		for(int j = 0; j < vd[i].vi.size(); j++){
			if(j != 0) cout << " ";
			cout << vd[i].vi[j];
		}
		cout << endl;
	}
	return 0;
}

C++: //include
//------------------------------------------
#include <vector>
#include <list>
#include <map>
#include <set>
#include <deque>
#include <stack>
#include <bitset>
#include <algorithm>
#include <functional>
#include <numeric>
#include <utility>
#include <sstream>
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <cctype>
#include <string>
#include <cstring>
#include <ctime>
#include <fstream>
using namespace std;

//conversion
//------------------------------------------
inline int toInt(string s) {int v; istringstream sin(s);sin>>v;return v;}
template<class T> inline string toString(T x) {ostringstream sout;sout<<x;return sout.str();}

//math
//-------------------------------------------
template<class T> inline T sqr(T x) {return x*x;}

//typedef
//------------------------------------------
typedef vector<int> VI;
typedef vector<VI> VVI;
typedef vector<string> VS;
typedef pair<int, int> PII;
typedef pair<long, long> PLL;
typedef long long LL;
//container util
//------------------------------------------
#define ALL(a)  (a).begin(),(a).end()
#define RALL(a) (a).rbegin(), (a).rend()
#define PB push_back
#define MP make_pair
#define SZ(a) int((a).size())
#define EACH(i,c) for(typeof((c).begin()) i=(c).begin(); i!=(c).end(); ++i)
#define EXIST(s,e) ((s).find(e)!=(s).end())
#define SORT(c) sort((c).begin(),(c).end())

//repetition
//------------------------------------------
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n)  FOR(i,0,n)

//constant
//--------------------------------------------
const double EPS = 1e-10;
const double PI  = acos(-1.0);

//clear memory
#define CLR(a) memset((a), 0 ,sizeof(a))




int main(){
	string str;
	vector< pair<string,int> >sp;
	int num;
	while(cin>>str>>num){
		sp.PB(MP(str,num));
	}
	bool c=false;
	SORT(sp);
	REP(i,SZ(sp)){
		if(!c)cout<<sp[i].first<<endl;
		if(i!=SZ(sp)-1&&sp[i].first==sp[i+1].first){
			cout<<sp[i].second<<" ";
			c=true;
		}else{
			c=false;
			cout<<sp[i].second<<endl;
		}
		
	}
	return 0;
}

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;
    for(set<int>::iterator j = i->second.begin();
        j != i->second.end(); ++j) {
      cout << " " << *j;
    }
    cout << endl;
  }
  return 0;
}

C++: #include <map>
#include <cstdio>
#include <queue>
#include <iostream>
#include <string>
using namespace std;
typedef priority_queue< int,vector<int>,greater<int> > myqueue;

int main()
{
	myqueue que;
	map< string,myqueue > index;
	map< string,myqueue >::iterator it;
	int paz;
	char in[1001];
	string word;

	while( scanf("%s %d",in,&paz) != EOF ){
		word.append(in);
		
		if( index.find(word) == index.end() ){
			que.push(paz);
			index.insert( make_pair(word,que) );
			que.pop();
		}
		
		else{
			index[word].push(paz);
		}

		word.erase( word.begin(),word.end() );
	}

	for(it = index.begin(); it != index.end(); it++){
		cout << it->first << endl;
		while( !it->second.empty() ){
			printf("%d",it->second.top());
			it->second.pop();
			if(it->second.empty()){
				printf("\n");
			}
			else{
				printf(" ");
			}
		}
	}

	return 0;
}

C++: #include <cstdio>
#include <cstring>
#include <cstdlib>
#include <cmath>
#include <complex>
#include <string>
#include <sstream>
#include <algorithm>
#include <vector>
#include <queue>
#include <stack>
#include <functional>
#include <iostream>
#include <map>
#include <set>
using namespace std;
typedef pair<int,int> P;
#define pu push
#define pb push_back
#define mp make_pair
#define eps 1e-7
#define INF 20000000
map<string,vector<int> > book;
int main()
{
        string s;
        int page;
        while(cin >> s >> page)
        {
                book[s].pb(page);
        }
        for(map<string,vector<int> >::iterator it=book.begin();it!=book.end();it++)
        {
                sort(it->second.begin(),it->second.end());
                cout << it->first << endl;
                for(int i=0;i<(it->second.size());i++)
                {
                        cout << it->second[i];
                        if(i==((it->second.size())-1))
                        {
                                cout << endl;
                        }
                        else
                        {
                                cout << ' ';
                        }
                }
        }
        return 0;
}

C++: int main(){
  std::string s;
  int p;
  std::map<std::string,std::vector<int> > m;
  while(std::cin>>s>>p,p!=0){
    m[s].push_back(p);
  }
  std::map<std::string,std::vector<int> >::iterator m_it = m.begin();
  while(m_it!=m.end()){
    std::cout<<(*m_it).first<<std::endl;
    std::vector<int> v = (*m_it).second;
    std::sort(v.begin(),v.end());
    std::vector<int>::iterator v_it = v.begin();
    while(v_it!=v.end()){
      std::cout<<*v_it;
      v_it++;
      (v_it==v.end())?std::cout<<std::endl:std::cout<<" ";
    }
    m_it++;
  }
  return 0;
}

C++: #include <bits/stdc++.h>
using namespace std;

#define out cout 
#define in cin
#define el endl

#define rep(i, N) for (int i = 0; i < N; i++)
#define ol(N) cout << N << endl

int main()
{
	int a, c = 0;
	string s;
	map<string, vector<int>> m;

	while (in >> s >> a){
		m[s].push_back(a);
	}
	for (auto chie : m) {
		cout << chie.first << '\n';
		sort(chie.second.begin(), chie.second.end());
		rep(i, chie.second.size() - 1) {
			cout << chie.second[i] << " ";
		}
		cout << chie.second[chie.second.size() - 1] << '\n';
	}

	return (0);
}