#include <stdio.h>
#include <string.h>
typedef long long ll;
int main() {
	char s[200001];
	int mod2019[2019] = {1};
	int dig = 1;
	scanf("%s", s);
	int len = strlen(s);
	ll ans = 0, sum = 0;
	for (int i = len - 1; i >= 0; i--) {
		sum = (sum + (s[i] - '0') * dig) % 2019;
		sum %= 2019;
		mod2019[sum]++;
		dig = dig * 10 % 2019;
		// printf("%lld\n", sum);
	}
	for (int i = 0; i < 2019; i++) {
		ans += (ll)mod2019[i] * (mod2019[i] - 1) / 2;
	}
	printf("%lld\n", ans);
	return 0;
}