#include <bits/stdc++.h>
#define rep(i,a,b) for(ll i=ll(a);i<ll(b);i++)
#define irep(i,a,b) for(ll i=ll(a);i>=ll(b);i--)
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }
#define pb push_back
#define mp make_pair
#define F .first
#define S .second 
using ll=long long;
using ld=long double;
const ll INF = 1LL<<60;
const ll mod=1e9+7;
using namespace std;
ll GCD(ll a, ll b) { return b ? GCD(b, a%b) : a; }
ll x10(ll b,ll k){
    if(k==0)return b;
    else {
        b*=10;
        b%=2019;
        b=x10(b,k-1);
    }
}
ll dp[220000];
map<ll,ll> p;
int main(){
    ll cnt,ans=0;
    string s,t;
    cin>>s;
    long sl=s.length();
    t=s[sl-1];
    dp[0]=stoll(t)%2019;
    rep(i,1,sl+1){
        ll y=s[sl-i-1]-'0';
        dp[i]=(dp[i-1]+x10(y,i))%2019;
    }
    rep(i,0,sl+1)p[dp[i]]++;  
    for(map<ll,ll>::iterator it=p.begin();it!=p.end();it++){
    ll ff=it->second;
    ans+=ff*(ff-1)/2;
    if(it->first==0)ans+=ff;
    }
    cout<<ans;
}