#abc307d. [abc307_d]Mismatched Parentheses
[abc307_d]Mismatched Parentheses
Problem Statement
You are given a string of length consisting of lowercase English letters and the characters (
and )
.
Print the string after performing the following operation as many times as possible.
- Choose and delete a contiguous substring of that starts with
(
, ends with)
, and does not contain(
or)
other than the first and last characters.
It can be proved that the string after performing the operation as many times as possible is uniquely determined without depending on how it is performed.
Constraints
- is an integer.
- is a string of length consisting of lowercase English letters and the characters
(
and)
.
Input
The input is given from Standard Input in the following format:
Output
Print the answer.
Sample Input 1
8
a(b(d))c
Sample Output 1
ac
Here is one possible procedure, after which will be ac
.
- Delete the substring
(d)
formed by the fourth to sixth characters of , making ita(b)c
. - Delete the substring
(b)
formed by the second to fourth characters of , making itac
. - The operation can no longer be performed.
Sample Input 2
5
a(b)(
Sample Output 2
a(
Sample Input 3
2
()
Sample Output 3
The string after the procedure may be empty.
Sample Input 4
6
)))(((
Sample Output 4
)))(((