#include <bits/stdc++.h>
using namespace std;
using vi = vector<int>;
using vb = vector<bool>;
using vl = vector<long>;
using vs = vector<string>;
using vvi = vector<vector<int>>;
using vvb = vector<vector<bool>>;
using vvc = vector<vector<char>>;
using pii = pair<int, int>;
using pil = pair<int, long>;
using pll = pair<long, long>;
#define fix20 cout << fixed << setprecision(20)
#define YES cout << "Yes" << endl
#define NO cout << "No" << endl
#define rep(i,n) for(int i=0; i<(int)(n);i++)
#define REP(i,s,t) for(int i=s; i<t; i++)
#define RNG(i,s,t,u) for(int i=s; i<t; i+=u)
#define MOD 1000000007
#define all(vec) vec.begin(), vec.end()

int main(){
  string s;
  cin >> s;
  vector<int> cnt(2019,0);
  cnt.at(0)++;
  long res = 0;
  long keta = 1;
  for(int i=s.size()-1;i>=0;i--){
    long p = s.at(i) - '0';
    long a = p * keta + res;
    res = a%2019;
    cnt.at(res)++;
    keta *= 10;
    keta %= 2019;
  }
  long ans = 0;
  rep(i,2019){
    long t = cnt.at(i);
    ans += t*(t-1)/2;
  }
  cout << ans << endl;
}