#include<stdio.h>
#include<stdlib.h>>
#include<string.h>
int main(){
    char s[200000];
    scanf("%s",s);
    int i, j, count=0, len=strlen(s);
    if(len>=4)
    {
        for(i=0; i<len-4; i++){
            int temp = (int)(s[i]-'0');
            temp = temp*10 + (int)(s[i+1]-'0');
            temp = temp*10 + (int)(s[i+2]-'0');
            for(j=i+3; j<len; j++){
                temp = temp*10 + (int)(s[j]-'0');
                temp %= 2019;
                if(temp==0)
                    count++;
                else
                    continue;
            }

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