cho.sh
Notes
Loading...

Removing Parentheses

Time limit

2s

Memory limit

128 MB

Problem

You are given a valid expression made only of lowercase English letters, the operators +, -, *, /, and parentheses. The grammar is defined as follows.

  1. A lowercase letter is a character.
  2. A term, expression+term, and expression-term are expressions.
  3. A factor, term*factor, and term/factor are terms.
  4. A character and (expression) are factors.

This grammar gives * and / higher precedence than + and -, and operators with the same precedence group from left to right.

You may remove parentheses only when the meaning of the expression does not change. Parentheses after + may be expanded as they are. When parentheses after - are expanded, the exposed + and - operators inside them are swapped. Similarly, if the parentheses after * contain one term, they may be expanded as they are. When such parentheses are expanded after /, the exposed * and / operators inside them are swapped.

Given an expression, output an equivalent expression with the minimum possible number of parentheses.

Input

The first line contains an expression with no spaces. Its length is at most 1,000.

Output

Print an expression with no spaces that has the minimum possible number of parentheses.