#include<algorithm>
#include<iostream>
#include<vector>
#include<string>
#include<queue>
#include<stack>
#include<cmath>
#include<list>
#include<set>
#include<map>

using namespace std;
long long MOD = 1000000007LL;
#undef INT_MIN
#undef INT_MAX
#define INT_MIN -2147483648
#define INT_MAX 2147483647
#define endl "\n"

int main() {
	string s;
	cin >> s;
	int count = 0;
	for (int i = 0; i < s.length() - 1; ++i) {
		unsigned long long buf = 0;
		for (int j = i; j < s.length(); ++j) {
			buf *= 10 % MOD;
			char c = s[j];
			buf += (c - 0x30);
			if (buf % 2019 == 0) {
				++count;
			}
		}
	}

	cout << count << endl;
	return 0;
}

