#include <bits/stdc++.h>
using namespace std;

typedef long long ll;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;

string S;
int N;
int rn[2019];

int main(){
	cin>>S; N = S.size();
	memset(rn, 0, sizeof(rn));
	int r = S[N-1] - '0';
	rn[0] = 1;
	int r10 = 1;
	rn[r] = 1;
	ll res = 0;
	for(int i=N-2; i>=0; i--){
		r10 = (r10 * 10) % 2019;
		r = (r + (S[i] - '0') * r10) % 2019;
		//cout<<i<<" "<<r<<" "<<rn[r]<<endl;
		res += rn[r];
		rn[r]++;
	}

	cout<<res<<endl;
	return 0;
}
