main :: IO () main = interact $ show . solve . words solve :: [String] -> Int solve [n, k, s] = if fst ws == t then snd ws else fst ws where t = (read :: String -> Int) k xs = zip [1..10000] s ys = foldl (\a x -> if snd x == '(' then a ++ [fst x] else a) [] xs zs = foldl (\a x -> if snd x == ')' then [fst x] ++ a else a) [] xs [ws] = filter (\(x, y) -> x==t || y==t) $ zip ys zs