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

#define BUFF 256

int check_mul(char* str,int i,int j);


int main (void){
  int i,j,len=0;
  int count=0;
  char str[BUFF];

  scanf("%s",&str);

  while(str[len] != '\0'){
    len++;
  }
  for(i=0; i<len-1; i++){
    for(j=i+1; j<len; j++){
      count += check_mul(str,i,j);
    }
  }
  printf("%d\n",count);
  return 0;
}

int check_mul(char* str,int i,int j){
  int k=0,h=0;
  int m=j-i;
  int num=0;
  char numl[BUFF] ={'\0'};

  m = j-i;
  while(m >= 0){
    numl[k] = str[i];
    k++;
    i++;
    m = j-i;
    
  }

  /* for(h=0; h<k; h++){ */
  /*   printf("%c",numl[h]); */
  /* } */
  num = atoi(numl);

  if (num % 2019 == 0){
    return 1;
  }
  return 0;
}

