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

int main(){
  
  char S[200000];
  int i,j,index;
  char c;

  for(index=0;c != '\n';
    index++){
    scanf("%c",&c);
    S[index] = c;
  }
  /***
  for(i=0; i <= index ; i++){
    printf("%c",S[i]);
  }
  ***/
  
  char ST[200001];
  int count=0,tmp;
  
  for(i=0; i < index -3 ; i++){
    for(j = i +3; j < index-1; j++){
      strncpy(ST,S + i,j-i+1);
      ST[j-i+1] = '\0';
      tmp = atoi(ST);
      if(tmp%2019 == 0){
	//printf("(%d,%d)\n",i+1,j+1);
	count++;
      }
    }
  }
  printf("%d\n",count);
  
  
  return 0;
    }
