#include <iostream>
#include <vector>

using namespace std;

int main() {

	long long rez = 0;
	vector<int> freq(2019);	
	string s;
	cin >> s;
	freq[0] = 1;
	int md = 0, p = 1;
	for (int i = (int)s.size() - 1; i >= 0; i--) {
		md = (md + p * (s[i] - '0'))	% 2019;
		rez += freq[md];
		freq[md]++;
		p = p * 10 % 2019;
	}
	cout << rez << "\n";
}
