//codeforces
//
#include "bits/stdc++.h"
using namespace std;
using int64 = long long;
int main()
{
  string s;
  cin>>s;
  if(s.size()<=4)
    cout<<0;
  else{
    int n=s.size();
    //int64 rs=0;
    int t=0;
    for(int i=0; i<n; i++){
      int r=0;
      for(int j=i; j<n; j++){
        r = r*10 + s[j] - '0';
        if(r%2019==0)
          t++;
        r %= 2019;
      } 
    }
    cout<<t<<endl;
  }
	return 0;
}
