input = require('fs').readFileSync('/dev/stdin','utf8');
N = input.split('');
r = 0;
for(i = 0; i < N.length; i++) {
  if(i<=200000) {
    for(j = i + 4; j <= N.length - 1; j++) {
      if(j <= 200000) {
        v = parseInt(input.substring(i,j),10);
        if(v % 2019 == 0) r++;
      }
    }
  }
}
console.log(r);
