#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define ll long long
#define P pair<int,int>
#define PI 3.141592653589793
const int INF = 1000000;

int main() {
	string S;
	cin >> S;
	int N = S.size();
	vector<int> mod(N),d(N);
	rep(i, N) {
		if (i == 0) {
			d[i] = 1;
			continue;
		}
		d[i] = 10 * d[i - 1];
		d[i] %= 2019;
	}
	rep(i, N) {
		int a = S.at(N - 1 - i) - '0';
		if (i == 0) {
			mod[i] = a;
			//cout << mod[i] << endl;
			continue;
		}
		mod[i] = (a * d[i]) % 2019 + mod[i-1];
		mod[i] %= 2019;
		//cout << mod[i] << endl;
	}
	vector<int> cnt(2019);
	cnt[0]++;
	rep(i, N) {
		cnt[mod[i]]++;
	}
	ll ans = 0;
	rep(i, 2019) {
			ans += cnt[i] * (cnt[i] - 1) / 2;
	}
	cout << ans;
}
