#include <bits/stdc++.h>
using namespace std;

int main() {
  string S;
  int int_S;
  string subspace_S;
  int int_sub_S;
  int size;
  int i = 0, j = 3, count = 0;
  
  cin >> S;
  int_S = atoi(S.c_str());
  size = (int)S.length();
  
  if(int_S < 2019){
  	cout << 0 << endl;	
  }else{
    for(i = 0; i < size-3; i++){
    	for(j = i+4; j <= size; j++){
        	subspace_S = S.substr(i, j-i);
        	int_sub_S = atoi(subspace_S.c_str());
          	if(int_sub_S % 2019 == 0){
              count++;
            }
        }
    }
    cout << count << endl;
  }
}
