open System

[<Literal>] 
let m = 2019

let S = Console.ReadLine()

let cusum = 
    let x = Array.zeroCreate (1 + S.Length) 
    let y = 
        let y = ref 1
        fun() -> 
            let r = !y
            y := !y * 10 % m 
            r
    for i in 1 .. S.Length do 
        let i' = S.Length - i;
        x.[i] <- ((int << string) S.[i'] * y() + x.[i - 1]) % m  
    x

cusum
|> Array.fold (fun (m, ans) x -> 
    if Map.containsKey x m then 
        let m' = Map.add x (m.[x] + 1) m
        (m', ans + m.[x])
    else
        let m' = Map.add x 1 m
        m', ans
    ) (Map.empty, 0)
|> snd
|> printfn "%i"