#include <bits/stdc++.h>

#define rep(i,n) for(int i=0;i<n;i++)
#define repn(i,n) for(int i=1;i<=n;i++)
#define LL long long
#define pii pair <int,int>
#define fi first
#define se second
#define pb push_back
#define mpr make_pair

using namespace std;

const LL MOD=1e9+7;

string s;
LL dp[2][2030],ne[2030][20],ans=0;

int main()
{
	cin>>s;
	rep(i,2019) repn(j,9) ne[i][j]=(i*10+j)%2019;
	dp[0][0]=1;
	rep(i,s.size())
	{
		int tmp=(i&1),tmp2=tmp^1;
		memset(dp[tmp2],0,sizeof(dp[tmp2]));
		dp[tmp2][0]=1;
		rep(j,2020) dp[tmp2][ne[j][s[i]-'0']]+=dp[tmp][j];
		ans+=dp[tmp2][0]-1;
	}
	cout<<ans<<endl;
	return 0;
}