#include <bits/stdc++.h>

#define ll long long
#define ull unsigned long long

using namespace std;

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

	ll N = S.size();
	ll MOD = 2019;

	ll ans = 0;
	map<int, int> m;
	ll base = 1;
	ll sum = 0;
	for (int ii = N-1; ii >= 0; --ii){
		ll v = ((S[ii] - '0') * base) % MOD;
		sum = (sum + v) % MOD;
		m[sum]++;
		ans += m[sum] - 1;
		if (sum == 0) ans++;
		base = (base * 10) % MOD;
	}

	cout << ans << "\n";

	return 0;
}
