//	Author : amnptl 
//	   Godbless
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define NeedForSpeed() ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
#define mod (2019) // not 1e9+7

ll power(ll base, ll exponent, ll modx = mod) 
{
    ll ret = 1 % modx; base %= modx;
    while(exponent) 
    {
        if(exponent & 1) ret = (ret * base) % modx;
        base = (base * base) % modx; exponent >>= 1;
    }
    return ret;
}

int main()
{
	NeedForSpeed();
	string s; cin>>s; int n = s.size(); int a[n+1];
	for(int i=0; i<n; i++) a[i+1] = (s[i] - '0');
	ll num[n+1]; num[n] = a[n]; map<int,int> m; m[0]++; ll ans = 0;
	for(int i=n-1; i>0; i--)
	{
		num[i] = (power(10,n-i)*a[i])%mod;
		num[i] = (num[i]+num[i+1])%mod;
		m[num[i]]++;
	}
	for(auto x : m) ans += ((x.second)*(x.second-1))/2;
	cout<<ans<<endl;
	return 0;
}