#include<stdio.h>
#include<string.h>
int main()
{
    char S[200000];
    int i,j,len;
    unsigned long long c=0,sum;
    scanf("%s",&S);
    len=strlen(S);
    for(i=0;i<(len-3);i++){
        sum=0;
        for(j=i;j<len;j++){
            sum=(sum*10+S[j]-'0')%2019;
            if(sum==0)
               c++;
        }
    }
    printf("%llu\n",c);
    return 0;
}



