Problem:
Book Index

Books are indexed. Write a program which reads a list of pairs of a word and a page number, and prints the word and a list of the corresponding page numbers.

You can assume that a word consists of at most 30 characters, and the page number is less than or equal to 1000. The number of pairs of a word and a page number is less than or equal to 100. A word never appear in a page more than once.

The words should be printed in alphabetical order and the page numbers should be printed in ascending order.

Input

word page_number
:
:

Output

word
a_list_of_the_page_number
word
a_list_of_the_Page_number
:
:

Sample Input

style 12
even 25
introduction 3
easy 9
style 7
document 13
style 21
even 18

Output for the Sample Input

document
13
easy
9
even
18 25
introduction
3
style
7 12 21

Solution in JavaScript (judge verdict: Accepted)

var print = console.log; // like python
var input_lines; // ?¨??????\????????????????????????????????????

function PreMain(input) {
    input_lines = input.split("\n");
    var f = function () {
        return input_lines.shift();
    };
    Main(f);
}

function IL(min1Flg) {
    var s = input_lines.shift().split(' ');
    var offset = min1Flg ? -1 : 0;
    var res = [];
    for (var i = 0; i < s.length; i++) {
        res.push(parseInt(s[i]));
    }
    return res;
}

/**
 * @return {number}
 */
Array.prototype.SUM = function SUM() {
    var sum = 0;
    this.forEach(function (elm) {
        sum += elm;
    });
    return sum;
};

/**
 * @return {string}
 */
Array.prototype.Format = function Format(split) {
    if (split === undefined) {
        split = " ";
    }
    return this.join(split);
};

Array.prototype.Copy = function Copy() {
    return [].concat(this);
};

/***
 * ??????Sort
 * <Array>.sort?????¨???(?????????)???????????????????????¨????????¨???
 * ??°????????????????????§?????°????????????????????????????????´??????????????????????????¨?????????
 * @constructor
 */
Array.prototype.Sort = function Sort() {
    this.sort(function (a, b) {
        if (a < b) return -1;
        if (a > b) return 1;
        return 0;
    });
    return this;
};

/*

(((???????????)??? ?????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????

*/
function item_getter_key(x, desc, func_when_eq) {
    var sign = 1;
    if (desc) {
        sign = -1;
    }
    return function (a, b) {
        if (a[x] < b[x]) return -1 * sign;
        else if (a[x] > b[x]) return sign;

        if (func_when_eq === undefined) {
            return 0;
        } else {
            return func_when_eq(a, b);
        }
    };
}


function Main(input) {
    var lst = [];
    for (var i = 0; i < input_lines.length; i++) {
        var x = input_lines[i].split(' ');
        if(x.length<=1){continue;}
        var flg = false;
        lst.forEach(function (v) {
            if (v[0] === x[0]) {
                v[1].push(parseInt(x[1]));
                flg = true;
            }
        });
        if (!flg) {
            lst.push([x[0], [parseInt(x[1])]]);
        }
    }

    lst.sort(item_getter_key(0));
    for (var i = 0; i < lst.length; i++) {
        print(lst[i][0]);
        print(lst[i][1].Sort().Format());
    }
}

PreMain(require("fs").readFileSync("/dev/stdin", "utf8"));
//PreMain(require("fs").readFileSync("input.txt", "utf8"));