#include <iostream>
#include <string>
#include <iomanip>
#include <ios>
using namespace std;
int main(void){
  string s;
  cin >> s;
  
  int l = s.length();
  long long ans = 0;
  
  for(int i=0;i<l-4;i++){
    long long n = s[i] - '0';
    for(int j=i+1;j<l;j++){
      n = (n * 10 + (s[j] - '0')) % 2019;
      if(n == 0) ans++;
    }
  }
  
  cout << ans << endl;
  
  return 0;
}
