#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
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;}
const ll INF = 1LL<<60;
const ll M = 1000000007;
ll mpow(ll a,ll b){ll res=1;while(b!=0){if(b&1)res=res*a%M;a=a*a%M;b=b>>1;}return res;}
ll mcomb(ll n,ll k){if(k>n/2)return mcomb(n,n-k);ll res=1;for(ll i=0;i<k;i++){res=res*(n-i)%M;res=res*mpow(k-i,M-2)%M;}return res;}
/*template*/
 
ll hpow(ll a,ll b){
  ll res=1;
  while(b!=0){
    if(b&1)res=res*a%2019;
    a=a*a%2019;
    b=b>>1;
  }
  return res;
}
 
int main()
{
  string s;cin>>s;
  ll n=s.length();
  ll a[2019]={0};
  ll hoge=0;
  for(ll i=0;i<n;i++){
    hoge=(hoge+(s[n-1-i]-'0')*hpow(10,i))%2019;
    a[hoge]++;
  }
  ll ans=0;
  for(ll i=0;i<2019;i++){
    ans+=a[i]*(a[i]-1)/2;
  }
  cout<<ans+a[0]<<endl;
  return 0;
}