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

int main(){
  char s[200001], subst[200001];
  scanf("%s", s);
  int length, counter=0;
  for(length=0; s[length]!='\0'; length++);

  for(int i=0; i<=length-2; i++){
    if(s[i] == '0') continue;
    for(int j=4; j<=length-i; j++){
      strncpy(subst, s+i, j);
      subst[j] = '\0';
      int tmp = atoi(subst);
      if(tmp%2019 == 0) counter++;
    }
  }
  printf("%d\n", counter);
  return 0;
}
