/*
(1)for binary shift operator always use 'LL' 1LL<<63

*/
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#include <ext/pb_ds/assoc_container.hpp> 
#include <ext/pb_ds/tree_policy.hpp> 
using namespace __gnu_pbds; 
  
#define ordered_set_pair tree<pair<ll,ll>, null_type,less<pair<ll,ll>>, rb_tree_tag,tree_order_statistics_node_update> 
#define ordered_set tree<int, null_type,less<int>, rb_tree_tag,tree_order_statistics_node_update> 
#define ordered_multiset tree<int, null_type,less_equal<int>, rb_tree_tag,tree_order_statistics_node_update> 
#define Luv(...) [&] (auto &&u, auto &&v) { return __VA_ARGS__; }
  ll powe(ll a,ll b,ll c){
    if(b==0)
    return 1;
    if(b%2==0)
    {
        ll z=powe(a,b/2,c);
        return (z*z)%c;
    }
    else return ((a%c)*powe(a,b-1,c))%c;
}
int main() {
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	ll n,p;//cin>>n>>p;
	ll i,j;
	ll sum=0;
	map<ll,ll> ma;
	string s;cin>>s;
	n=s.size();p=2019;
	
	ll prev=0;
	ma[0]=1;
	for(j=n-1;j>=0;j--){
		prev=(prev+(s[j]-'0')*powe(10,n-j-1,p))%p;
		sum+=ma[prev];
		ma[prev]++;

	}
	cout<<sum;

	return 0;
} 