#include<bits/stdc++.h>
using namespace std;
 
#define rep(i, a, n) for(int i=a; i<n; i++)
#define ll long long
#define all(x) begin(x), end(x)
#define toInt(x) (x - '0')
#define pll pair<ll, ll>
#define pli pair<ll, int>

const long long INF = 1LL<<60;
const int inf = 1 << 30;
const int mod = 1e9+7;


template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1; } return 0; }

int main(){
  string s;
  cin >> s;
  int n = s.size();
  reverse(all(s)); 

  int x = 1;
  int t = 0;
  vector<int> cnts(2019);
  cnts[0]  = 1;
  ll ans = 0;
  rep(i, 0, n){
    int num = (s[i] - '0') * x + t;
    num %= 2019;
    t = num;
    cnts[num]++;
    x = (x * 10) % 2019;
  }

  for (int cnt: cnts){
    ans += cnt * (cnt - 1) / 2;
  }
  cout << ans << endl;
}
