import qualified Data.Text as T
import qualified Data.Text.IO as T
import qualified Data.Text.Read as T
import qualified Data.Vector.Unboxed as VU

main :: IO ()
main = do
  s <- T.getLine :: IO T.Text
  let
    tailRems :: [Int]
    tailRems = uncurry (:) . snd . T.foldr step (10, (0, [])) $ s
      where
        step :: Char -> (Int, (Int, [Int])) -> (Int, (Int, [Int]))
        step c (l, (r, rs)) = (10 * l `mod` 2019, ((unsafeCharToInt c * l + r) `mod` 2019, r : rs))
    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
