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

#define N (2019)

int main(void) {
	int x, y, c;
	int a[N], b[N];

	c = 0;
	memset(a, 0, N);
	while ((x = getchar() - '0') > 0) {
		a[0] += 1;
  	memset(b, 0, N * sizeof(int));
		for (y = 0; y < N; y++) {
			b[(y * 10 + x) % N] = a[y];
		}
		memcpy(a, b, N * sizeof(int));
		c += a[0];
	}

	printf("%d\n", c);
}
