#include<iostream>
#include<cstdio>
#include<cstring>
#include<cmath>
#include<algorithm>
#include<queue>
#include<stack>
#include<vector>
#include<map>
using namespace std;

int read(){
	int x=0,f=1;
	char c=getchar();
	while(!isdigit(c)){if(c=='-')f=-1;c=getchar();}
	while(isdigit(c)){x=(x<<3)+(x<<1)+c-48;c=getchar();}
	return x*f;
}

int k,m,n,mod=2019;
char c[200010];
map<int,int> M;
vector<pair<int,int> > ans;
int fpm(int x,int y){
	int sum=1;
	while(y){
		if(y&1)sum=1ll*sum*x%mod;
		x=1ll*x*x%mod;
		y>>=1;
	}
	return sum;
}
int main(){
	scanf("%s",c+1);
	n=strlen(c+1);
	int num=0;
	M[0]=n+1;
	for(register int i=n;i>=1;i--){
		(num=num+(c[i]-'0')*fpm(10,n-i))%=mod;
		//cout<<i<<" "<<num<<" "<<M[num]<<endl;
		if(M[num])ans.push_back(make_pair(i,M[num]-1));
		M[num]=i;
	}
	sort(ans.begin(),ans.end());
	m=0;long long anss=0;
	for(register int i=0;i<ans.size();i++){
		if(!i){m++;continue;}
		if(ans[i].first==ans[i-1].second+1)m++;
		else anss+=1ll*m*(m+1)/2;
	}
	anss+=1ll*m*(m+1)/2;
	printf("%lld\n",anss);
	return 0;
}