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

int pow_mod(int a, int n, int mod) {
  int res = 1;
  while (n > 0) {
    if (n & 1) res *= a;
    a = a*a;
    a %= mod;
    n >>= 1;
    res %= mod;
  }
  return res;
}

int main() {
  string S;
  cin >> S;
  int N = S.size();
  vector<int> mod(N+1);
  mod[N] = 0;
  for (int s = N-1; s >= 0; s--) {
    int a = S[s] - '0';
    mod[s] = a * pow_mod(10, (N-1)-s, 2019) + mod[s+1];
    mod[s] %= 2019;
  }
  map<int, int> cnt;
  for (auto m : mod) {
    cnt[m]++;
  }
  int ans = 0;
  for (auto c : cnt) {
    ans += c.second * (c.second - 1) / 2;
  }
  cout << ans << endl;
}
