function main(input) {
  const i = input.split('');
  let count = 0;
  let str;
  for (let j = 0; j < i.length; j++) {
    str = i[j];
  	for (let k = j+1; k < i.length; k++) {
    	str += i[k]
     	if (parseInt(str) % 2019 === 0) count++;
    }
  }
  console.log(count);

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