#include<bits/stdc++.h>
using namespace std;

int cnt[2010];

int main() {
	string s;
	cin >> s;
	int num = 0, t = 1, res = 0;
	cnt[0] = 1;
	for(int i = s.size() - 1; i>=0; i--) {
		num = (num + (s[i] - '0') * t) % 2019;
		res += cnt[num];cnt[num]++;
		t = t * 10 % 2019;
	}
	printf("%d\n", res);
	return 0;
}