open Batteries
(* 前からst文字を切り抜く *)
let slice st str = String.init (String.length str - st) (fun a -> String.get str (a+st))
(* 文字列をcharのarrayにする *)
let explode s = List.init (String.length s) (String.get s) |> Array.of_list
let s = read_line () |> explode
let sl = Array.length s

let get_start_to_end i j =
  String.init (j - i + 1) @@ fun a -> s.(a + i)
let t = Big_int.big_int_of_int 2019

let rec loop1 i ans=
  let rec loop2 j ans1=
    if j >= sl then ans1 else
      (
        if Big_int.eq_big_int ( Big_int.mod_big_int ((get_start_to_end i j) |> Big_int.big_int_of_string) t) Big_int.zero_big_int 
        then loop2 (j+i+1) (ans1+1)
        else loop2 (j+1) ans1
      )
  in if i >= sl-4 then ans else (loop1 (i+1) (ans+(loop2 (i+1) 0)))

let _ = loop1 0 0 |> Printf.printf "%d\n"

