import Control.Monad
import Data.List
import Data.Char

main = do
    ss <- tails <$> getLine
    print $ sum $ map (solve 0) ss

solve _ [] = 0
solve p (x:xs) = (f p') + solve p' xs
    where p' = (10*p + (digitToInt x)) `mod` 2019
          f p = if p == 0 then 1 else 0