#include <iostream>
#include <string>
#include <vector>

using namespace std;

int main()
{
	string s;
	cin >> s;

	int mod = 2019;
	vector<int> dp(s.length() + 1);
	int t = 1;
	for (int i = s.length() - 1; i >= 0; i--) {
		dp[i] = (s[i] - '0') * t + dp[i + 1];
		dp[i] %= mod;
		
		t *= 10;
		t %= mod;
	}

	int a[2019] = {};
	for (int i = 0; i <= s.length(); i++) {
		a[dp[i]]++;
	}

	long long ans = 0;
	for (int i = 0; i < 2019; i++) {
		ans += a[i] * (a[i] - 1) / 2;
	}
	cout << ans << endl;

	return 0;
}