#C13832. Merge Sorted Nested Lists

    ID: 43414 Type: Default 1000ms 256MiB

Merge Sorted Nested Lists

Merge Sorted Nested Lists

You are given two sorted lists, each of which may contain nested lists. Your task is to flatten these nested lists and then merge the two sorted lists into a single sorted list.

The flattening process is defined as follows: for a list ( L ), its flattened version is ( flatten(L) = { x : x \in L \text{ or } x \in flatten(s), \text{ for any sublist } s \in L } ).

After flattening, the inputs are guaranteed to be sorted. Your job is to merge these two sorted flattened lists into one sorted list. The input is provided via STDIN and the result should be output to STDOUT in JSON array format.

inputFormat

Input is read from STDIN with two lines.

The first line is a JSON array representing the first sorted list (which may be nested), and the second line is a JSON array representing the second sorted list (which may also contain nested lists).

outputFormat

Output the merged and flattened sorted list as a JSON array to STDOUT.## sample

[1, 3, 5, [7, 9]]
[2, 4, 6, [8, 10]]
[1, 2, 3, 4, 5, 6, 7, 8, 9, 10]