import Data.List import Control.Monad main = getLine >> getLine >>= mapM_ print . solve solve :: String -> [Int] solve = map snd . sort . snd . foldl' f ([], []) . zip [1..] where f :: ([Int], [(Int, Int)]) -> (Int, Char) -> ([Int], [(Int, Int)]) f (xs, ans) (i, '(') = (i:xs, ans) f (x:xs, ans) (i, ')') = (xs, (x, i):(i, x):ans)