let () =
  Scanf.scanf "%d %s" @@ fun n s ->
  let rec loop a c i =
    if i >= n then -a, c
    else if s.[i] = '(' then loop a (c+1) (i+1)
    else loop (min a (c-1)) (c-1) (i+1)
  in
  let l, r = loop 0 0 0 in
  String.make l '(' ^ s ^ String.make (max 0 (l+r)) ')'
  |> print_endline