import qualified Data.Vector.Unboxed as VU
import Data.List (tails)

main :: IO ()
main = do
  ds <- map unsafeCharToInt <$> getLine :: IO [Int]
  let
    tailRems :: [Int]
    tailRems = map snd . scanr step (10, 0) $ ds
      where
        step :: Int -> (Int, Int) -> (Int, Int)
        step d (l, d') = (l * 10 `mod` 2019, (d * l + d') `mod` 2019)
    cs :: VU.Vector Int
    cs = count tailRems
  print . VU.sum . VU.map (\k -> k * pred k `div` 2) $ cs

count :: [Int] -> VU.Vector Int
count = VU.accum (+) (VU.replicate 2019 0) . map (flip (,) 1)

unsafeCharToInt :: Char -> Int
unsafeCharToInt c = fromEnum c - 48

readInt :: String -> Int
readInt "" = 0
readInt s = read s
