#include <stdio.h>

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