#include <bits/stdc++.h>

#define rep(i, n) for (ll i = 0; i < (ll)(n); i++)
#define ll long long
using namespace std;
  map<int, int> t;

int main() {
  string s;
  cin >> s;
  int n = s.size();
  vector<int> a(n);
  rep (i, n) a[i] = s[i] - '0';
  vector<ll> num(n);
  for (int i = 1; i < n + 1; i++) {
    if (i == 1) {
      num[n - 1] = a[n - 1];
      // cout << num[n - 1] << endl;
    }
    else {
      num[n - i] = num[n - i + 1] + pow(10, i - 1) * a[n - i];
      // cout << num[n - i] << endl;
    }
  }

  t[0] = 1;

  rep(i, n) {
    int a = num[i] % 2019;
    t[a]++;
  }

  int count = 0;

  for (auto p : t) {
    if (p.second > 0) {
      count += p.second * (p.second - 1) / 2;
    }
  }
  cout << count << endl;
 
}