AtCoder Beginner Contest 064
D
Insertion
AtCoder
⌀ 969
原题
← C→
翻译中…

Problem Statement

翻译中…

You are given a string $S$ of length $N$ consisting of ( and ). Your task is to insert some number of ( and ) into $S$ to obtain a correct bracket sequence. Here, a correct bracket sequence is defined as follows:

翻译中…
  • () is a correct bracket sequence.
  • If $X$ is a correct bracket sequence, the concatenation of (, $X$ and ) in this order is also a correct bracket sequence.
  • If $X$ and $Y$ are correct bracket sequences, the concatenation of $X$ and $Y$ in this order is also a correct bracket sequence.
  • Every correct bracket sequence can be derived from the rules above.
翻译中…

Find the shortest correct bracket sequence that can be obtained. If there is more than one such sequence, find the lexicographically smallest one.

翻译中…

Constraints

翻译中…
  • The length of $S$ is $N$.
  • $1 ≤ N ≤ 100$
  • $S$ consists of ( and ).
翻译中…

Input

翻译中…

Input is given from Standard Input in the following format:

翻译中…

N
S

翻译中…

Output

翻译中…

Print the lexicographically smallest string among the shortest correct bracket sequences that can be obtained by inserting some number of ( and ) into $S$.

翻译中…

样例

Input #1
3
())
Output #1
(())
Input #2
6
)))())
Output #2
(((()))())
Input #3
8
))))((((
Output #3
(((())))(((())))
题目信息
题号
abc064_d
时间限制
2 s
内存限制
256 MB

题面与样例版权归 AtCoder 及出题人所有;中文翻译由 AI 生成(CI 管线),如有出入请以原文为准。