#include <bits/stdc++.h>

using namespace std;
#define rep(i, n) for(int i=0;i<n;i++)
#define REP(i, n) for(int i=1;i<=n;i++)
typedef long long ll;

ll mod = 2019;

int main() {
	string s;
	cin >> s;
	ll n = s.size();
	vector<ll> ms(n + 1, 0);
	ll ten = 1;
	reverse(s.begin(), s.end());
	ms[1] = s[0] - '0';
	vector<ll> m(2019, 0);
	REP(i, n) {
		ms[i] = ms[i - 1] + ten * (s[i - 1] - '0');
		ms[i] %= mod;
		ten *= 10;
	}
	rep(i, n + 1) {
		m[ms[i]]++;
	}
	ll ans = 0;
	rep(i, 2019) {
		ans += m[i] * (m[i] - 1) / 2;
	}
	cout << ans << endl;
	return 0;
}