{-# 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
  v <- VM.new 2019
  VM.set v (0::Int)
  VM.write v 0 1

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

  countN 0 1 1

  let f x = (x - 1) * x `div` 2
      solve i res | i == 2019 = return res
                  | otherwise = do
                      x <- VM.read v i
                      solve (i+1) (res + f x)

  ans <- solve 0 0

  print ans