{-# LANGUAGE Strict #-}
import qualified Data.ByteString.Char8 as B
import           Data.Char             (digitToInt)
import qualified Data.Vector.Unboxed   as V


main :: IO ()
main = do
  s <- B.getLine
  print $ solve s

solve :: B.ByteString -> Int
solve s = V.sum $ V.map (\h -> h * (h - 1) `div` 2) hs
  where m = 2019
        hs = hist m $ subModNum s m

subModNum :: B.ByteString -> Int -> [Int]
subModNum s m = map fst $ scanr (\a (y, f) -> ((y + a * f) `mod` m, 10 * f `mod` m)) (0, 1) as
  where as = [digitToInt c | c <- B.unpack s]

hist :: Int -> [Int] -> V.Vector Int
hist n xs = V.accum (+) (V.replicate n 0) [(x, 1) | x <- xs]
