Script Me

View as PDF

Submit solution

Points: 10
Time limit: 2.0s
Memory limit: 128M

Problem type

Rules

()+() = ()()                                      => [combine]
((()))+() = ((())())                              => [absorb-right]
()+((())) = (()(()))                              => [absorb-left]
(())(())+() = (())(()())                          => [combined-absorb-right]
()+(())(()) = (()())(())                          => [combined-absorb-left]
(())(())+((())) = ((())(())(()))                  => [absorb-combined-right]
((()))+(())(()) = ((())(())(()))                  => [absorb-combined-left]
()+(())+((())) = (()())+((())) = ((()())(()))     => [left-associative]

For example,

(())+() = ()+(()) = (()())

Input Specification

On the first and only line, one question, Q. See the sample input for more details. It is guaranteed that Q will contain at most 10 bracket expressions (thus, at most 9 +s), and each bracket expression will contain at most 1000 characters. Thus, |Q| \le 10^4 + 10. It is also guaranteed each bracket expression is valid.

Output Specification

Output the answer to the question.

Sample Input 1

()()()+((())())

Sample Output 1

(()()()(())())

Sample Input 2

()()+()()()+(())

Sample Output 2

(()()()()()())

Comments

There are no comments at the moment.