#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
using vll = vector<ll> ;
#define all(v) v.begin(),v.end()

ll modpow(ll a,ll b,ll mod){
  ll ans=1%mod;
  while(b){	
    if(b&1) ans=(ans*a)%mod;
    a=(a*a)%mod;
    b=b>>1; 
  }
  return ans;
  }

int main(){
  string S;cin>>S;
  vll tmp_mod(S.size(),0);
  tmp_mod[S.size()]=0;
  ll dg = 0;
  for(ll i=S.size()-1;i>=0;--i){
    ll num = S[i]-'0';
    tmp_mod[i] = (num*modpow(10,dg,2019) + tmp_mod[i+1]) % 2019;
    dg++;
  }
  map<ll,ll> m;
  for(ll i=S.size();i>=0;--i){
    m[tmp_mod[i]]++;
  }
  ll ans=0;
  for(auto& x : m){
    ll cnt = ll(x.second);
    if(x.second<=1) continue;
    else ans += (cnt-1)*cnt/2;
  }
  cout << ans << endl;
}