import Control.Monad
import Data.List
import Data.Char

main = do
    ss <- getLine 
    let solve acc (i,x) = (10^i * x + acc) `mod` 2019
    print . sum . map (\xs -> let l = length xs in (l * (l-1)) `div` 2) . group . sort . scanl solve 0 . zipWith (\v c -> (v, digitToInt c)) [0..] $ reverse ss