f [] _ _ = ([],[]) f ('(':s) is j = (r:ls,rs) where (ls,r:rs) = f s (j:is) (j+1) f (')':s) (i:is) j = (i:ls,j:rs) where (ls,rs) = f s is (j+1) main = do getLine s <- getLine mapM_ print $ fst $ f s [] 1