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 rec loop1 i =
  let rec loop2 j =
    if j >= sl then 0 else
      (
        if (int_of_string @@ get_start_to_end i j) mod 2019 = 0 then 1 + loop2 (j+2) else loop2 (j+1) 
      )
  in if i >= sl-4 then 0 else (loop2 (i+1) + loop1 (i+1))

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

