#include <iostream>
#include <map>
#include <vector>
#include <string>
#include <math.h>
#include <algorithm>
#include <functional>
#define int long long
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
using namespace std;
constexpr int MOD = 1000000007;
constexpr int INF = numeric_limits<int>::max() / 2;
typedef pair<int, int> P;
using Graph = vector<vector<int>>;



signed main() {
	cin.tie(nullptr);
	ios::sync_with_stdio(false);

	int P, N;
	string S;
	cin >>S;
	N = S.size();
	P = 2019;
	int ans = 0;
	if (P == 2) {
		rep(i, N) {
			if (S[i] == '0' || S[i] == '2' || S[i] == '4' || S[i] == '6' || S[i] == '8') ans += i + 1;
		}
	}
	else if (P == 5) {
		rep(i, N) {
			if (S[i] == '0' || S[i] == '5') ans += i + 1;
		}
	}
	else {
		map<int, int> mp{};
		int num = 0, kai = 1;
		mp[0]++;
		for (int i = N - 1; i >= 0; i--) {
			num += (S[i] - '0') * kai;
			num %= P;
			mp[num]++;
			kai = (kai * 10) % P;
		}
		for (auto p : mp) {
			int n = p.second;
			ans += n * (n - 1) / 2;
		}
	}
	cout << ans << endl;
}