checkString :: String -> Bool
checkString (x:"") = True
checkString x = x < "27"
solve :: String -> Int
solve "" = 1
solve ('0':_) = 0
solve (x:"") = 1
solve (x:y:rest) | checkString (x:[y]) = solve (y:rest) + solve (rest)
solve (x:y:rest) = solve (y:rest)
main = interact f
where f = unlines . map (show . solve) . takeWhile (/="0") . words