#include <math.h>

int main()
{
  char s[1000000];
  scanf("%s", &s);
  
  int i = 0, j, tmp_i, tmp_j, tmp, cnt = 0;
  while (s[i] != '\0')
  {
    j = i + 3;
    while (s[j] != '\0')
    {
      tmp_j = j;
      tmp_i = i;
      tmp = 0;
      while (tmp_j - i >= 0)
      {
        tmp += pow(10, tmp_j) * (s[tmp_i] - '0');
        tmp_j--;
        tmp_i++;
      }
      if (tmp % 2019 == 0 && tmp != 0)
      {
        cnt++;
      }
      j++;
    }
    i++;
  }
  
  printf("%d", cnt);
}