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 = map ((`mod` 2019) . unsafeTextToInt) . T.tails $ s
    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)

unsafeTextToInt :: T.Text -> Int
unsafeTextToInt s | T.null s  = 0
                  | otherwise = case T.signed T.decimal s of
                                  Right (n, _) -> n
