#include<iostream>
#include<string>
using namespace std;
int main(){
  string s;cin>>s;
  int n=s.size();
  int c=0;
  int b=1;
  int* r=new int[n+1];
  int* cc=new int[n]{};
  r[n]=0;
  for(int i=n-1;i>=0;i--){
    r[i]=(r[i+1]*b+(s[i]-'0'))%2019;
    b=b*10%2019;
    c+=cc[i];cc[r[i]]++;
  }
  cout << c << endl;
  return 0;
}  
