#include <bits/stdc++.h>
#define rep(i,n) for (ll i = 0; i < n; ++i)
using namespace std;
using ll = long long;
using ull = long long unsigned;
using P = pair<ll,ll>;
const int MAX=1001001001;


int main(){
	ios::sync_with_stdio(false);
	cin.tie(0);
	string S;
  cin>>S;
	ll n=S.size();
	vector<ll>s(n);
	rep(i,n){
		s[i]=S[i]-'0';
	}
	//あまりの数
	vector<ll> p(n+1,0);
	map<ll,ll>mp;
	p[n-1]=s[n-1]%2019;
	//cout<<p[n-1]<<endl;
	rep(i,n-1){
		p[n-2-i]=s[n-2-i];
		rep(j,i+1){
		//	cout<<j<<endl;
			p[n-2-i]*=10;
			p[n-2-i]%2019;
		}

	//	p[n-2-i]+s[n-1-i]);
	p[n-2-i]+=p[n-1-i];
		p[n-2-i]=p[n-2-i]%2019;
	//	cout<<p[n-2-i]<<endl;

		mp[p[n-2-i]]++;
	}
	mp[0]++;
	int ans=0;
//cout<<mp[44]<<'m'<<endl;
	rep(i,2019){
		int temp=mp[i];
		ans+=temp*(temp-1)/2;
	//	cout<<temp<<endl;
	}

	cout<<ans;





}
