#include <bits/stdc++.h>
#define rep(i,a,b) for(int i=int(a);i<=int(b);++i)
using namespace std;
template<class A>void pr(A a){cout << (a) << endl;}
template<class A,class B>void pr(A a,B b){cout << a << " "  ;pr(b);}
template<class A,class B,class C>void pr(A a,B b,C c){cout << a << " " ;pr(b,c);}
template<class A,class B,class C,class D>void pr(A a,B b,C c,D d){cout << a << " " ;pr(b,c,d);}
typedef long long ll;
typedef pair<ll, ll> l_l;
typedef pair<int, int> i_i;
int INF=numeric_limits<int>::max();
// for(int j=0;j<N;++j) {
int to_int(char c) {
  return c - '0';
}

typedef long long ll;
ll modpow(ll a, ll n, ll MOD) {
  ll res = 1;
  while(n>0){
    if(n&1) res = res * a % MOD;
    a = a * a % MOD;
    n >>= 1;
  }
  return res;
}

int main(void) {
  string S;cin>>S;
  int n = S.length();
  int T[n+10];
  vector<int> M(2018,0);

  T[n] = 0;
  M[T[n]]++;

  for(int i=n-1;i>=0;i--) {
    // pr(to_int(S[n-i-1]));
    T[i] = (T[i+1] + to_int(S[i])*modpow(10,n-i-1,2019)) % 2019;
    M[T[i]]++;
  }

  ll ans=0;

  for(auto m:M) {
    ans+=m*(m-1)/2;
  }

  pr(ans);
  return 0;
}
