import Text.Regex.PCRE

decompress [] = ""
decompress (x : xs)
  | x == '(' = if null match
               then decompress ""
               else let [[_, ls, rs, rest]] = match
                        l = read ls
                        r = read rs
                        (partToRepeat, rest') = splitAt l rest
                    in (concat . replicate r $ partToRepeat) ++ decompress rest'
  | otherwise = x : decompress xs
  where
    match = xs =~ "(\\d+)x(\\d+)\\)(.+)" :: [[String]]

main = do
  input <- getContents
  print . length . decompress $ input
