#include <stdio.h>
#include <string>
#include <iostream>
#include <sstream>
using namespace std;

int main()
{
  string s;
  int ans = 0, i, j;
  istringstream ss1;
  int p1;
  cin >> s;
  for(i = 0; i < s.size()-3; i++) {
    for(j = i+3; j < s.size(); j++) {
      ss1 = istringstream(s.substr(i,j-i+1));
  	  ss1 >> p1;
      if(p1 % 2019 == 0) {
        ans++;
      }
    }
  }
  cout << ans << "\n";
  return 0;
}