fun readStr () = let fun scan reader stream = SOME (StringCvt.splitl (not o Char.isSpace) reader (StringCvt.skipWS reader stream)) in valOf (TextIO.scanStream scan TextIO.stdIn) end exception BadInput fun findAns s = let fun count nil (left, right) = (left, right) | count (#"#" :: tl) (left, right) = (left, right) | count (#"(" :: #"^" :: #"^" :: #"*" :: #")" :: tl) (left, right) = count tl (left + 1, right) | count (#"(" :: #"*" :: #"^" :: #"^" :: #")" :: tl) (left, right) = count tl (left, right + 1) | count _ _ = raise BadInput in count (String.explode s) (0, 0) end val () = let val s = readStr () val (left, right) = findAns s in print (Int.toString left ^ " " ^ Int.toString right ^ "\n") end