console.log((args=>{
  const S = args.trim().split``.map(v=>v|0);
  const L = S.length;
  const M = Array(2019).fill(0);
  let e = 0, d = 1;
  for ( let i = L-1; i >=0; i-- ) {
    e = (e + S[i] * d)%2019;
    M[e]++;
    d = d*10%2019;
  }
  let a = M[0];
  for ( let i = 0; i < 2019; i++ ) {
    if ( M[i] < 2 ) continue;
    a += M[i] * (M[i]-1) / 2;
  }
  return `${a}`;
})(require('fs').readFileSync('/dev/stdin', 'utf8')));
