import Data.List

main = do
 getLine
 as <- getLine
 putStrLn (ins as)

ins as
 | valid as == (Just 0) = as
 | otherwise = replicate nbl '(' ++ as ++ replicate nbr ')'
  where
   nbl = let (bl,br) = partition (=='(') (dropWhile (==')') as)
          in length (takeWhile (==')') as) + max 0 (length br - length bl)
   nbr = let (bl,br) = partition (=='(') as in (length bl) + nbl - (length br)
--   nbr = let (br,bl) = partition (==')') $ dropWhile (=='(') (reverse as)
--          in length (takeWhile (=='(') (reverse as)) + length bl - length br

valid = foldr (\b acc -> if b==')' then succ <$> acc else if b=='(' && ((Just 0) < acc) then pred <$> acc else Nothing) (Just 0)