import Data.Char
import Data.List

main = do
  s <- getLine
  print $ compute s

compute :: String -> Int
compute s = length $ filter (\x -> x `mod` 2019 == 0) $ concat $ unfoldr step (s,[])
  where
    step ("",_) = Nothing
    step (d:ds,xs) = Just (drop 3 xs', (ds, xs'))
      where
        e = digitToInt d
        f x = 10 * x + e
        xs' = e : map f xs