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

int ctoi(char c)
{
  if (c >= '0' && c <= '9')
  {
    return c - '0';
  }
  return 0;
}

int main(int argc, char const *argv[])
{
  char S[200001];
  scanf("%s", S);

  int S_len = strlen(S);
  unsigned int tmp;
  unsigned int count = 0;
  for (int i = 0; i < S_len; i++)
  {
    tmp = 0;
    for (int j = i; j < S_len; j++)
    {
      tmp = tmp * 10 + ctoi(S[j]);
      tmp %= 2019;
      if (tmp == 0)
      {
        count++;
      }
    }
  }

  printf("%d", count);
  return 0;
}
