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

int main() {
  string S;
  cin >> S;
  ll ans = 0;
  ll N = S.size();
  //iは桁数
  for (ll i = 4; i <= N; i++) {
    //jは最初の場所
    for (ll j = 0; j <= N-i; j++) {
      ll num;
      num = stoll(S.substr(j, i));
      if (num % 2019 == 0) {
        ans++;
      }
    }
  }
  cout << ans << endl;
  return 0;
}

