#C9770. Merge Dictionaries

    ID: 53900 Type: Default 1000ms 256MiB

Merge Dictionaries

Merge Dictionaries

You are given two dictionaries in JSON format. Your task is to merge them into one dictionary. If both dictionaries contain the same key, the value from the second dictionary is used. Note that the dictionaries may include nested dictionaries, which should be preserved as-is.

The input is provided via STDIN, where the first line contains the first dictionary and the second line contains the second dictionary. Your output should be the merged dictionary in JSON format, printed on a single line to STDOUT.

In mathematical terms, if we denote the dictionaries as \(D_1\) and \(D_2\), the merged dictionary \(M\) is defined as:

\[ M = D_1 \cup D_2, \quad \text{with } \forall k \ (k \in D_1 \cap D_2 \Rightarrow M(k)=D_2(k)). \]

inputFormat

The input consists of two lines:

  1. The first line is a JSON object representing the first dictionary.
  2. The second line is a JSON object representing the second dictionary.

outputFormat

Output a single line containing the merged dictionary as a JSON object. Ensure that if a key appears in both dictionaries, the value from the second dictionary is used.

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