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

int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  cout << fixed << setprecision(18);
  
  string s;
  cin >> s;
  ll n = s.size();
  
  ll ans = 0;
  for(ll i = 0; i <= n-1-4; i++) {
    ll I = stoll(s.substr(i));
    for(ll j = i+4; j <= n; j++) {
      ll J = (j==n ? 0LL : stoll(s.substr(j)) );
      if((I-J) % 2019 == 0) ans++;
    }
  }
  
  cout << ans << "\n";
}