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

ll r(ll x, ll y) {
  if (y == 0) return 1;
  else if (y % 2 == 0) return r(x, y/2) * r(x, y/2) % mod;
  else return x * r(x, (y-1)/2) % mod * r(x, (y-1)/2) % mod;
}
  
int main() {
  string S;
  cin >> S;
  int n = S.size();
  vector<int> s(n);
  for (int i = 0; i < n; i++) {
    s[i] = S[i] - '0';
  }
  ll c = 0;
  if (n < 4) {
    cout << 0 <<endl;
  }
  else {
    for (int i = 0; i < n - 4; i++) {
      int p = 100 * s[i] + 10 * s[i+1] + s[i+2];
      for (int j = i + 4; j < n; j++) {
        p = p*10 + s[j];
        p %= 2019;
        if (p == 0) {
          c++;
        }
      }
    }
    cout << c <<endl;
  }
} 
