let id x = x

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

let s_len = String.length s

let () =
  let ans = ref 0 in
  for i = 0 to s_len - 5 do
    for j = 4 to s_len - i do
      let t = int_of_string (String.sub s i j) in
      ans := !ans + if t mod 2019 = 0 then 1 else 0
    done
  done;
  print_int !ans