import java.util.Scanner

object Main {
  def main(args: Array[String]): Unit = {
    val sc = new Scanner(System.in)
    val n = sc.nextInt()
    val s = sc.next()
    val ss = s.toCharArray
    
    var strings = Seq.empty[Array[Char]]
    var str = Seq.empty[Char]
    for (i <- ss.indices) {
      if (i == 0) {
        str = str :+ ss(i)
      } else if (ss(i - 1) == ')' && ss(i) == '(') {
        strings = strings :+ str.toArray
        str = Seq.empty[Char]
      } else {
        str = str :+ ss(i)
      }
    }
    strings = strings :+ str.toArray
    
    strings.foreach(c => f(c))
    
    println()
  }
  
  def f(s: Array[Char]): Unit = {
    val left = s.count(x => x == '(')
    val right = s.count(x => x == ')')
    
    if (left == right) {
      s.foreach(print)
    } else if (left < right) {
      (0 until (right - left)).foreach(_ => print("("))
      s.foreach(print)
    } else {
      s.foreach(print)
      (0 until (left - right)).foreach(_ => print(")"))
    }
  }
}