#include <bits/stdc++.h>
using namespace std;
#define ci(a) cin>>(a)
#define co(a) cout<<(a)<<endl
#define rep(i,n) for(int i=0;i<n;i++)

long long make_num(string s,int sta,int len)
{
	long long num=0;
	for(int i=0;i<len;i++){
		num*=10;
		num+=(s.at(sta-len+i)-'0');
	}
	return num;
}
int main()
{
	string S;
	cin>>S;
	int size=S.size();
	long long num;
	int mod[2019]={0};
	rep(i,size-3){
		num=make_num(S,size,4+i);
//		cout<<(num%2019)<<endl;
		mod[num%2019]++;
	}
	int cnt=mod[0];
	rep(i,2019){ if(i>0&&mod[i]>0&&mod[i]%2==0)cnt++;}
	co(cnt);
	return 0;
}
