let id x = x

let s = Scanf.scanf "%s\n" id

let s_len = String.length s

let a = 
  let rec f t d arr =
    if d = s_len then arr
    else begin
      let v = int_of_char s.[s_len - d - 1] - 48 in
      let b = (v * t) mod 2019 in
      arr.(d + 1) <- (arr.(d) + b) mod 2019;
      f (t * 10 mod 2019) (d + 1) arr
    end
  in
  f 1 0 (Array.make (s_len + 1) 0)

let ans = ref 0

let () =
  let rec f arr i =
    let v = a.(i) in
    ans := !ans + arr.(v);
    arr.(v) <- arr.(v) + 1;
    if i < s_len then f arr (i + 1)
  in
  f (Array.make 2020 0) 0;
  print_int !ans