function Main(input){
    input = input.split("");
    var le = input.length;
    var log = input.slice();
    var find = [];
    var findtop = 0
    for(var i=0;i<le;i++){
        input = log.slice(i,log.length)
       // console.log(input.join(""))
        var sum = 0;
        var m;
        while(input.length>4){
        var n = Number(input.slice(0,4).join(""));
        if(n>=2019){
            input.splice(0,4);
           m = n - Math.floor(n/2019)*2019;
           // console.log(n)
            input = String(m).split("").concat(input)
        }else{
            n =  Number(input.slice(0,5).join(""));
                        input.splice(0,5);
         m = n - Math.floor(n/2019)*2019;
            input = String(m).split("").concat(input)
        }
        if(m==0) sum++;
                //    console.log(m)
        }
        find.push(sum);
    }
    var sum = 0;
    for(var i=0;i<find.length;i++){
        if(find[i]!=0)sum += factorialize(find[i])
    }
    console.log(sum)
   // console.log(find)
  }Main(require("fs").readFileSync("/dev/stdin", "utf8").trim());
  function factorialize(k) {
  var j = 1;
  for(var i = 1; i <= k; i++){
    j *= i;
  }
  return j;
}