#C292. Flatten Nested List and Calculate Depth Sum
Flatten Nested List and Calculate Depth Sum
Flatten Nested List and Calculate Depth Sum
Given a nested list of integers (which may contain other nested lists), your task is to flatten this list into a single list and calculate the depth sum. The depth sum is defined as (\sum_{i=1}^{n} (a_i \times d_i)) where (a_i) is the integer and (d_i) is its depth level (with the outermost list having depth 1, and each inner list increasing the depth by 1). You can assume that the input is well-formed and only contains integers or nested lists of integers. If an element of another type is encountered, the behavior is undefined.
Input is provided via standard input as a single line containing a valid JSON representation of the nested list. Your program should output two lines: the first line containing the flattened list (the integers separated by a single space) and the second line containing the computed depth sum.
inputFormat
A single line containing the nested list in JSON format. For example: [1, [2, [3, 4], 5], 6]
outputFormat
The output should consist of two lines. The first line is the flattened list of integers separated by a single space, and the second line is the integer value of the depth sum.## sample
[1, [2, [3, 4], 5], 6]
1 2 3 4 5 6
42
</p>