#include <iostream>
#include <string>
#include <sstream>

using namespace std;

int main(){
  string s;
  cin >> s;
  int count = 0;
 
  for (int i = 0; i < s.size() - 3; i++){
    for(int j = 4; j <= s.size()-i; j++){
      string ss = s.substr(i, j+i-1);
      int x = 0;
      stringstream str(ss);
      str >> x;
      if (x % 2019 == 0){
        count++;
      }
    }
  }
  cout << count  << "\n";
}
