#include <iostream>
#include <cmath>
#include <string>
int main()
{
	std::string S;
	std::cin >> S;
	unsigned int zero = 0;
	int digit = std::log10(std::stoll(S, &zero, 10)) + 1;
	int sum = 0;
	for (int i = 0; i < digit; i++)
	{
		for (int j = i + 1; j <= digit; j++) 
		{
			std::string str = S.substr(i, j - i);
			long long ext = std::stoll(str, &zero, 10);
			if (ext == 0) continue;
			long long res = ext % 2019;
			if (res == 0) {
				sum++;
			}
			
		}
	}
	std::cout << sum;
}