{-# 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 -> V.Vector Int
subModNum s m = V.map fst $ V.scanr' (\a (y, f) -> ((y + a * f) `mod` m, 10 * f `mod` m)) (0, 1) as
  where cs = V.unfoldr B.uncons s
        as = V.map digitToInt cs

hist :: Int -> V.Vector Int -> V.Vector Int
hist n xs = V.accumulate_ (+) (V.replicate n 0) xs (V.replicate m 1)
  where m = V.length xs
