#include<iostream>
#include<string>
//#include<chrono>

using namespace std;

int main()
{
	//auto start = chrono::steady_clock::now();
	string S;
	int count = 0;

	cin >> S;

	for (int j = S.length() - 1; j >= 3; j--)
	{
		int sum = 0;
		int base = 1;
		for (int i = j; i >= 0; i--)
		{
			sum += (S[i] - '0') * 1;
			sum %= 2019;
			base *= 10;
			base %= 2019;
			count += (sum == 0);
		}
	}
	
	cout << count << endl;

	//auto end = chrono::steady_clock::now();
	//chrono::duration<double> d = end - start;
	//cout << d.count() << endl;
	return 0; 
}