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

typedef long long ll;

ll power(ll x, ll y, ll M)
{
    ll res = 1;
    x = x%M;
    while (y)
    {
        if (y&1) res = ((res%M)*(x%M))%M;

        y>>=1;
        x = ((x%M)*(x%M))%M;
    }
    return res;
}

int main(){

    ios::sync_with_stdio(false);
    cin.tie(0);

    string s;
    cin >> s;

    int n = s.length();    

    if(n<=3) cout << 0 << "\n";

    else{
        
        ll count=0;

        unordered_map<ll, ll> umap;

        ll x;
        ll y=0;
        string p;
        for(int i=0; i<n; i++){

            p=s[i];
            int d = stoi(p);
            x = (power(10,n-i-1,2019)*(d))%2019;
            y = ((y%2019)+(x%2019))%2019;
            
            if(umap.find(y%2019)!=umap.end()) count+=umap.at(y%2019);
            umap[y%2019]++;
        }

        cout << count << "\n";

    }

    return 0;
}
