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

let rec loop old lst i =
  match lst with
  | [] -> dp.(i) <- old
  | first :: rest -> dp.(i) <- old; loop (old ^ (Char.escaped first)) rest (i+1)

let _ = loop "" s 0

let rec loop1 i =
  let rec loop2 j =
    if j > sl then 0 else
    (
      if (slice (String.length dp.(i)) dp.(j) |> int_of_string) mod 2019 = 0 then 1 + loop2 (j+2) else loop2 (j+1)
    )
  in if i >= sl-3 then 0 else (loop2 (i+1) + loop1 (i+1))

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

