#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)

typedef long long ll;
typedef pair<int, int> P;

const ll mod =  1000000007;  //出力は (ans % mod + mod) % mod  (負の剰余を正にする)
const int inf = 1e9;
const long long INF = 1LL << 60;   // INF = 1152921504606846976

ll pow_k(ll x,ll n){  // xのn乗 (mod m)
    ll res = 1;
    if(n > 0){
        res = pow(x,n / 2);
        if(n % 2 == 0){
            res = (res * res);
        }else{
            res = (((res * res)) * x);
        }
    }
    return res;
}

int main()
{
    string s; cin >> s;
    ll n = s.size();
    ll a[n];
    reverse(s.begin(),s.end());
    a[0] = s[0] - '0';
    for(ll i = 0; i < n-1; i++){
        a[i+1] = ((ll)(s[i+1]-'0') * pow_k(10,i+1) + (a[i])) % 2019;
        //a[i+1] = ((a[i]+ (s[i+1]-'0'))*pow(10,i)) % 2019);
    }
    map<ll,ll> mp;
    mp[0] = 1;
    rep(i,n){
        mp[a[i]]++;
    }
    ll ans = 0;
    rep(i,mp.size()){
        if(mp[i] > 1){
            ll tmp = mp[i];
            ans += (tmp * (tmp-1))/2;
        }
    }
    cout << ans << endl;
}
