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

int main(void)
{
  char S[200000];
  unsigned long long cnt = 0;

  scanf("%s", S);

  for (int i = 0; S[i] != '\0'; i++)
  {
    unsigned long long tmp = 0;
    for (int j = i; S[j] != '\0'; j++)
    {
      tmp = tmp * 10 + (S[j] - '0');
      tmp %= 2019;
      if (tmp == 0)
      {
        cnt++;
      }
    }
  }

  printf("%lld\n", cnt);

  return 0;
}
