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

int main()
{
	char s[200010];
	gets(s);
	int len = strlen(s);
	
	if (len < 5) {
		puts("0");
		return 0;
	}
	
	unsigned int cnt = 0;
	int surp;
	const char *const last1 = s + len - 4;
	const char *const last2 = s + len;
	char *cp;
	const char *cp1, *cp2;
	for (cp = s; cp < last2; ++cp) {
		*cp -= '0';
	}
	for (cp1 = s; cp1 < last1; ++cp1) {
		surp = *cp1       * 1000
		     + *(cp1 + 1) * 100
		     + *(cp1 + 2) * 10
		     + *(cp1 + 3);
		for (cp2 = cp1 + 4; cp2 < last2; ++cp2) {
			surp *= 10;
			surp += *cp2;
			surp %= 2019;
			if (surp == 0) {
				cnt++;
			}
		}
	}
	
	printf("%u\n", cnt);
	
	return 0;
}
