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 -> 
    match Map.tryFind x m with 
    | Some v -> Map.add x (v + 1) m, ans + v 
    | _ -> Map.add x 1 m, ans 
    ) (Map.empty, 0)
|> snd
|> printfn "%i"
