#include<bits/stdc++.h>
using namespace std;

// macro
#define rep(i,n) for(i=0;i<n;i++)
#define ll long long
#define all(v) v.begin(), v.end()

// code starts
int main()
{
  string s;cin>>s;
  int n=s.size();
  vector<int> num(n);
  int i;
  rep(i,n)num[i]=s[i]-'0';
  vector<int> us(n+1,0);
  vector<int> count(2019,0);
  int ans=0;
  count[0]=1;
  int ks=1;
  for(i=n-1;i>=0;i--)
  {
    us[i]=(us[i+1]+num[i]*ks)%2019;
    ans+=count[us[i]];
    count[us[i]]++;
    ks=(ks*10)%2019;
  }
  cout<<ans<<endl;
}

