#include <bits/stdc++.h>
#define REP(i, n) for (ll i = 0; i < (ll)n; i++)
#define REPvec(itr, mp) for (auto itr = mp.begin(); itr != mp.end(); itr++)
#define all(x) x.begin(), x.end()
#define MOD 1000000007  // 1e9+7
using namespace std;
typedef long long int ll;
typedef vector<int> vecint;
typedef vector<ll> vecll;
typedef vector<double> vecd;
typedef vector<string> vecstr;
typedef vector<char> vecchar;
typedef vector<bool> vecbool;
typedef vector<vector<bool> > vec2bool;
typedef vector<vector<int> > vec2int;
typedef vector<vector<double> > vec2d;
////////////////////////////////////////////////
void init() {
  cin.tie(nullptr);
  ios_base::sync_with_stdio(false);
  cout << fixed << setprecision(15);
}
////////////////////////////////////////////////
int main() {
  init();
  string s;
  cin >> s;
  int n = s.size();
  vecint pow10(n, 1);
  REP(i, n - 1) { pow10[i + 1] = (pow10[i] * 10) % 2019; }
  vecint mod(n, 0);
  mod[n - 1] = s[n - 1] - '0';
  vecint dp(2019, 0);
  dp[0] = 1;
  for (int i = n - 2; i >= 0; i--) {
    mod[i] = mod[i + 1] + (s[i] - '0') * pow10[n - i - 1];
    mod[i] %= 2019;
    dp[mod[i]]++;
  }

  // REP(i, n) { cout << pow10[i] << endl; }
  // REP(i, n) { cout << mod[i] << endl; }
  int ans = 0;

  REP(i, 2019) ans += dp[i] * (dp[i] - 1) / 2;
  cout << ans << endl;
}
