import Control.Monad
import Data.Maybe
import qualified Data.ByteString.Char8 as BS --(ByteString, getLine, readInt, words)

import Data.Array.Unboxed --(UArray)
import Data.Array.IO --(IOUArray, newListArray, newArray, writeArray, readArray)

import Data.Char --(toLower, toUpper, isUpper, ord)


-- example: putStrLn show 123 ++ "and" ~~ 456 ++ "or" ~~ 789
(~~) :: Show a => String -> a -> String
a ~~ b = a ++ show b

bslen = BS.length -- o(1)
bshd = BS.head -- o(1)
bstl = BS.tail -- o(1)
bslst = BS.last -- o(1)
bsini = BS.init -- o(1)
charToInt n = ord n - ord '0'
readi n = read n :: Int

bsToInt :: BS.ByteString -> Int
bsToInt = fst . fromJust . BS.readInt
getInt = bsToInt <$> BS.getLine

bsToInts :: BS.ByteString -> [Int]
bsToInts = map bsToInt . BS.words 
getInts = bsToInts <$> BS.getLine

getLines :: Int -> IO [BS.ByteString]
getLines n = replicateM n BS.getLine

getLinesToInts :: Int -> IO [Int]
getLinesToInts n = replicateM n $ bsToInt <$> BS.getLine

mapPutStrLn :: [String] -> IO()
mapPutStrLn = mapM_ putStrLn



newints :: Int -> Int -> Int -> IO(IOUArray Int Int)
newints start n = newArray (start, n)

rd :: IOUArray Int Int -> Int -> IO Int
rd = readArray

wt :: IOUArray Int Int -> Int -> Int -> IO()
wt = writeArray

--example: effect  (newArray (1, 3) 0)  3 (+100)   ->   array [(1,0), (2,0), (3,100)]
effect :: IOUArray Int Int -> Int -> (Int -> Int) -> IO()
effect ary i operator = (operator <$> readArray ary i) >>= writeArray ary i



countIJ :: BS.ByteString -> IOUArray Int Int -> IO Int -> Int -> Int -> IO Int
countIJ s cnts acc ti d  
    |bslen s == 0 = acc
    |otherwise     = countIJ s' cnts acc' ti' d'
    where
    s'   = bsini s
    ti'  = ( num * d + ti ) `mod` 2019
    num  = charToInt (bslst s)
    d'   = (d*10) `mod` 2019
    acc' = do
        res <-  (+)  <$>  acc  <*>  rd cnts ti'
        effect cnts ti' (+1)
        return res


main :: IO ()
main = do
    s <- BS.getLine
    let n = bslen s
    let acc = 0
    cnts <- newints 0 2018  0
    wt cnts 0 1
    acc' <- countIJ s cnts (return acc) 0 1
    print acc'

