#include "stdio.h"
#include "math.h"
#define mod 2019

int main(void)
{
  long int s;
  int i,j,k;
  int cnt=0;
  int temp;
  long int sum=0;
  int count=0;
  int a[200001];
  a[0]=0;

  scanf("%ld",&s);

  for(i=1;s!=0;i++)
  {
    a[i] = s%10;
    s=s/10;
    cnt++;
  }
/*  for(i=1;i<=cnt;i++)
  {
    printf("%d",a[i]);
  }printf("\n");*/
  for(i=1;i<=cnt/2;i++)
  {
    temp =a[i];
    a[i] = a[cnt+1-i];
    a[cnt+1-i] = temp;
  }
/*    for(i=1;i<=cnt;i++)
  {
    printf("%d",a[i]);
  }printf("\n");*/

  for(i=1;i<=cnt-3;i++)
  {
    for(j=i+3;j<=cnt;j++)
    {
      temp = i;
      for(k=0;k<j-i+1;k++)
      {
        sum = sum + pow(10,j-temp)*a[temp];
        temp++;
      }
      if (sum%mod == 0)
      {
        count++;
        //printf("%ld\n",sum);
      }
      sum=0;
    }
  }
  printf("%d",count);
}