#include <bits/stdc++.h>

#define REP(i, n) for(int (i)=0;(i)<(n);++(i))
#define REPV(iter, v) for(auto (iter)=(v).begin(); (iter)!=(v).end();++(iter))
#define ALL(v) (v).begin(),(v).end()

#define MOD 1000000007

using namespace std;

typedef long long ll;

int main()
{
    string S;
    cin >> S;
    
    ll n = S.size();
    vector<ll> T(n + 1, 0);
    ll m = 2019;
    T[n] = 0;
    ll r = 1;
    vector<ll> countMod(m, 0);
    countMod[T[n]]++;
    REP(i, n)
    {
        T[n - i - 1] = ((S[n - i - 1] - '0') * r + T[n - i]) % m;
        countMod[T[n - i - 1]]++;
        r *= 10;
        r = r % m;
    }
    ll ans = 0;
    REP(i, m) ans += countMod[i] * (countMod[i] - 1) / 2;

    cout << ans << endl;
}
