#include <stdio.h>
#include <string.h>

char buff[200000+1];
int ans = 0;

int num(char c) { return c-'0'; }
int main() {
    scanf("%s", buff);
    //for (int i=4; i<200000; i++) buff[i]='0';
    //buff[200000]=0;
    int len = strlen(buff);

    for (int i=0; i+4<=len; i++) {
        int rest = num(buff[i])*100
            + num(buff[i+1])*10
            + num(buff[i+2]);
        //printf("i=%d\n", i);
        for (int pos=i+3; pos<len; pos++) {
            //printf("rest=%d\n", rest);
            rest = rest*10+num(buff[pos]);
            rest %= 2019;
            if (rest==0) ans++;
        }
    }
    printf("%d\n", ans);

}
