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

int main(){
  string str;
  int count = 0;
  cin >> str;
  for(int i=0;i<=str.length()-4;i++){
      for(int j=i+4;j<=str.length();j++){
          long long wareruka = stoll(str.substr(i,j));
          
          if(wareruka % 2019 == 0){
              count++;
          }
      }
  }
  cout << count <<endl;
}