breakLastRParenthesis xs = reverse $ snd $ break (== ')') $ reverse xs breakHeadLParenthesis xs = snd $ break (== '(') xs solve xs = [show (hidarimuki xs), show (migimuki xs)] hidarimuki :: String -> Int hidarimuki [] = 0 hidarimuki (x:xs) = iter xs + hidarimuki (breakHeadLParenthesis xs) where iter cs | ws == "" = 0 | star == "" = iter (hat ++ tail ws) | (length . filter (== '^')) hat < 2 = iter (hat ++ tail star ++ ws) | otherwise = (length . filter (== ')')) ws where (w, ws) = break (== ')') cs (hat, star) = break (== '*') w migimuki :: String -> Int migimuki xs = hidarimuki $ reverse $ map (\x -> if x == ')' then '(' else if x == '(' then ')' else x) xs main = getLine >>= putStrLn . unwords . solve . breakLastRParenthesis . breakHeadLParenthesis