#include <stdio.h>

int main()
{
	char S[200001];
	scanf("%s", S);
	
	int i, count[2019] = {1}, tmp[2] = {0, 1};
	long long ans = 0;
	for (i = 0; S[i] != 0; i++);
	for (i--; i >= 0; i--) {
		tmp[0] = (tmp[0] + tmp[1] * (S[i] - '0')) % 2019;
		ans += count[tmp[0]]++;
		tmp[1] = tmp[1] * 10 % 2019;
	}
	printf("%lld\n", ans);
	fflush(stdout);
	return 0;
}