#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(k,i,n) for(ll i=k;i<n;++i)
#define ar array

int main() {
	ios::sync_with_stdio(0);
	cin.tie(0);

	ll n, p=2019;
	string s;
	cin >> s;
	n=s.length();
	ll ans=0;
		map<ll, ll> mp;
		++mp[0];
		ll t=0, p2=1;
		for(ll i=n-1; i>=0; --i) {
			t=(t+(s[i]-'0')*p2)%p;
			ans+=mp[t];
			mp[t]++;
			p2=p2*10%p;
		}
	cout << ans;
}