output_description: Print the lexicographically smallest string among the shortest correct bracket
  sequences that can be obtained by inserting some number of `(` and `)` into S.
  
  * * *
input_description: Input is given from Standard Input in the following format:
  
      
      
      N
      S
attempt: # -*- coding: utf-8 -*-
  import sys
  import math
  import os
  import itertools
  import string
  import heapq
  import _collections
  from collections import Counter
  from collections import defaultdict
  from functools import lru_cache
  import bisect
  
  
  class Scanner:
      @staticmethod
      def int():
          return int(sys.stdin.readline().rstrip())
  
      @staticmethod
      def string():
          return sys.stdin.readline().rstrip()
  
      @staticmethod
      def map_int():
          return [int(x) for x in Scanner.string().split()]
  
      @staticmethod
      def string_list(n):
          return [input() for i in range(n)]
  
      @staticmethod
      def int_list_list(n):
          return [Scanner.map_int() for i in range(n)]
  
      @staticmethod
      def int_cols_list(n):
          return [int(input()) for i in range(n)]
  
  
  class Math:
      @staticmethod
      def gcd(a, b):
          if b == 0:
              return a
          return Math.gcd(b, a % b)
  
      @staticmethod
      def lcm(a, b):
          return (a * b) // Math.gcd(a, b)
  
      @staticmethod
      def roundUp(a, b):
          return -(-a // b)
  
      @staticmethod
      def toUpperMultiple(a, x):
          return Math.roundUp(a, x) * x
  
      @staticmethod
      def toLowerMultiple(a, x):
          return (a // x) * x
  
      @staticmethod
      def nearPow2(n):
          if n <= 0:
              return 0
          if n & (n - 1) == 0:
              return n
          ret = 1
          while n > 0:
              ret <<= 1
              n >>= 1
          return ret
  
      @staticmethod
      def sign(n):
          if n == 0:
              return 0
          if n < 0:
              return -1
          return 1
  
      @staticmethod
      def isPrime(n):
          if n < 2:
              return False
          if n == 2:
              return True
          if n % 2 == 0:
              return False
          d = int(n**0.5) + 1
          for i in range(3, d + 1, 2):
              if n % i == 0:
                  return False
          return True
  
  
  MOD = int(1e09) + 7
  INF = int(1e15)
  
  
  def main():
      # sys.stdin = open("sample.txt")
      N = Scanner.int()
      S = Scanner.string()
      c1, c2 = 0, 0
      for i in range(N):
          if S[i] == ")":
              c1 -= 1
          else:
              c1 += 1
          if S[N - i - 1] == ")":
              c2 += 1
          else:
              c2 -= 1
          c1 = max(0, c1)
          c2 = max(0, c2)
      ans = "(" * c2 + S + ")" * c1
      print(ans)
  
  
  if __name__ == "__main__":
      main()
  
problem_description: 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.
samples: [{"input": "3\n    ())", "output": "(())\n    \n\n* * *"}, {"input": "6\n    )))())", "output": "(((()))())\n    \n\n* * *"}, {"input": "8\n    ))))((((", "output": "(((())))(((())))"}]