f :: String -> Int -> Int -> (Int, Int)
f [] l r = (l, r)
f ('(':xs) l r = f xs (l + 1) r
f (')':xs) 0 r = f xs 0 (r + 1)
f (')':xs) l r = f xs (l - 1) r

main = do
    n <- readLn :: IO Int
    s <- getLine
    let (l, r) = f s 0 0
    putStrLn $ replicate r '(' ++ s ++ replicate l ')'