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++: #define _USE_MATH_DEFINES
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <climits>
#include <cfloat>
#include <ctime>
#include <cassert>
#include <map>
#include <utility>
#include <set>
#include <iostream>
#include <memory>
#include <string>
#include <vector>
#include <algorithm>
#include <functional>
#include <sstream>
#include <complex>
#include <stack>
#include <queue>
#include <numeric>
#include <list>
#include <iomanip>
#include <iterator>

using namespace std;

typedef long long ll;
typedef pair<int,int> Pii;
typedef pair<ll,ll> Pll;
 
int main(){
	string s;
	int x;
	map<string,vector<int> > mp;
	while(cin>>s>>x)
		mp[s].push_back(x);
	typedef vector<pair<string,vector<int> > > P;
	P vp(mp.begin(),mp.end());
	sort(vp.begin(),vp.end());

	for(P::iterator it = vp.begin(); it != vp.end(); ++it){
		sort((*it).second.begin(),(*it).second.end());
		cout << (*it).first << endl;
		vector<int> &v = (*it).second;
		for(int i = 0; i < (int)v.size(); i++){
			printf("%d%c",v[i],i==(int)v.size()-1?'\n':' ');
		}
	}

    return 0;
}

C++: #include<iostream>
#include<vector>
#include<string>
#include<algorithm>
using namespace std;
int main() {
	string a;
	int b;
	string c[100];
	int d[100][1000];
	int g[100];
	for (int i = 0; i < 100; i++) {
		g[i] = 0;
	}
	int e = 0;
	while (cin >> a >> b) {
		int f;
		bool h = false;
		for (int i = 0; i < e; i++) {
			if (c[i] == a) {
				f = i;
				h = true;
				goto stop;
			}
		}
		c[e] = a;
		d[e][g[e]] = b;
		g[e]++;
		e++;
		stop:;
		if (h) {
			d[f][g[f]] = b;
			g[f]++;
		}
	}
	for (int i = 0; i < e; i++) {
		sort(d[i], d[i] + g[i]);
	}
	for (int i = 0; i < e; i++) {
		cout << c[i] << endl;
		for (int j = 0; j < g[i]; j++) {
			if (j == 0)
				cout << d[i][j];
			else
				cout << " " + d[i][j];
		}
		cout << endl;
	}
}

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

using namespace std;

int main() {
  string str;
  int page;
  vector<pair<string, int>> vec;

  while (cin >> str >> page)
    vec.push_back(make_pair(str, page));

  sort(vec.begin(), vec.end(), [](auto &a, auto &b) {
    return (a.first != b.first) ? a.first < b.first : a.second < b.second;
  });

  string last = "";
  for (auto &v : vec) {
    if (last == v.first) {
      cout << " " << v.second;
   } else {
      if (last != "")
        cout << endl;
      cout << v.first << endl << v.second;
    }
    last = v.first;
  }
  cout << endl;
}

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

using namespace std;

int main(void){
    set<string> words;
    map<string,priority_queue<int, vector<int>,greater<int> > > indeces;
    char wd[32];
    int page;
    
    while (cin >> wd >> page){
        string strWd(wd);
        
        words.insert(strWd);
        if (indeces.find(strWd) == indeces.end()){
            priority_queue<int,vector<int>, greater<int> > pq;
            indeces.insert(make_pair(strWd, pq));
        }
        indeces[strWd].push(page);
    }
    for (set<string>::iterator itr = words.begin(); itr != words.end(); itr++){
        string wd = *itr;
        cout << wd << endl;
        cout << indeces[wd].top();
        indeces[wd].pop();
        while (!indeces[wd].empty()){
            cout << " " << indeces[wd].top();
            indeces[wd].pop();
        }
        cout << endl;
    }
  
    return 0;
}

C++: //#define _GRIBCXX_DEBUG
#include <algorithm>
#include <cctype>
#include <climits>
#include <cmath>
#include <complex>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>
#include <deque>
#include <functional>
#include <iostream>
#include <iomanip>
#include <list>
#include <map>
#include <memory>
#include <numeric>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <utility>
#include <vector>
using namespace std;


// ?????¬???????????¬??????
#pragma region MACRO
#define P(x) cout << (x) << endl
#define p(x) cout << (x)
#define PED cout << "\n"
#define rep(i,n) for(int i=0; i<(int)n; ++i)
#define REP(i,x,n) for(int i=x; i<(int)n; ++i)
#define repi(i,n) for(int i=0; i<=(int)n; ++i)
#define REPI(i,x,n) for(int i=x; i<=(int)n; ++i)
#define ILP while(true)
#define FOR(i,c) for(__typeof((c).begin())!=(c).begin(); i!=(c).end(); ++i)
#define ALL(c) (c).begin(), (c).end()
#define mp make_pair
#pragma endregion

// ???
#pragma region TYPE_DEF
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<string, string> pss;
typedef pair<string, int> psi;
typedef pair<int, string> pis;
typedef vector<int> vi;
typedef vector<double> vd;
typedef vector<long> vl;
typedef vector<long long> vll;
typedef vector<string> vs;
#pragma endregion

// Effective std
#pragma region ESTD
template<typename C, typename T>
constexpr int count(C& c, T t) { return count(ALL(c), t); }
template<typename C, typename F>
constexpr int count_if(C& c, F f) { return count_if(ALL(c), f); }
template<typename C, typename T>
void erase(C& c, T t) { remove(ALL(c), t), c.end(); }
template<typename C>
void remove(vector<C>& c, unsigned int index) { c.erase(c.begin()+index); }
template<typename C, typename T, typename U>
constexpr void replace(C& c, T t, U u) { replace(ALL(c), t, u); }
template<typename C, typename F, typename U>
constexpr void replace_if(C& c, F f, U u) { (ALL(c), f, u); }
template<typename C>
constexpr void reverse(C& c) { reverse(ALL(c)); }
template<typename C>
constexpr void sort(C& c) { sort(ALL(c)); }
template<typename C, typename Pred>
constexpr void sort(C& c, Pred p) { sort(ALL(c), p); }
#pragma endregion

// ?????°
#pragma region CONST_VAL
#define PI (2*acos(0.0))
#define EPS (1e-9)
#define MOD (int)(1e9+7)
#pragma endregion


int main()
{
    map< string, vi > index;
    string sbuf;
    int ibuf;
    while(cin>>sbuf>>ibuf) index[sbuf].push_back(ibuf);
    for(auto &el : index) {
        sort(el.second);
        P(el.first);
        for(auto vel : el.second) {
            cout << vel;
            if(vel != *(el.second.end()-1)) cout << " ";
        }
        PED;
    }
    return 0;
}

C++: #define _USE_MATH_DEFINES
#include "bits/stdc++.h"
using namespace std;

//#define int long long
#define DBG 1
#define dump(o) if(DBG){cerr<<#o<<" "<<o<<endl;}
#define dumpc(o) if(DBG){cerr<<#o; for(auto &e:(o))cerr<<" "<<e;cerr<<endl;}
#define rep(i,a,b) for(int i=(a);i<(b);i++)
#define rrep(i,a,b) for(int i=(b)-1;i>=(a);i--)
#define each(it,c) for(auto it=(c).begin();it!=(c).end();it++)
#define all(c) c.begin(),c.end()
const int INF = sizeof(int) == sizeof(long long) ? 0x3f3f3f3f3f3f3f3fLL : 0x3f3f3f3f;
const int MOD = (int)(1e9 + 7);

signed main() {
	map<string, vector<int>>M;
	string s; int n;
	while (cin >> s >> n) {
		M[s].push_back(n);
	}
	each(it, M) {
		cout << it->first << endl;
		sort(it->second.begin(), it->second.end());
		int i(0);
		each(that, it->second) {
			if (i)cout << " ";
			cout << *that;
		}
		cout << endl;
	}
	return 0;
}