#C12783. Aggregate Integer Sums by Key
Aggregate Integer Sums by Key
Aggregate Integer Sums by Key
You are given a list of records. Each record consists of a string and an integer. Your task is to aggregate the integers for each unique string. Formally, for each key k, you should compute the sum
$$ S_k = \sum_{i: key_i = k} value_i$$
and output the resulting dictionary in which the keys are sorted in lexicographical order. The output should be a single line string in the following format:
{"key1":value1,"key2":value2,...}
Note that there are no spaces in the output.
inputFormat
The first line of input contains an integer n indicating the number of records.
Each of the following n lines contains a string and an integer separated by a space.
outputFormat
Output a single line string representing a dictionary where each key is a unique string from the input and its corresponding value is the sum of all integers associated with that string. The keys must be sorted in lexicographical order. The format must be exactly as follows: {"key1":value1,"key2":value2,...}
## sample4
apple 1
banana 2
apple 3
orange 4
{"apple":4,"banana":2,"orange":4}