In the LISP programming language everything is written inside balanced parentheses (LIKE THIS). This means that LISP code sometimes contains long stretches ")))...)" of closing parentheses. It is very tedious for the LISP programmer to get the number of these closing parentheses ')' to correspond exactly to the number of opening parentheses '('.
To prevent such syntax errors, some LISP dialects introduce a magic closing parenthesis ']' which substitutes one or more closing parentheses ')' as needed to properly balance the opening parentheses '('. But then the LISP compiler must calculate how many closing parentheses ')' each magic parenthesis ']' really substitutes. How?
Write a program which is given a string of opening, closing, and magic parentheses, and which calculates for each occurrence of the magic parenthesis the number of opening parentheses it corresponds to. In case of multiple solutions, the program should find any one of them.
The number '1' means that the input can be balanced. In this the output continues with the following M extra lines.
The 1st of these extra lines consists of the number C1 ³ 1 of closing parentheses ')' the 1st magic parenthesis ']' in the input substitutes to. The 2nd extra line consists of the corresponding number C2 ³ 1 for the 2nd ']' in the input, and so on.
If there are many ways in which the given string can be balanced, then your program may output any one of them.
입력 8 2 (((((])] 출력 1 3 1
출처:boi 2005