#include<bits/stdc++.h>
#define rep(i, n) for (ll i = 0; i < (ll)(n); ++i)
#define repk(i,k,n) for (ll i = k; i < (ll)(n); ++i)
#define MAX 500000001000000000
#define MOD 1000000007
typedef long long  ll;

using namespace std;

ll ans;
map<int, int> t;

int main() {
	cin.tie(0);
	ios::sync_with_stdio(false);

	string s;
	cin >> s;

	int n = s.size();

	vector<int> num(n);
	rep(i,n) {
		num[i] = s[i] - '0';
	}
	
	vector<ll> snum(n);
	snum[n-1] = num[n-1];
	repk(i, 1, n) {
		snum[n-i-1] = snum[n-i] + num[(n-1)-i] * pow(10, i);
	}

	t[0]++;
	rep(i, n) {
		t[(snum[i] % 2019)]++;
	}

	for (auto p : t) {
		ans += p.second * (p.second - 1) / 2;
	}

	cout << ans << endl;

	return 0;
}