function main(lines) {
  const input = lines.split('\n')[0]
  let count = 0

  for(let i=0; i<input.length; i++){
    for(let j=0; j<=input.length; j++){
      if(i<j){
        let tmp = parseInt(input.slice(i,j),10)%2019
        if(tmp === 0){
          count++
        }
      }
    }
  }
  console.log(count)

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