#include<bits/stdc++.h>

using namespace std;

#define debug(n) cerr << #n << ':' << n << endl;
#define dline    cerr << __LINE__ << endl;

using ll = long long;
template<class T, class U> using P = pair<T,U>;
template<class T> using Heap = priority_queue<T>;
template<class T> using heaP = priority_queue<T,vector<T>,greater<T>>;
template<class T,class U> using umap = unordered_map<T,U>;
template<class T> using uset = unordered_set<T>;

template<class T>
bool ChangeMax(T&a,const T&b){
  if(a >= b) return false;
  a = b;    return true;
}

template<class T>
bool ChangeMin(T&a,const T&b){
  if(a <= b) return false;
  a = b;    return true;  
}

template<class T, size_t N, class U>
void Fill(T (&a)[N], const U&v){
    fill((U*)a,(U*)(a+N),v);
}

template<class T>
istream& operator >> (istream&is, vector<T>&v){
  for(auto&e:v)is >> e;
  return is;
}

int main(){
  string s; cin >> s;
  int n = static_cast<int>(s.size());
  vector<ll> dp1(2019);
  ll cnt = 0;
  for(int i = 0; i < n; ++i){
    vector<ll> dp0(2019);
    int x = s[i] - '0';
    for(int j = 0; j < 2019; ++j){
      dp0[(j*10+x)%2019] += dp1[j];
    }
    dp0[x]++;
    cnt += dp0[0];
    dp1 = move(dp0);    
  }
  cout << cnt << endl;
  return 0;  
}
