#C12918. Combine Key-Value Pairs Summing Values
Combine Key-Value Pairs Summing Values
Combine Key-Value Pairs Summing Values
You are given a list of key-value pairs. Your task is to combine the pairs with the same key by summing their corresponding values.
The input is provided via stdin. The first line contains an integer \(n\) representing the number of pairs. Each of the next \(n\) lines contains a string key and an integer value separated by a space.
The output should list each unique key along with its aggregated sum, printed in lexicographical order (alphabetical order) with each key-value pair on a separate line. The key and the sum should be separated by a space.
For example, if the input is:
4 a 1 b 2 a 3 c 1
Then the output should be:
a 4 b 2 c 1
inputFormat
The first line of the input contains an integer n (0 ≤ n ≤ 10^5), representing the number of key-value pairs. The following n lines each contain a string and an integer, separated by a space.
outputFormat
For each unique key, output a line containing the key and its corresponding sum separated by a space. The keys must be printed in lexicographical order. If n is 0, no output should be produced.## sample
4
a 1
b 2
a 3
c 1
a 4
b 2
c 1
</p>