'use strict';
function main(input) {
  const arr = input.trim().split(' ');
  const a = arr[0];
  let array = 0;
  let count = 0;

  for (let i = 0; i < a.length + 1; i ++) {
    for (let j = 0; j < a.length + 1; j ++) {
      array = Number(a.slice(i, j));
      if (array % 2019 === 0 && array !== 0) {
        count ++;      }
    }
  }
  
  console.log(count);
}

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