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

int main(){
	string S;
	cin >> S;
	int s=S.size();
	vector<int> N(s);
	for(int i=0;i<s;i++)N[i]=S[i]-'0';
	
	vector<long long> p(2019,0);
	
	int b=1;
	int c=0;
	for(int i=0;i<s;i++){
		c+=N[s-i-1]*b;
		c%=2019;
		p[c]++;
		b*=10;
		b%=2019;
	}
	
	long long ans=0;
	for(int i=0;i<2019;i++){
		if(i==0)ans+=p[i]*(p[i]+1)/2;
		else ans+=p[i]*(p[i]-1)/2;
	}
	cout << ans << endl;
	return 0;
}