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

long long n;
string s;
vector<long long> cnt, sum;

long long solve();

int main() {
  cin >> s;
  n = s.size();
  cout << solve() << endl;
  return 0;
}

long long solve() {
  reverse(s.begin(), s.end());
  cnt.assign(2019, 0);
  sum.assign(n + 1, 0);
  cnt[0] = 1;
  long long res = 0, ten = 1;
  for (int i = 0; i < n; ++i, (ten *= 10) %= 2019) {
    sum[i + 1] = sum[i];
    sum[i + 1] += (s[i] - '0') * ten;
    sum[i + 1] %= 2019;
    res += cnt[sum[i + 1]];
    ++cnt[sum[i + 1]];
  }
  return res;
}
