#include<bits/stdc++.h>
using namespace std;
#define FASTIO ios_base::sync_with_stdio(false), cin.tie(0), cout.tie(0);
#define ll long long
#define pb push_back
#define F first
#define S second
#define ld long double
#define vi vector<ll>
const int N = 1e9 + 5;

void solve() {
	string s;
	cin >> s;
	vi MOD(2019, 0);
	MOD[0] = 1;
	ll n = 0, a = 1;
	for (int i = s.size() - 1; i >= 0; i--) {
		ll cur = s[i] - '0';
		n = (n + (a * cur) % 2019) % 2019;
		//cout << a << " " << n << endl;
		a *= 10;
		a %= 2019;
		MOD[n]++;
	}
	ll ans = 0;
	for (auto c : MOD) ans += (c * (c - 1)) / 2;
	cout << ans;
}

int main() {

	FASTIO;
/*
#ifndef ONLINE_JUDGE
	// for getting input from input.txt
	freopen("input.txt", "r", stdin);
	// for writing output to output.txt
	freopen("output.txt", "w", stdout);
#endif
*/
	int t = 1;
	//cin >> t;
	while (t--) {
		solve();
	}
	return 0;
}