#include <stdio.h>
int n, x, a, e;
char s[200001];
int d[2019];
int main() {
	scanf(" %s", s);
	while (s[n] != NULL)n++;
	e = 1;
	d[0]++;
	for (int i = n - 1; i >= 0; i--) {
		x += (s[i] - '0') * e;
		e *= 10;
		e %= 2019;
		x %= 2019;
		d[x]++;
	}
	for (int i = 0; i < 2019; i++) {
		a += d[i] * (d[i] - 1) / 2;
	}
	printf("%d\n", a);
}