-- Try AtCoder
-- author: Leonardone @ NEETSDKASU

main = putStrLn . solve . head . tail . lines =<< getContents

count c d [] = (c, d)
count c d ('(':s) = count (c + 1) d s
count c d (')':s) 
    | c > 0 = count (c - 1) d s
    | otherwise = count c (d + 1) s

solve s = answer where
    (op, cl) = count 0 0 s
    answer = replicate cl '(' ++ s ++ replicate op ')'
