{-# LANGUAGE BangPatterns #-}
import           Control.Exception           (assert)
import           Control.Monad
import           Control.Monad.Primitive
import qualified Control.Monad.ST            as ST
import qualified Data.Array.IO               as IO
import qualified Data.Array.ST               as ST
import qualified Data.Array.Unboxed          as A
import           Data.Bits
import qualified Data.ByteString.Char8       as BS
import           Data.Char
import           Data.Foldable
import           Data.List
import           Data.Maybe
import qualified Data.Sequence               as Seq
import qualified Data.Set                    as Set
import qualified Data.Vector.Unboxed         as V
import qualified Data.Vector.Unboxed.Mutable as VM
import           Debug.Trace

readInt = fst . fromJust . BS.readInt
readIntList = map readInt . BS.words
getInt = readInt <$> BS.getLine
getIntList = readIntList <$> BS.getLine
getIntVec n = V.unfoldrN n (BS.readInt . BS.dropWhile isSpace) <$> BS.getLine

readInteger = fst . fromJust . BS.readInteger
readIntegerList = map readInteger . BS.words
getInteger = readInteger <$> BS.getLine
getIntegerList = readIntegerList <$> BS.getLine

inf :: Int
inf = 10^18

main = do
  s <- BS.getLine
  let n = BS.length s
  ms <- VM.new n

  let countN x i | i == n = return ()
                 | otherwise = do
                     let c = s `BS.index` i
                         x' = (x * 10 + read [c]) `mod` 2019
                     VM.write ms i x'
                     countN x' (i+1)

  countN (0::Int) 0
  ms' <- V.freeze ms

  let loop' !j !x !ct | j == n = ct
                      | otherwise = let m = ms' V.! j
                                        x' = x * 10 `mod` 2019
                                        ct' = if x' == m then ct + 1 else ct
                                    in loop' (j+1) x' ct'

      solve !i !res | i == n = res
                    | otherwise =
                      let x = if i == 0 then 0 else ms' V.! (i-1)
                          ct = loop' i x 0
                      in solve (i+1) (res+ct)

      ans = solve 0 0

  print ans