#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i = 0; i < n; i++)
#define per(i,n) for(int i = n-1; i >= 0; i--)
typedef long long ll;
typedef pair<int, int> P;
typedef pair<long long, long long> Pll;
typedef vector<int> vi;
typedef vector<ll> vll;
const int mod = 2019;

int main() {
  string s;
  cin >> s;
  reverse(s.begin(),s.end());
  int amari[220000];
  int ans = 0;
  map<int,int> mp;
  rep(i,s.size()) {
    if(i==0) {
      string t = "";
      t += s[i];
      int m = stoi(t);
      mp[m]++;
    }
    int ten = 1;
    rep(j,i) {
      ten *= 10;
      ten %= mod;
    }
    string t = "";
    t += s[i];
    int m = stoi(t);
    ten *= m;
    ten %= mod;
    ten += amari[i-1];
    ten %= mod;
    amari[i] = ten;
    mp[amari[i]]++;
  }
  for(auto p : mp) {
    int m = p.second;
    if(m==0) continue;
    ans += m*(m-1)/2;
  }
  cout << ans << endl;
  return 0;
}