import Data.Char
import Text.Printf
import qualified Data.IntMap.Strict as M
import qualified Data.ByteString.Char8 as C

m :: Int
m = 2019

main :: IO ()
main = do
  s <- C.getLine
  let acc (a, mp, pp, total) c =
        let a' = (a * 10 + digitToInt c) `mod` m
            pp' = pp * 202 `mod` m
            k = a' * pp' `mod` m
            increment Nothing = Just 1
            increment (Just x) = Just (x + 1)
            mp' = M.alter increment k mp
            total' = total + M.findWithDefault 0 k mp
        in (a', mp', pp', total')
      (_, _, _, ans) = C.foldl' acc (0, M.fromList [(0, 1)], 1, 0 :: Int) s
  printf "%d\n" ans