#include <bits/stdc++.h>
using namespace std;
int cnt[2019];
int main() {
	string s;
	cin >> s;
	int ans = 0, now = 0, p = 1;
	cnt[0] = 1;
	for (int i = s.size() - 1; i >= 0; i--){
		now = (now + (s[i] - '0') * p) % 2019;
		ans += cnt[now]++;
		p = p * 10 % 2019;
	}
	cout << ans;
	return 0;
}