#include<stdio.h>
#include<stdlib.h>
#include<string.h>
#include<math.h>
#define BUFSIZE 100

int a=0;
char enter[BUFSIZE];
int count = 0;
long long sum = 0;

int cal(int small,int large){
/*
  a++;
  if(a == 4) return 0;
*/
  if(large == strlen(enter)){
    if(small == strlen(enter)-4){
       return 0;
    }else{
      printf("hoge");
      return 0;
      cal(small+1,samll+4);
    }
  }
  for(int i=0;i < BUFSIZE;i++){
    if(large-small-i == -1) break;
      sum += (enter[small+i]-'0')*(int)pow(10,large-small-i);

  }
  if(sum % 2019 == 0) count++;

  /*
  printf("\n\n%d\n\n",sum);
  sum = 0;
  cal(small,large+1);
  */
}

int main(void){
  scanf("%s",enter);
  cal(0,3);
  printf("%d",count);
}
