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

int main(void)
{
    int	len;
    char    s[200001];
    int	res = 0;

    fscanf(stdin, "%s", s);
    len = strlen(s);

    char    b[200001];
    for (int i = 0; i <= len - 4; i++) {
	b[0] = s[i];
	b[1] = s[i+1];
	b[2] = s[i+2];
	b[3] = s[i+3];
	for (int j = i + 3; j < len; j++) {
	    int	n;
	    //strncpy(b, s+i, j-i+1);
	    b[j-i] = s[j];
	    b[j-i+1] = '\0';
	    sscanf(b, "%d", &n);
	    if (n % 2019 == 0) {
		//printf("%s, %d, %d, %d -> %s\n", s, i, j, n, b);
		res++;
	    }
	}
    }

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