# include <bits/stdc++.h>

using namespace std;

int main() {
    string s;
    cin >> s;
    map <int, int> mp;
    long long ans = 0;
    int pw = 1, pf = 0;
    mp[0] = 1;
    for (int i = (int)s.size() - 1; i >= 0; i--) {
        pf = (pf + pw * (s[i] - '0')) % 2019;
        ans += mp[pf];
        mp[pf]++;
        pw = (pw * 10) % 2019;
    }
    cout << ans << endl;
}
