#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const ll MOD = 1e9 + 7;
const int inf = 1e9;
const ll INF = 1e18;
const double pi = 3.14159265358979323846;
#define rep(i,n) for(ll i=0;i<n;i++)

int main(){
	string s;cin>>s;
	int n=s.size();int keep[2019]={};
	//余りを累積和すればいける
	keep[0]=1;
	int a[n+1];a[0]=0;//その桁が追加されるといくつ余りが増えるか
	ll md=2019;
	int ans=0;
	int j=1;
	for(int i=0;i<n;i++){//下から何桁取るか考える
		ll t=s[n-i-1]-'0',tt=s[n-i-1]-'0';
		t=t*j%md;
		a[i+1]=(t+a[i])%md;
		//数え上げ
		int l=a[i+1];
		keep[l]++;
		//cout<<keep[l]<<" "<<keep0[l]<<"\n";
		
		if(tt!=0) ans+=keep[l]-1;
		//cout<<a[i+1]<<"\n";
		j*=10;
	}

	cout<<ans<<"\n";
}