let s = read_line()
let a = Array.make 2019 0

let rec f i d n ans =
  if i = -1 then ans
  else
    let j = int_of_char s.[i] - int_of_char '0' in
    let n = (j * d + n) mod 2019 in
    let an = a.(n) in
    a.(n) <- an + 1;
    f (i - 1) (10 * d mod 2019) n (ans + an)

let () =
  a.(0) <- 1;
  let l = String.length s - 1 in
  let ans = f l 1 0 0 in
  Printf.printf "%d\n" ans
