Module: Correct Bracket Sequence (RSP)


Problem

3 /6


Tilda-omega-lambda-calculus

Theory Click to read/hide

In the case of the presence of brackets of several types, everything becomes a little more complicated. We create a stack to act as that balance variable. This is necessary because parentheses cannot overlap. When we walk through a line and encounter an opening parenthesis, we push it onto the stack. When we encounter a closing brace, we try to pop the opening brace of that type off the stack. If a brace of a different type is on the stack, the sequence is invalid. If the stack is non-empty at the end, the sequence is also invalid. 

Problem

Tilda-omega-lambda-calculus is an even more innovative development of "British Scientists, Inc" in the field of functional programming. Its difference from the omega-lambda calculus is only in the ability to put square and curly brackets. Elephant-shaped brackets were also planned, but the company failed to change the UNICODE standard. 
The input is a tilde-omega-lambda expression of no more than 10^7 characters. You need to print the result of its tilde-izzy reduction, which works the same way as the izzy reduction for omega-lambda expressions, but with square and curly brackets.

Recall that  izzy-reduction is one of the operations on such expressions. When it is executed, it is checked whether the bracket sequence in the expression is correct. The terms are ignored. If the sequence is correct, it becomes the gg term, if not, it becomes the wp term. 
 

 

Examples
# Input Output
1 main{izzy[lol](ttt)} gg