#include <iostream>
#include <string>
#include <vector>

using namespace std;
using ll = long long;
using vi = vector<int>;
#define rloop(i, n) for (int i = (int)n - 1; i >= 0; i--)

long long modpow(long long a, long long n, long long mod) {
    long long res = 1;
    while (n > 0) {
        if (n & 1) res = res * a % mod;
        a = a * a % mod;
        n >>= 1;
    }
    return res;
}

int main() {
    string s; cin >> s;
	vi a(2019, 0);
	a[0] = 1;
	int t = 0;
	rloop(i, s.size()) {
		t = (modpow(10, s.size() - i - 1, 2019) * (s[i] - 48) + t) % 2019;
		a[t]++;
	}
	ll sum = 0;
	loop(i, 2019) {
		sum += a[i] * (a[i] - 1) / 2;
	}
	cout << sum << endl;
}
