import Control.Applicative import Control.Monad import qualified Data.ByteString.Char8 as B import Data.Maybe (fromJust) import Text.Printf import Debug.Trace solvel :: B.ByteString -> Integer solvel s = calcl (0,0,0) 0 s 0 calcl (n1,n2,n3) num s acc = if s == B.empty then acc else case (B.head s) of '(' -> calcl (n1,n2,n3+1) num bs acc ')' -> calcl (n1,n2,n3) num bs (acc + num) '^' -> calcl (n1+n2,n3,0) num bs acc _ -> calcl (0,n2,n3) (num+n1) bs acc where bs = B.tail s rev = B.map (\c -> case c of '(' -> ')' ')' -> '(' _ -> c) . B.reverse main = do s <- B.getLine let rs = rev s printf "%d %d\n" (solvel s) (solvel rs)