#include <bits/stdc++.h>
#define rep(i,n) for (int i = 0; i < (n); ++i)
#define all(v) v.begin(), v.end()
using namespace std;
typedef long long ll;

int main() {
	string s;
	cin >> s;
	reverse(all(s));
	ll ans = 0;
	int n = s.size();
	const int mod = 2019;
	vector<int> tot(n+1), cnt(mod);
	int x = 1;
	rep(i, n) {
		if(i == 0) tot[i+1] = (int) (s[i] - '0');
		else tot[i+1] = (tot[i] + (int) (s[i] - '0')* x) % mod;
		x *= 10;
		x %= mod;
	}
	rep(i, n+1) cnt[tot[i]]++;
	rep(i, mod) ans += cnt[i]*(cnt[i]-1)/2;
	// rep(i, n+1) cout << tot[i] << " ";
	cout << ans << endl;
	return 0;
}