import Text.Regex.PCRE

decompressLength s
  | null findFirstParenMatch = length s
  | otherwise                = length pre
                             + r * decompressLength repeatedString
                             + decompressLength rest'
  where
    findFirstParenMatch = s =~ "([A-Z]*)\\((\\d+)x(\\d+)\\)(.+)" :: [[String]]
    [[_, pre, ls, rs, rest]] = findFirstParenMatch
    l = read ls
    r = read rs
    (repeatedString, rest') = splitAt l rest


main = do
  input <- getContents
  print . decompressLength $ input
