#C4599. Calculating Word Sums

    ID: 48154 Type: Default 1000ms 256MiB

Calculating Word Sums

Calculating Word Sums

Your task is to calculate the sum of integers associated with each word from the input. Each line of the input contains a word followed by one or more integers. For each word, compute the sum of the subsequent integers. After processing all the input lines, output each word along with its total sum in descending order of sums. If two words have the same sum, they should be listed in alphabetical order.

For example, if the input contains the lines apple 1 2 3 and apple 4 5, the total sum for 'apple' is 15.

inputFormat

The input is provided via standard input (stdin). Each line contains a word followed by one or more integers separated by spaces. The input terminates at EOF.

outputFormat

For each distinct word, output a line containing the word and its total sum separated by a space. The output should be sorted in descending order of sums. If two words have the same sum, sort them in alphabetical order.## sample

apple 1 2 3
banana 4 5 6
apple 4 5
orange 10
banana 1 2
orange 2 3 4
grape 1 1 1 1
orange 19

banana 18 apple 15 grape 4

</p>