#C14890. Merge Two Dictionaries
Merge Two Dictionaries
Merge Two Dictionaries
This problem involves merging two dictionaries. You are given two dictionaries (in JSON format) with string keys and integer values. Your task is to merge them into a single dictionary. If a key appears in both dictionaries, then its corresponding value in the merged dictionary should be the sum of the values from both dictionaries. Mathematically, for any key \(k\) that appears in both dictionaries, the final value is given by:
\(merged[k] = dict1[k] + dict2[k]\)
If a key appears in only one dictionary, its value remains unchanged in the merged dictionary.
inputFormat
The input consists of two lines. Each line is a JSON formatted dictionary with string keys and integer values. The first line represents the first dictionary and the second line represents the second dictionary.
outputFormat
Output a single JSON formatted dictionary representing the merged result. For overlapping keys, output the sum of values. The output must be printed to stdout.
## sample{"a":2, "b":3, "c":1}
{"a":1, "b":2, "d":4}
{"a":3, "b":5, "c":1, "d":4}