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

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

int checkDividableBy2019(int *integers, int i, int j)
{
  unsigned int rem = 0;
  for (int index = i; index <= j; index++)
  {
    rem = rem * 10 + integers[index];
    rem %= 2019;
  }
  if (rem == 0)
  {
    return 1;
  }
  else
  {
    return 0;
  }
}

int main(int argc, char const *argv[])
{
  char S[200001];
  scanf("%s", S);
  int S_len = strlen(S);
  int *S_int = malloc(sizeof(int) * S_len);
  for (int i = 0; i < S_len; i++)
  {
    S_int[i] = ctoi(S[i]);
  }

  unsigned int sum;
  unsigned int count = 0;
  for (int i = 0; i < S_len; i++)
  {
    sum = 0;
    for (int j = i; j < S_len; j++)
    {
      sum += S_int[j];
      sum %= 3;
      if (sum == 0 && j - i > 3)
      {
        count += checkDividableBy2019(S_int, i, j);
      }
    }
  }

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