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++: // clang-format off
#include <bits/stdc++.h>
#define int long long
#define main signed main()
#define loop(i, a, n) for (int i = (a); i < (n); i++)
#define rep(i, n) loop(i, 0, n)
#define forever for (;;)
#define all(v) (v).begin(), (v).end()
#define rall(v) (v).rbegin(), (v).rend()
#define prec(n) fixed << setprecision(n)
typedef std::pair<int, int> pii;
typedef std::vector<int> vi;
typedef std::vector<double> vd;
typedef std::vector<std::string> vs;
typedef std::vector<pii> vpii;
typedef std::vector<vi> vvi;
typedef std::vector<vpii> vvpii;
const int INF = sizeof(int) == sizeof(long long) ? 1000000000000000000LL : 1000000000;
const int MOD = 1000000007;
const double PI = acos(-1);
template<typename A, typename B> bool cmin(A &a, const B &b) { return a > b ? (a = b, true) : false; }
template<typename A, typename B> bool cmax(A &a, const B &b) { return a < b ? (a = b, true) : false; }
template<typename T> std::istream &operator>>(std::istream &is, std::vector<T> &v) { rep(i,v.size()) is >> v[i]; return is; }
template<typename A, typename B> std::istream &operator>>(std::istream &is, std::pair<A, B> &p) { is >> p.first; is >> p.second; return is; }
using namespace std;
// clang-format on

template<typename InputIterator> std::string join(InputIterator first, InputIterator last, const std::string &sep) {
  if (first == last) return "";
  std::stringstream ss;
  ss << *(first++);
  for_each(first, last, [&](typename InputIterator::value_type &x) { ss << sep << x; });
  return ss.str();
}

main {
  string s;
  int p;
  map<string, vi> m;
  while (cin >> s >> p) m[s].push_back(p);
  for_each(m.begin(), m.end(), [](pair<string, vi> p) {
    cout << p.first << endl;
    sort(all(p.second));
    cout << join(all(p.second), " ") << endl;
  });
}

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

int main(void)
{
	char s[50];
	int a, cnt = 0;
	pair <string, vector <int> > res[128];
	while (scanf("%s %d", s, &a) != EOF){
		bool flag = false;
		for (int i = 0; i < cnt; i++){
			if (res[i].first == s){
				res[i].second.push_back(a);
				flag = true;
				break;
			}
		}
		if (!flag){
			res[cnt].first = s;
			res[cnt].second.push_back(a);
			cnt++;
		}
	}
	sort(res, res + cnt);
	for (int i = 0; i < cnt; i++){
		sort(res[i].second.begin(), res[i].second.end());
	}
	
	for (int i = 0; i < cnt; i++){
		cout << res[i].first << endl;
		for (int j = 0; j < res[i].second.size(); j++){
			cout << res[i].second[j];
			if (j+1 != res[i].second.size()) cout << " ";
			else puts("");
		}
	}
	
	return 0;
}

C++: #include <iostream>
#include <algorithm>
#include <vector>
#include <string>
using namespace std;
struct po{
  string str;
  vector <int> page;
};


int main() {
  
  po ls[1001];
  
  int a=0;
  string ch;
  int b;
  while(cin >>ch>> b){
    int flg = 0;

    for(int i=0;i<a;i++) 
      if(ch == ls[i].str){
	ls[i].page.push_back(b);
	flg = 1;
	break;
      }
    
    if(flg == 1) continue;
    ls[a].str = ch;
    ls[a].page.push_back(b);
    a++;
  }


  for(int i=0;i<a-1;i++) 
    for(int j=a-1;j>i;j--)
      if(ls[j].str < ls[j-1].str) {
	po t = ls[j];
	ls[j] = ls[j-1];
	ls[j-1] = t;
      }

  for(int i=0;i<a;i++) {
    cout << ls[i].str << endl;
      sort(ls[i].page.begin(),ls[i].page.end());
    for(int j=0;j<ls[i].page.size();j++){
      cout << ls[i].page[j];
      if(j != ls[i].page.size()-1) cout <<" ";
    }
    cout << endl;
  }


  return 0;
}

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

using namespace std;

int main(){
	int n;
	string s;
	map<string, vector<int>> m;
	while(cin >> s >> n){
		m[s].push_back(n);
	}
	
	map<string, vector<int>>::iterator it;
	for(it = m.begin(); it != m.end(); it++){
		cout << it->first << endl;
		sort(it->second.begin(), it->second.end());
		for(int i = 0; i < it->second.size(); i++){
			if(i){
				cout << ' ';
			}
			cout << it->second[i];
		}
		cout << endl;
	}
	
	return 0;
}

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

C++: #include<bits/stdc++.h>
using namespace std;
int main(){
	string s;
	string ans = "";
	int in;
	map <string ,vector <int> > mp;
	while(cin >> s >> in){
		mp[s].push_back(in);
	}
	for(auto itr = mp.begin() ; itr != mp.end() ; itr++){
		cout << (*itr).first << endl;
		sort((*itr).second.begin(),(*itr).second.end());
		for(int i = 0; i < (*itr).second.size() ; i++)
			cout << (*itr).second[i] << (i == (*itr).second.size() - 1 ? "" : " ");
		cout << endl;
	}
}