402342: GYM100733 G No Negations

Memory Limit:64 MB Time Limit:2 S
Judge Style:Text Compare Creator:
Submit:0 Solved:0

Description

G. No Negationstime limit per test2 secondsmemory limit per test64 megabytesinputstandard inputoutputstandard output

It is late at night and you found a logical expression on the blackboard, which you believe is the secret to figure out if your gang is going to be attacked tomorrow.

Your immediate reaction is to copy the expression and take it to the big bosses. Luckily, you remembered that mafia bosses don't enjoy surprises, and they want your expression to be simple and clean.

Given the logical expression in the board, having variables represented by english letters A-Z, and the operators OR and AND, simplify it using Morgan's law, that is:

To help you, we will use the following format:

  • [A + B] = (a * b) or
  • [A + b] = (a * B) or
  • [a + B] = (A * b) or
  • [A * B] = (a + b) or
  • [A * b] = (a + B) or
  • [a + B] = (A + b)

This is also valid for three or more variables. The expression will have variables, represented by letters A-Z: if it is a lower case letter, it is a negated variable. It may also have parenthesis that group expressions, so you must solve the expressions between the parenthesis first. There may also be square brackets, in which case you must apply the rules above.

Don't simplify the expression beyond applying the rules described in the problem.

Input

The input is a logical expression having at most 200 characters. Each character can be a variable (A-Z), a negated variable (a-z), the operator OR (+) or the operator AND (*). Also, it can have parenthesis. A negation is represented by a lowercase character or a logic block between square brackets ([ ]).

Output

Print the simplified logic expression.

ExamplesInput
[J+b+V*a]
Output
(j*B*v+A)
Input
i+i+G+m*((f))
Output
i+i+G+m*((f))
Input
v+a*(M*[T*b*N*U*g*G+x+O])
Output
v+a*(M*(t+B+n+u+G+g*X*o))
Input
g*[Q+w+[l*(j)]]
Output
g*(q*W*(l*(j)))

Source/Category

加入题单

上一题 下一题 算法标签: