#include<stdio.h>
#include<stdlib.h>
#include<string.h>
#include<math.h>
#define BUFSIZE 100000000
char enter[BUFSIZE];
int count = 0;
long long sum=0;
int cal(int small,int large){
  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++;
    }
  sum = 0;
  return 0;
}

int main(void){
  scanf("%s",enter);

/*
  printf("%c\n",enter[0]);
*/
  int len = strlen(enter);
  for(int i=0;i < len-3;i++){
    for(int j=i+3;j < len ;j++){
        cal(i,j);
    }
  }
  printf("%d",count);
}
