#define _USE_MATH_DEFINES
#include <math.h>
#include <iostream>
#include <iomanip>
#include <cstdlib>
#include <algorithm>
#include <numeric>
#include <stdio.h>
#include <vector>

using namespace std;
typedef long long ll;

#define rep(i, n) for(ll i = 0; i < (ll)(n); i++)

ll modpow(ll a,ll n,ll m) {
    if(n==1) return a%m;
    if(n%2==1) return (a*modpow(a,n-1,m))%m;
    ll b = modpow(a,n/2,m)%m;
    return (b*b)%m;
}

int main() {

    ll mod = 2019;
    string S;
    cin >> S;
    ll N = S.length();
    ll A[N];
    rep(i,N){
        if(i==0) A[N-1] = S[N-1]-48;
        else A[N-1-i] = ((ll(S[N-1-i])-48)*modpow(10,i,mod))%mod;
    }
    ll B[N];
    rep(i,N){
        if(i==0) B[N-1] = ll(S[N-1])-48;
        else B[N-1-i] = (B[N-i]+A[N-1-i])%mod;
    }
    sort(B,B+N);
    ll out = 0;
    ll cnt = 0;
    rep(i,N-1){
        if(B[i]==0) out++;
        else{
            if(B[i]==B[i+1]) cnt++;
            else if(cnt>0){
                out += cnt*(cnt+1)/2;
                cnt = 0;
            }
            if(i==N-2&&cnt>0) out += cnt*(cnt+1)/2;
        }
    }
    cout << out << endl;
    return 0;
}
