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

int main() {
  string S;
  cin >> S;
  int ans = 0;
  rep(i,S.size()-3){
    for(ll j=i+4; j < S.size()+1;j++){
      if(stoll(S.substr(i,j))%2019 == 0) ans++;
    }
  }
  cout << ans << endl;
}
