#include <bits/stdc++.h>
 
using namespace std;
 
typedef long long ll;
typedef vector<ll> vll;
typedef vector<vll> vvll;
typedef pair<ll,ll> P;
typedef vector<P> vp;
typedef vector<string> vs;
typedef vector<bool> vb;

const ll mod=1e9+7;
const ll inf=1e16;

#define rep(i,m,n) for(ll i=m;i<n;i++)
#define repr(i,m,n) for(ll i=m-1;i>=n;i--)
#define fi first
#define se second
#define chmax(x,y) x=max(x,y)
#define chmin(x,y) x=min(x,y)
#define eb(x) emplace_back(x)
#define all(x) x.begin(),x.end()
#define gll greater<ll>()

string s;

void solve(){
 cin >> s;
 ll n=s.length();
 reverse(all(s));
  vll sum(n+1,0);
  ll pow=1;
 rep(i,0,n){  
  sum[i+1]=sum[i]+pow*(s[i]-'0');
  sum[i+1]%=2019; 
  pow*=10;
  pow%=2019; 
 }
  map<ll,ll> mp;
 for(auto a:sum) mp[a]++;  
  ll res=0;
 for(auto p:mp) res+=p.se*(p.se-1)/2; 
 cout << res << endl;
}

int main(){
   cin.tie(nullptr);
  ios::sync_with_stdio(false);
  solve();
}  