#include <bits/stdc++.h>
using namespace std;
int fun(string s)
{
  int n=s.size();
  int numMultiples=0;
  int seenRemainders[n+1] ={0};
  for (int i=0;i<n;i++)
  {
    int remainder=0;
    int prefixesFound = 0;
    for (int j=i;j<n;j++)
    {
      remainder = (10 * remainder + (s[j]-'0')) % 2019;
      if (seenRemainders[j]==remainder)
        break;
      seenRemainders[j]=remainder;
    }
    if(remainder==0)
      prefixesFound++;
    numMultiples += prefixesFound * (prefixesFound + 1) / 2;
  }
  return numMultiples;
}
int main()
{
  string s;
  cin>>s;
  int n=s.size();
  cout<<fun(s)+1;
  return 0;
}