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

template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1; } return 0; }

using ll = long long;

ll pow(ll x, ll y) {
    if (y == 0LL) return 1LL;
    ll X = 1LL;
    for (ll i = 0LL; i < y; i++) {
      X *= x;
      X %= 2019;
    }
    return X;
}

ll dp[200100];
ll dpp[2100];

int main() {
  string S;
  cin >> S;
  ll l = S.size();
  ll f = S.at(0) - '0';
  dp[l+1] = 0LL;
  dpp[0] = 1LL;
  ll s = 10LL;
  for(ll i = l; i >=1; i--) {
    ll t = S.at(i-1) - '0';
    dp[i] = (dp[i+1] + t*s)%2019LL;
    s *= 10LL;
    s %= 2019LL;
    dpp[dp[i]]++;
  }
  ll ans = 0LL;
  for(ll i = 0; i < 2100; i++) {
    ans += dpp[i] * (dpp[i] -1) /2;
  }
  cout << ans << endl;
}