import qualified Data.List as L
import qualified Data.Set as Set

main :: IO ()
main = do
  s <- getLine
  let s1 = (check s) :: [String]
  let s2 = check2 $ map read s1 :: [Int]
  print $ L.length $ ordNub s2

check s = L.filter (\x -> L.length x >= 4) $ ordNub $ L.subsequences s
check2 s = L.filter (\x -> x `mod` 2019 == 0) s

ordNub :: Ord a => [a] -> [a]
ordNub xs = foldr (\x k s -> if Set.member x s
  then k s
  else x : k (Set.insert x s))
  (const []) xs Set.empty