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

main = do
    ss <- tails <$> getLine
    let solves = map (solve 0) ss
        n = length ss - 1
        solve _ [] = 0
        solve p (x:xs) | p' == 0 = 1 + 2 * solves !! (n - length xs)
                       | otherwise = solve p' xs
            where p' = (10*p + (digitToInt x)) `mod` 2019
    print $ sum solves