#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define Rep(i, m,n) for (int i = m; i < (int)(n); i++)

int main(){
 int N; cin>>N; 
  vector<int>A;
  
  for(i,(N+10)/10=1,i++){A.at(i)=N&10; N=N/10;}
  reverse(A.begin(),A.end());
  
  
  rep(i,A.size()-1){ int S=A.at(i);
  Rep(k,i+1,A.size()){

    S=S*10+A.at(k);
    if(S%2019==0){ans++;}
  }
  }
  cout<<ans<<endl;
}