function main(arg) {
  var N = arg[0]
  var count = 0;
  for(var i = 4; i < N.length; i++ ) {
	  for(let j = 0; j <= N.length - i; j++) {
      	var a = parseInt(N.slice(j , j + i))
        if(a % 2019 === 0) {
        	count ++;
        }
      }
  }
  console.log(count) 
}

main(require("fs").readFileSync("/dev/stdin", "utf8").trim().split('\n'));
