const Main = input => {
  let count = 0;
  for(let i = 0; i < input.length; i++) {
    for(let j = 0; j < input.length; j++) {
      if(j < i) continue;//条件より
      
      const result = input.substr(i, j - i);//切り出し
      const num = parseInt(result, 10);
      
      if(num % 2019 === 0) count++;
    }
  }
  
  console.log(count);
}
 
Main(require("fs").readFileSync("/dev/stdin", "utf8"));