open Str
       
let () =
  let _ = read_line () in
  let s = split (regexp "") (read_line ()) in
  let f (l, st) x =
    match st with
      [] -> if x = ")" then (l+1, []) else (l, ["("])
    | y :: ys -> if x = ")" && y = "(" then (l, ys) else (l, "("::y::ys) in
  let (l, r) = List.fold_left f (0,[]) s in
  String.make l '(' ^ String.concat "" s ^ String.make (List.length r) ')' |> print_endline
