import Control.Applicative import Data.List import Data.ByteString.Char8 (ByteString) import qualified Data.ByteString.Char8 as B main :: IO () main = solve <$> B.getLine >>= putStrLn solve :: ByteString -> String solve xs = f $ foldl' count (0,0) (B.tails xs) where f (x, y) = unwords . map show $ [x, y] data Face = L0 | L1 | L2 | L3 | R0 | R1 | R2 | R3 left L0 '^' = L1 left L1 '^' = L2 left L2 '*' = L3 left s _ = s right R0 '*' = R1 right R1 '^' = R2 right R2 '^' = R3 right s _ = s point L3 = 1 point R3 = 1 point s = 0 count :: (Int, Int) -> ByteString -> (Int, Int) count (l, r) bs | B.null bs = (l, r) | B.head bs == '(' = let (x,y,_,_) = B.foldl' f (l, r, L0, R0) (B.tail bs) in (x, y) | otherwise = (l, r) where f (cl, cr, sl, sr) c | c == ')' = (cl + point sl, cr + point sr, sl, sr) | otherwise = (cl, cr, left sl c, right sr c)