#include <bits/stdc++.h>
#define rep(i,s,n) for (int i=s;i<n;++i)
#define drep(i,s,n) for (int i=n;i>=s;--i)
#define all(x) (x).begin(),(x).end()
#define rall(a) (a).rbegin(),(a).rend()
#define print(x) cout<<(x)<<endl
using namespace std;
typedef long long ll;
int gcd(int a,int b)
{if (a%b == 0) return(b);
 else          return(gcd(b,a%b));}
int lcm(int a,int b)
{return a*b/gcd(a,b);}
void printv(vector<auto> v) {cout<<'[';rep(i,0,v.size()){cout<<v[i]<<',';}cout<<']'<<endl;}
void printvv(vector<vector<auto>> vv)
{
  cout<<'['<<endl;
  rep(q,0,vv.size()){cout<<'[';rep(p,0,vv.at(q).size())cout<<vv.at(q).at(p)<<',';cout <<']'<<endl;}
  cout<<']'<<endl;
}
void printpair(vector<pair<ll, ll>> vp)
{
  cout<<'['<<endl;
  rep(i,0,vp.size())
  {
    pair<ll, ll> p=vp[i];
    cout<<'{'<<p.first<<','<<p.second<<'}'<<endl;
  }
  cout<<'}'<<endl;
}
void solve(); int main(){cin.tie(0);ios::sync_with_stdio(0);solve();}
int step_x[] = {-1,0,0,1};
int step_y[] = {0,-1,1,0};
const long long INF = 1e12;
//------------------------------------------------------------
ll ans=0,n;
string s;
void solve()
{
    cin >> s;
    n=s.length();
    vector<int> dp(2019,0);

    dp[0]++;

    ll cur=0,coef=1;
    // 2019で割った余りは一巡だけ考えればよい(解説: Ti−1 == Tj (mod2019))←計算したものの再利用
    rep(i,0,n) {
      cur = (cur+coef*(s[n-1-i]-'0')%2019)%2019; // avoid overflow
      dp[cur]++;
      coef = coef*10%2019;
    }

    rep(i,0,2019) ans+=dp[i]*(dp[i]-1)/2; // 2の時だけ1追加する（dp[i]=0,1,2）

    print(ans);

    return;
}

