let id x = x
let n = Scanf.scanf "%d\n" id
let string = Scanf.scanf "%s\n" id

let rec makestr str n =
if n = String.length str - 1 then str else
  if str.[n] = '(' && str.[n+1] = ')' then
    makestr ((String.sub str 0 n) ^ (String.sub str (n+2) ((String.length str) - (n+2)))) 0 else makestr str (n+1)
  
let str = makestr string 0

let rec count x y str n =
  if n = String.length str then (x,y) else
  match str.[n] with
  | '(' -> count (x+1) y str (n+1)
  | ')' -> count x (y+1) str (n+1)

let (x,y) = count 0 0 str 0

let xlist = String.make x ')'
let ylist = String.make y '('
  
let () =
  Printf.printf "%s\n" (ylist ^ string ^ xlist)