#include <bits/stdc++.h>
using namespace std;

# define REP(i,n) for (int i=0;i<(n);++i)
# define all(v) v.begin(),v.end()
# define showVector(v) REP(i,v.size()){cout << (v[i]) << " ";} cout << endl;
typedef long long int ll;

int main(void) {

  string s;
  cin >> s;

  int md = 2019;

  int now = 0;
  int ten = 1;
  vector<int> mp(2019, 0);
  for(int i = s.size()-1; i >= 0; i--){
    (now += (s[i] - '0') * ten) %= md;
    mp[now]++;
    (ten *= 10) %= md;
  }

  ll ans = mp[0];
  for(auto m : mp) {
    ans += m * (m - 1) / 2;
  }
  cout << ans << endl;

  return 0;
}