#include <bits/stdc++.h>
using namespace std;
#define ll long long int
int main() {
	// your code goes here
	ll n,p=2019;
	string s;
	cin>>s;
  n=s.size();
	ll a[n];
	for(ll i=0;i<n;i++)
	{
		a[i]=s[i]-'0';
	}
	map<ll,ll> m;
	m[0]=1;
	ll out=0;
	ll t=0;
	ll ten=1;
	if(p!=2 && p!=5)
	{
	for(ll i=n-1;i>-1;i--)
	{
		t=((t)+(a[i]*ten)%p)%p;
		t=t%p;
		out+=m[t];
		m[t]++;
		ten=(ten*10)%p;
	}
	cout<<out;
	}
	else
	{
		ll out=0;
		for(ll i=0;i<n;i++)
		{
			if(a[i]%p==0)
			{
				out+=i+1;
			}
			
		}
		cout<<out;
	}
	return 0;
}
