#include <bits/stdc++.h>
using namespace std;
#ifdef LOCAL_DEBUG
  #include "LOCAL_DEBUG.hpp"
#endif
#define int long long

signed main(){

  string s; cin >> s;

  reverse(s.begin(), s.end());
  int n = s.size();
  vector<int> imos(n+1, 0);
  int ten = 1;
  for(int i = 0; i < n; i++){
    imos[i+1] = (imos[i] + (s[i]-'0') * ten ) % 2019;
    ten = (ten * 10) % 2019;
  }

  int ans = 0;
  map<int, int> mp;
  for(int i = 0; i < n+1; i++){
    ans += mp[imos[i]];
    mp[imos[i]]++;
  }
  cout << ans << endl;

  return 0;
}