#include <bits/stdc++.h>
using namespace std;

typedef long long ll;

int bin_pow(int b, int e) {
    if(e == 0) return 1;

    int p = bin_pow(b, e / 2);
    p *= p;
    p %= 2019;

    if(e & 1) return p * b % 2019;
    else return p;
}

int main() {
	ios_base::sync_with_stdio(false);

    string s;
    cin >> s;

    int n = s.size();
    vector<int> suf(n + 1), cnt(2020);
    cnt[0]++;

    int ans = 0, e = 0;

    for(int i = n - 1; i >= 0; i--) {
        suf[i] = (((s[i] - '0') * bin_pow(10, e++)) % 2019 + suf[i + 1]) % 2019;

        for(int j = 0; j <= 2018; j++) {
            if((suf[i] - j + 2019) % 2019 == 0) {
                ans += cnt[j];
            }
        }

        cnt[suf[i]]++;
    }

    cout << ans << endl;
}

