import Control.Applicative import Control.Monad import qualified Data.ByteString.Char8 as B import Data.Maybe (fromJust) import Text.Printf import Debug.Trace calcr :: [Integer] -> B.ByteString -> Integer -> Integer calcr (r:rs) s acc = if s == B.empty then acc else calcr rs bs (if B.head s == '(' then acc + sub rs bs 0 else acc) where bs = B.tail s sub rs s lv = if s == B.empty then 0 else case lv of 3 -> head rs 0 -> sub (tail rs) (B.tail s) (if B.head s == '*' then lv+1 else lv) _ -> sub (tail rs) (B.tail s) (if B.head s == '^' then lv+1 else lv) calcacc = B.foldr (\c acc -> (head acc + if c == ')' then 1 else 0):acc) [0] rev = B.map (\c -> case c of '(' -> ')' ')' -> '(' _ -> c) . B.reverse main = do s <- B.getLine let rs = rev s printf "%d %d\n" (calcr (calcacc rs) rs 0) (calcr (calcacc s) s 0)