Problem F
Nizovi
An array in a certain programming language is defined in the following way:
-
The beginning and the end of an array is denoted by an open and closed curly bracket, respectively.
-
Inside the curly braces, there are $0$ or more values separated by commas (there is no comma after the last value in the array).
-
Each value can be a word (a sequence of lowercase letters of the English alphabet) or another array.
-
Examples of correctly defined arrays are: “{}”, “{a,b,c}”, and “{abc,znj,{novi,niz},pozz}”.
Recently, you’ve noticed that the programming language does not throw an error if you do not place the appropriate number of spaces and new lines before or after the curly braces or the commas. Given the fact that you do not like the values being so “squished” together, you’ve decided to get to work and modify the shape of the array in the following way:
-
Each value that is not an array or denotes the beginning or the end of the array (curly braces) will be in its own line.
-
The commas are “connected” with the value located directly before them and there is a new line after each comma.
-
After the curly bracket denoting the beginning of an array, the indentation of the content increases (shifting the output to the right) by $2$ spaces.
-
Before the curly bracket denoting the end of an array ’}’, the indentation of the content decreases (shifting the output to the left) by $2$ spaces.
-
The final line with the last curly bracket ends in a new line.
Input
The first line of input contains an array of characters $S$ ($2 \leq |S| \leq 1\, 500$), representing the array from the task. The array is well-formed according to the array definition given at the beginning of the problem description.
Output
The output must consist of the modified version of the array from the task. Judging for this problem is sensitive to changes in spaces and newlines.
Sample Input 1 | Sample Output 1 |
---|---|
{abc,ono,sto} |
{ abc, ono, sto } |
Sample Input 2 | Sample Output 2 |
---|---|
{} |
{ } |
Sample Input 3 | Sample Output 3 |
---|---|
{znakovi} |
{ znakovi } |
Sample Input 4 | Sample Output 4 |
---|---|
{a,b,{c,d},e,{}} |
{ a, b, { c, d }, e, { } } |