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

main :: IO ()
main = do
  s <- getLine :: IO String
  let
    tailRems :: [Int]
    tailRems = map ((`mod` 2019) . readInt) . 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)

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