#include <stdio.h>
int strCount(char *p){
  int count = 0;
  while('\0' != *p){
	p++;
    count++;
  }
  return count;
}

int main (){
  int Count,i,j,num,solve;
  char data[6],*p;
  
  scanf("%s",data);
  p = data;
  Count = strCount(data);
  
  for(i = 0; (Count - 3) > i; i++){
	num = 0;
    for(j = 0; (Count - 3 - i) > j; j++){
	  if(j == 0){
        num = 1000*(int)(*(p+i)) + 100*(int)(*(p+i+1)) + 10*(int)(*(p+i+2)) + (int)(*(p+i+3));
      }else{
        num = num*10 + *(p + i + 3 + j);
      }
      if(num%2019 == 0){
		solve++;
      }
    }
	p++;
  }
  
  printf("%d",solve);
  
  return 0;
}