#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define lvector vector<ll> 
#define lque queue<ll>
#define lpque priority_queue<ll>
#define dlpque priority_queue<ll,lvector,greater<ll>>
#define P pair<ll,ll>
#define ALL(a) (a).begin(),(a).end()
#define rep(i,n) for(ll (i)=0; (i)<(n); ++(i))
#define print(a) cout << (a) << endl

int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  string s;cin>>s;
  ll n=s.length(),ans=0,mod=2019,digit=1,val=0;
  lvector mods(2019,0);
  for(ll pos=n-1;pos>-1;pos--) {
    val=(val+(s[pos]-'0')*digit)%mod;
    digit=(digit*10)%mod;
    mods[val]++;
  }
  ans+=mods[0];
  for(ll i:mods) ans+=i*(i-1)/2;
  print(ans);
  return 0;
}