#include<bits/stdc++.h>
using namespace std;

#define int long long
#define pb push_back
#define ff first
#define ss second
#define all(a) a.begin(), a.end()

const int mod = 1e9+7;
const int inf = 2e18;

int modularExponentiation(int base,int exponent,int modulo)
{
	if(exponent==0)
		return 1;
	
	
	if(!(exponent&1))
	{	
		int res = modularExponentiation(base,exponent/2,modulo);
		return (res*res)%modulo;
	}
	else
	return ((base%modulo)*modularExponentiation(base,exponent-1,modulo))%modulo;
}


int32_t main()
{	
	ios_base::sync_with_stdio(0);
	cin.tie(0);
	cout.tie(0);

	string s;
	cin>>s;

	int n = s.size();

	int mp[2029]={0};	


	int k = 0;
	int pre[n+1]={0};

	int m = 2019;
	//pre[0]=1;
	for(int i=n-1;i>=0;i--)
	{
		int curr_digit = s[i]-'0';
		int curr_pow = modularExponentiation(10,k,m);

		int t1 = ((curr_pow%m)*(curr_digit%m))%m;
		int t2 = ((i+1)<n)?pre[i+1]:0;

		pre[i] = (t1%m+t2%m)%m;
		k++;
	}
	mp[0]++;
	for(int i=0;i<n;i++)
	{
		mp[pre[i]]++;
		//cout<<pre[i]<<" ";
	}

	int ans = 0;

	for(int i=0;i<2019;i++)
	{
		int val = mp[i];
		ans+=(val*(val-1))/2;
	
	}
	cout<<ans<<'\n';
	return 0;
}	