-- FileName   : 164d
-- CreatedDate: 2020-04-26 21:35:23

import Control.Monad
import Data.List

--reachHead _ [] = 0
--reachHead n a = let nn = (n*10) + (head a) `mod` 2019 in if nn == 0 then 1 + (reachHead nn $ tail a) else reachHead nn (tail a)

makeList _ [] = []
makeList n (x:xs) = let nn = (n*10+x)`mod`2019 in (nn:(makeList nn xs))

countModZero [] _ = 0
countModZero l@(x:xs) given@(y:ys) = (length $ filter (==0) l) +(countModZero (zipWith (f y) xs [1..(length xs)])) ys

f l n m = (n - (l * (pow 10 m))) `mod` 2019

pow n 0 = 1
pow n m = (pow n (m-1)) * n `mod` 2019

main = do
   s <- map (\x -> fromEnum x - 48) <$> getLine
   putStrLn $ show $ countModZero (makeList 0 s) s
--   print $ makeList 0 s
--   print $ countModZero (makeList 0 s) s

--------------------------------------------
getIntList        = map (read :: String -> Int) . words <$> getLine
getIntegerList    = map (read :: String -> Integer) . words <$> getLine
getIntegerListN m = map (read :: String -> Integer) <$> replicateM m getLine


base :: Integer
base = 1000000007

plus :: Integer -> Integer -> Integer
plus a b = (a+b) `mod` base

times :: Integer -> Integer -> Integer
times a b = a * b `mod` base

minus :: Integer -> Integer -> Integer
minus a b
   | a < b     = a-b + base
   | otherwise = a-b

power :: Integer -> Integer -> Integer
power n k
   | k == 0         = 1
   | k `mod` 2 == 0 = power (times n n) (k`div`2)
   | otherwise      = times n $! power n (k-1)

inv :: Integer -> Integer
inv n = power n $ base - 2

binom :: Integer -> Integer -> Integer
binom n m
   | (n-m) < m = times (foldr times 1 [m+1..n]) $ inv $ foldr times 1 [1..n-m]
   | otherwise = times (foldr times 1 [n-m+1..n]) $ inv $ foldr times 1 [1..m]
