#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define rep(i,n) for(ll i=0;i<n;i++)


int main(){
	string s;
	cin >> s;
	int s_size = s.size();
	ll count = 0;
	ll test = 0;
	if(s_size-3>0){
 	 rep(i,s_size-3){
			rep(j,s_size-i-3){
			test = stoll(s.substr(i,j+4));
			if(test != 0 && test % 2019 == 0){count++;}
	}
	}
	}
	cout << count << endl;
	return 0;
}
