function main(input) {
  const lines = input.split("\n");
  const S = lines[0];

  let count = 0;
  const l = S.length;
  for (let i = 0; i < l; i++) {
    for (let j = i + 4; j <= l; j++) {
      const s = S.slice(i, j);
      if (s % 2019 == 0) count++;
      // console.log(s)
    }
  }

  console.log(count);
}

main(require("fs").readFileSync("/dev/stdin", "utf8"));