import Data.Char
import Data.List

main = do
  s <- getLine
  print $ compute s

compute :: String -> Int
compute s = sum $ unfoldr step (s,[])

step :: (String,[Int]) -> Maybe (Int,(String,[Int]))
step ("",_) = Nothing
step (d:ds,xs) = Just (length $ filter (0 ==) xs', (ds, xs'))
  where
    e = digitToInt d
    f x = (10 * x + e) `mod` 2019
    xs' = e : map f xs