eolymp
bolt
Try our new interface for solving problems
Problems

Brackets Sequence

Brackets Sequence

Let us define a regular brackets sequence in the following way: \begin{enumerate} \item Empty sequence is a regular sequence. \item If \textbf{S} is a regular sequence, then \textbf{(S)} and \textbf{\[S\]} are both regular sequences. \item If \textbf{A} and \textbf{B} are regular sequences, then \textbf{AB} is a regular sequence. \end{enumerate} For example, all of the following sequences of characters are regular brackets sequences: () \[\] (()) (\[\]) ()\[\] ()\[()\] \textbf{, , , , ,} And all of the following character sequences are not: ( \[ ) )( (\[)\] (\[(\] \textbf{, , , , ,} Some sequence of characters '\textbf{(}', '\textbf{)}', '\textbf{\[}', and '\textbf{\]}' is given. You are to find the shortest possible regular brackets sequence, that contains the given character sequence as a subsequence. Here, a string \textbf{a_1a_2...a_n} is called a subsequence of the string \textbf{b_1b_2...b_m}, if there exist such indices \textbf{1} ≤ \textbf{i_1} < \textbf{i_2} < \textbf{...} < \textbf{i_n} ≤ \textbf{m}, that \textbf{a_j=b_ij} for all \textbf{1} ≤ \textbf{j} ≤ \textbf{n}. \InputFile The input contains at most \textbf{100} brackets (characters '\textbf{(}', '\textbf{)}', '\textbf{\[}' and '\textbf{\]}') that are situated on a single line without any other characters among them. \OutputFile Write a single line that contains some regular brackets sequence that has the minimal possible length and contains the given sequence as a subsequence.
Time limit 1 second
Memory limit 16 MiB
Input example #1
([(]
Output example #1
()[()]
Author Andrew Stankevich
Source 2001-2002 ACM Northeastern European Regional Programming Contest