#include <bits/stdc++.h>
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
using namespace std;
using ll = long long;
using P = pair<ll, ll>;
const string ln = "\n";
constexpr int INF = 1001001001;
constexpr int MOD = 1000000007;

ll modpow(ll a, ll n) {
  ll res = 1;
  while (n > 0) {
    if (n & 1) res = res * a % 2019;
    a = a * a % 2019;
    n >>= 1;
  }
  return res;
}

int main() {
  cin.tie(nullptr);
  ios::sync_with_stdio(false);

  string s;
  cin >> s;

  ll n = s.size();

  ll md[210000] = {};
  md[0] = 1;
  for (int i = 1; i <= 200000; i++) {
    md[i] = modpow(10, i);
  }

  ll ans = 0;
  for (int l = 0; l < n - 4; l++) {
    for (int r = l + 4; r <= n; r++) {
      string sub = s.substr(l, r);
      ll sum = 0;
      for (int i = 0; i < sub.size(); i++) {
        ll num = sub[sub.size() - 1 - i] - '0';
        ll t = (num * md[i]) % 2019;
        sum += t;
        sum %= 2019;
      }

      if(sum % 2019 == 0) {
        ans++;
      }
    }
  }

  cout << ans << ln;

  return 0;
}
