process.stdin.resume();
process.stdin.setEncoding('utf8');

var lines = []
var reader = require('readline').createInterface({
  input: process.stdin,
  output: process.stdout
});

reader.on('line', (line) => {
  lines.push(line);
});

reader.on('close', () => {
 var s = lines[0].split('');
 var num = '';
 var count = 0;

 for(i=0; i<s.length-4; i++){
   var num = '';
   for(j=4; j<=s.length; j++){
    num = s.slice(i,j);
    num = num.join('');
    number = Number(num);
    if(number == 0){
      continue;
    }
    else if(number % 2019 == 0){
      count++;
  
      
      }
    }
   }
   
   console.log(count);
 
});
