#C12431. Flatten Nested List

    ID: 41858 Type: Default 1000ms 256MiB

Flatten Nested List

Flatten Nested List

In this problem, you are given a nested list of integers, which may contain further nested lists. Your task is to flatten the list such that all elements appear in their original order as encountered in a depth-first traversal.

Mathematically, the flattening process can be described as follows:

$$flatten(L) = \begin{cases} [] & \text{if } L \text{ is empty},\\ [x] & \text{if } L = [x] \text{ and } x \text{ is an integer},\\ flatten(a) \Vert flatten(b) & \text{if } L = a \Vert b, \end{cases} $$

Here, (\Vert) denotes list concatenation. Your solution must read the nested list from standard input in JSON format and output the flattened sequence of numbers to standard output, with each number separated by a space.

inputFormat

The input consists of a single line that contains a nested list in JSON format. The list may be empty or may contain integers and/or other nested lists.

outputFormat

Output the flattened list of integers as a sequence of numbers separated by a single space. There should be no extra spaces at the beginning or end of the output.## sample

[1,2,3]
1 2 3