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 :: VU.Vector Int
    tailRems = VU.map snd . VU.scanr step (10, 0) . VU.map unsafeCharToInt . VU.unfoldr T.uncons $ s
      where
        step :: Int -> (Int, Int) -> (Int, Int)
        step d (l, r) = (l', r')
          where
            l' = 10 * l `mod` 2019
            r' = (d * l + r) `mod` 2019
    cs :: VU.Vector Int
    cs = count tailRems
  print . VU.sum . VU.map (\k -> k * pred k `div` 2) $ cs

count :: VU.Vector Int -> VU.Vector Int
count v = VU.accumulate_ (+) (VU.replicate 2019 0) v (VU.replicate (VU.length v) 1)

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