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

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

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

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

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