import Control.Monad
import Data.List
import Data.Char
import qualified Data.Vector as V

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