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


int main() {
	string S;
	cin >> S;

	u64 k = 2019;
	u64 ans = 0;
	
	for(u64 b=0; b<S.size(); b++) {
		u64 tdiv = 0;
		for(u64 e=b; e<S.size(); e++) {
			tdiv = tdiv * 10 + S[e] - '0';
			bool r = (tdiv != 0);
			
			tdiv = tdiv - (tdiv / k) * k;
			if(r && tdiv == 0) {
				ans++;
			}
		}
	}

	cout << ans;

}
