#include <stdio.h>
#include <stdlib.h>

#define BUFF 256

void chk (char *num,int len);
int main (void){
  int len=0;
  int num=0;
  char str[BUFF] ={'\0'};

  if ( scanf("%s",str) == 1);
  while(str[len] != '\0') len++;

  chk(str,len);
 
  return 0;
  
}

void chk (char *num,int len){
  int i,j,k,m=0,div=0;
  int count =0;
  char str[BUFF]={'\0'};

  
  for(i=0; i<len-1; i++){
    for(j=i+1; j<len; j++){
      m = 0;
      for(k=0;k<BUFF; k++){
	str[k] = '\0';
      }
      for(k=i;k<=j; k++){
	str[m] = num[k];
	m++;
      }
      div = atoi(str);
      if (div % 2019 == 0){
	count++;
    }
      /* printf("div = %d\n",div); */
    }
  }
  printf("%d\n",count);
  return;
}
