Given one expression, write a program that prints every distinct expression that can be obtained by removing one or more pairs of matching parentheses.
The given expression has balanced parentheses. For example, 1+2, (3+4), and (3+4*(5+6)) are all expressions whose parentheses match correctly.
On the other hand, expressions such as 1+(2*3 and ((2+3)*4 are not valid because some parentheses are not closed or do not have matching partners.
When parentheses are removed, the opening and closing parenthesis from the same pair must be removed together.
For example, from (2+(2*2)+2), the possible expressions are (2+2*2+2), 2+(2*2)+2, and 2+2*2+2. Expressions such as (2+2*2)+2 and 2+(2*2+2) cannot be made because they would require removing parentheses that are not a matching pair.
A single expression may also be wrapped by several layers of parentheses.
The first line contains an expression made of nonnegative integers. The expression's parentheses are balanced.
The expression contains only digits, +, *, -, /, (, and ). Its length is at most 200, and it contains at least 1 and at most 10 pairs of parentheses.
Print every distinct expression obtainable by removing one or more valid parenthesis pairs, in lexicographic order.