Олимпиадный тренинг

Задача 27311. Tilda-omega-lambda-calculus


Задача

Темы:
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