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

Задача 27310. Omega lambda calculus


Задача

Темы:
Omega lambda calculus - an innovative development of "British Scientists, Inc" in the realm of formal logic. Any expression of the omega-lambda calculus consists of parentheses and terms (a term can be any sequence of Latin letters). 
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 term gg, if not, it becomes the term wp
An omega-lambda expression of no more than 107 characters is used as input. You need to display the result of its izzy reduction.
 

 

Examples
# Input Output
1 a(b(xx)f(g(x))m(y)) gg