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

int main(void) {
  char N;
  scanf("%s", &N);
  long cnt = 0;
  long S_int = 0;
  int len_s = strlen(S)
  for(int n = 4; n <= len_s; n++) {
    for(int i = 0; i <= len_s - n; i++) {
      strncpy(S_int, S+i, n);
      S_int = atoi(S_int);
      if (S_int % 2019 == 0){
       	cnt += 1;
      }
    }
  }
  printf("%ld", cnt);
  return 0;
}