module Main where
import Control.Monad
import Control.Applicative
import Data.Maybe
import Data.List
import qualified Text.Printf
import qualified Data.ByteString.Char8 as BC
import qualified Data.ByteString as BC

------------------------------------------

main :: IO ()
main = do
  n <- readInt
  ps <- getLine
  let (x, _) = calc ps
      (_, y) = calc $ reverse ps
  putStrLn $ replicate (-x) '(' ++ ps ++ replicate y ')'

calc :: String -> (Int, Int)
calc ps = go maxBound minBound 0 ps
  where go t u _ "" = (t, u)
        go t u v (x:xs)
          | x == '('  = go t             (max u (v+1)) (v+1) xs
          | otherwise = go (min t (v-1)) u             (v-1) xs

------------------------------------------

{- Int input -}

parseInt :: BC.ByteString -> Int
parseInt = fst . fromJust . BC.readInt

parseInts :: BC.ByteString -> [Int]
parseInts = map parseInt <$> BC.words

readInt :: IO Int
readInt = parseInt <$> BC.getLine

readInts :: IO [Int]
readInts = parseInts <$> BC.getLine

{- Double Formatting -}

doubleFmt :: Double -> String
doubleFmt = Text.Printf.printf "%.12f"
