#C6871. Merge Two Dictionaries

    ID: 50679 Type: Default 1000ms 256MiB

Merge Two Dictionaries

Merge Two Dictionaries

You are given two dictionaries in JSON format. Your task is to merge these two dictionaries into a single dictionary. When a key appears in both dictionaries, the value from the second dictionary should be used. The output should also be in JSON format.

Note: The input will be provided via standard input (stdin) and the output should be printed to standard output (stdout).

The formula for merging can be summarized as: \[ D = D_1 \cup D_2 \quad \text{with} \quad \forall k \in (D_1 \cap D_2),\ D[k] = D_2[k] \]

inputFormat

The input consists of two lines where each line is a JSON object representing a dictionary. Each dictionary has string keys and integer values. For example:

{"a": 1, "b": 2}
{"b": 3, "c": 4}

outputFormat

Output the merged dictionary as a JSON object on one line. Using the above example, the answer would be:

{"a": 1, "b": 3, "c": 4}
## sample
{"a": 1, "b": 2}
{"c": 3, "d": 4}
{"a": 1, "b": 2, "c": 3, "d": 4}