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

int main()
{

	string s;
	cin >> s;

	int len=s.size();
	map<int,int> modulocount;
	int current_mod=0;
	int mod10n=0;

	modulocount[0]=1;
	mod10n=1;
	for (int i=len-1;i>=0;--i)
	{
		current_mod+=(mod10n*(s[i]-'0'));
		while (current_mod>=2019)
		{
			current_mod-=2019;
		}

		modulocount[current_mod]++;
		//fprintf(stderr,"i:%d current:%d mod10n:%d\n",i,current_mod,mod10n);

		mod10n*=10;
		while (mod10n>=2019)
		{
			mod10n-=2019;
		}
	}

	int count=0;
	for (pair<int,int> p: modulocount)
	{
		int combination=p.second*(p.second-1)/2;
		//fprintf(stderr,"mod %d, count %d, combination %d\n",p.first,p.second,combination);
		count+=combination;
	}
	cout << count << endl;
}


