#include <bits/stdc++.h>
#define REP(i, n) for (int i = 0; i < (int)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();
  vec2int dp(n, vecint(2019, 0));
  REP(i, n) {
    int tmp = s[i] - '0';
    dp[i][tmp] = 1;
    REP(k, 2019) {
      if (i == 0) continue;
      dp[i][(10 * k + tmp) % 2019] += dp[i - 1][k];
    }
  }
  int ans = 0;
  REP(i, n) {
    // cout << dp[i][0] << endl;
    ans += dp[i][0];
  }
  cout << ans << endl;
}
