#include<stdio.h>
#include<string.h>
#include<math.h>
int main(){
  long long s;
  scanf("%lld ",&s);
  
  long long x=1,y=1;
  while(s/x>=10){
    x*=10;y++;}
  
  long long i,j,ans=0,t;
  for(i=pow(10,y);i>=1;i/=10)
    for(j=1;j<=i;j*=10){
     t=(s%i)/j*10;
     if(t%2019==0&&t!=0)ans++;
    }
  printf("%lld\n",ans);
return 0;}