#include<stdio.h>
int main (void)
{
    int i,a=0,k;
    int s;
    int b[2019]={0};
    int l[2019];
    while(1){
        s=getchar();
        if(s==10)break;
        k=s-'0';
        for(i=0;i<2019;i++)l[(i*10+k)%2019]=b[i];
        l[k]++;
        a+=l[0];
        for(i=0;i<2019;i++)b[i]=l[i];
    } 
    printf("%d",a);
}