#include <bits/stdc++.h>

#define ll long long
#define ull unsigned long long

using namespace std;

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

	ll N = S.size();
	ll MOD = 2019;
	ll ans = 0;
	for (int ii = N-1; ii > 0; --ii){
		ll val = S[ii] - '0';
		ll rem = val % MOD;
		ll base = 10;
		for (int jj = ii - 1; jj >= 0; --jj){
			ll v = (S[jj] - '0') * base;
			rem = (rem + v % MOD) % MOD;
			if (rem == 0) {
				ans++;
				break;
			}
			base = (base * 10) % MOD;
		}
	}

	cout << ans << "\n";


	return 0;
}
