#include<iostream>
#include<cstdio>
#include<cstring>
#include<algorithm>
using namespace std;
int Mod=2019;
typedef long long lol;
lol ans,c[2020],a[200005];
char s[200005];
int n,pow10;
int main()
{
	scanf("%s",s);
	n=strlen(s);
	pow10=1;
	for (int i=n-1;i>=0;i--)
	{
		a[i]=(a[i+1]+(s[i]-'0')*pow10%Mod)%Mod;
		pow10=pow10*10%Mod;
	}
	c[0]++;
	for (int i=n-1;i>=0;i--)
	{
		ans+=c[a[i]];
		//printf("%d %d %d\n",i,a[i],c[a[i]]);
		c[a[i]]++;
	}
	cout<<ans;
} 