#include<bits/stdc++.h>
#define rep(i,n) for(int i = 0; i < (int) n; i++)
using ll = long long;
template <class T>
using vt = std::vector<T>;
using vvi = std::vector<vt<int>>;
const int MOD = 2019;

int main(){
  std::string s;
  std::cin >> s;
  int N = s.size();

  vt<int> p(N);
  int ten = 10;
  p[0] = s[N-1] - '0';
  for(int i = N-2; i >= 0; i--) {
    p[N-1-i] = ((s[i]-'0')*ten + p[N-2-i])%MOD;
    ten *= 10;
    ten%=MOD;
  }

  vt<int> v(2019);
  rep(i,N){
    v[p[i]]++;
  }
  int ans = 0;
  rep(i,2019){
    if(i==0)
      ans += v[0];
    else
      ans += v[i]*(v[i]-1)/2;
  }

  std::cout << ans << '\n';
  return 0;
}
