function main(input) {
  const s = input[0];
  let counter = 0;
  const n = s.length;

  for(let i=0;i<n;i++){
    for(let j=i+4;j<n;j++){
      let str = parseInt(s.substr(i,j-i+1));
      if((str%673)===0){
        if((str%3)===0){
          counter++;
        }
      }
    }
  }
  console.log(counter);
}
main(require('fs').readFileSync('/dev/stdin', 'utf8').trim().split("\n"));