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

int main()
{
	auto&& as_int = [] (char c) { return(int) c - '0'; };
	string s;
	cin >> s;
	size_t n = s.length();
	map<int, int> cnt {};
	vector<int> t(n+1, 0);
	{

		t[n] = 0;
		int factor = 1;

		for (size_t i = n; i > 0; i--)
		{
			t[i - 1] = (t[i] + as_int(s[i - 1]) * factor % 2019) % 2019;
			factor = factor * 10 % 2019;
		}
		for (size_t i = 0; i < n+1; i++)
		{
			auto&& tmp = t[i];
			for (size_t j = i; j < n ; j++)
			{
				if (tmp == t[j + 1])
				{
					cnt[tmp]++;
				}
			}
		}
	}
	int nn = 0;
	for (auto& i : cnt)
	{
		nn += i.second;
	}
	cout << nn << endl;
}