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

const int m = 2019;

int main()
{
	string s;
	cin >> s;
	reverse(s.begin(), s.end());

	int n = s.size();
	vector<ll> sum(n);
	sum[0] = s[0] - '0';
	ll x = 10;
	for (int i = 1; i < n; i++) {
		sum[i] = (sum[i - 1] + (s[i] - '0')*x) % m;
		x *= 10 % m;
	}

	map<ll, ll> mp;
	mp[0] = 1;
	for (int i = 0; i < n; i++) {
		if (mp.count(sum[i])) mp[sum[i]] = (mp[sum[i]] + 1) % m;
		else mp[sum[i]] = 1;
	}

	ll ans = 0;
	for (const auto& item : mp) ans += (item.second*(item.second - 1) / 2) % m;
	cout << ans << endl;
}
