#include <stdio.h>
#include <inttypes.h>

char S[222222];

uint64_t keisan[2][2019];

int main(void) {
	int i, j;
	uint64_t kotae = 0;
	if (scanf("%222220s", S + 1) != 1) return 1;
	keisan[0][0] = 1;
	for (i = 1; S[i] != '\0'; i++) {
		for (j = 0; j < 2019; j++) {
			keisan[i % 2][(j * 10 + (S[i] - '0')) % 2019] = keisan[(i - 1) % 2][j];
		}
		kotae += keisan[i % 2][0];
		keisan[i % 2][0]++;
	}
	printf("%" PRIu64 "\n", kotae);
	return 0;
}
