#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <math.h>
#define MAX(a, b) ((a) > (b) ? (a) : (b))

int main(void)
{
long i, j, k, len, count, num;
char S[200001];
  

  memset(&S, 0, sizeof(S));
  count = 0;
  num = 0;
  
  scanf("%s", &S);
  len = strlen(S);
  for (i = 0; i < len - 3; ++i ) {
    for (j = i + 3; j < len; ++j) {
      num = 0;
      for (k = i; k <= j; ++k) {
        num *= 10;
        num += (S[k] - 0x30);
      }
      if (num % 2019 == 0) {
        count++;
      }
    }
  }
  printf("%ld\n", count);
  return 0;
}
