#include <bits/stdc++.h>
#define ALL(a)  (a).begin(),(a).end()
using namespace std;
typedef long long ll;
typedef pair<int, int> P;
typedef pair<long long, long long> Pll;
typedef vector<int> vi;
typedef vector<vector<int>> vvi;
typedef vector<long long> vll;
typedef vector<vector<long long>> vvll;
template <typename T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template <typename T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }
const long long INF = 1LL << 60;
const int INT_INF = 1 << 30;
#define MOD 1000000007LL
#define endl "\n"

int main(){
  ios::sync_with_stdio(false);
  cin.tie(nullptr);
  string S;
  cin >> S;
  int N = S.size();
  vvll dp(N+1, vll(2019, 0));
  ll initial = S.at(0) - '0';
  dp.at(1).at(initial) = 1;
  for(int i = 1; i < N; i++){
    ll num = S.at(i) - '0';
    for(int j = 0; j < 2019; j++){
      dp.at(i+1).at((10*j + num) % 2019) += dp.at(i).at(j);
    }
    dp.at(i+1).at(num)++;
  }
  ll ans = 0;
  for(int i = 1; i <= N; i++){
    ans += dp.at(i).at(0);
  }
  cout << ans << endl;
}