#include<bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); ++i)
typedef long long ll;
int main() {
  string s;
  cin >> s;
  int n = s.size();
  int cnt = 0, e = 0;
  int c[n] = { }, d[n] = { }, dec[n + 1] = { 1 };
  rep(i,n)
  {
    c[i] = s[i] - '0';
    d[i] = (c[i] + e * 10);
    if (d[i] >= 2019)
      d[i] %= 2019;
    e = d[i];
    dec[i + 1] = dec[i] * 10;
    if (dec[i + 1] >= 2019)
      dec[i + 1] %= 2019;
    if (d[i] == 0)
      cnt++;
  }
//  rep(i,n)
//    cout << d[i] << " ";
//  cout << endl;
//  rep(i,n+1)
//    cout << dec[i] << " ";
//  cout << endl;
  int a = 0;
  rep(i,n)
  {
//    cout << d[i] << ":";
    for (int j = 0; j <= i - 1; j++) {
      a = d[j] * dec[i - j];
      if (a >= 2019)
        a %= 2019;
      if (d[i] == a) {
        cnt++;

      }
//      cout << d[j] * dec[i - j] % 2019 << " ";
    }
//    cout << endl;
  }
  cout << cnt;
}
