#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;
	ll ans = 0;
	int n = s.size();
	vector<vector<ll>> dp(n, vector<ll>(n));
	vector<ll> v(2020);
	rep(i, n) {
		int now = (int) (s[i] - '0');
		vector<ll> n = v;
		rep(j, 2019) {
			if(v[j] == 0) continue;
			ll next = (j*10 + now)%2019;
			n[next] += v[j];
			n[j] -= v[j];
			// if(i<5) cout << i << " " << j << " " << next << " " << v[next] << " " << v[j] << endl;
		}
		v = n;
		v[now]++;
		ans += v[0];
	}
	// rep(i, 2019) cout << i << " :" << v[i] << endl;
	cout << ans << endl;
	return 0;
}