let () = Scanf.scanf "%d\n%s\n" @@ fun n s ->
  Array.init n (String.get s)
  |> Array.fold_left (fun (minimum, h) -> function
    | '(' -> (minimum, h + 1)
    | ')' -> (min minimum (h - 1), h - 1)) (0, 0)
  |> (fun (minimum, h) ->
      let d = max 0 (~- minimum) in
      Printf.printf "%s%s%s\n" (String.make d '(') s (String.make (max 0 (d + h)) ')'))


