#include <bits/stdc++.h>
using namespace std;
#define rep(i, m, n) for(int i=m; i<n; i++)
typedef long long ll;
typedef pair<int, int> P;
typedef pair<ll, ll> Pll;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<ll> vll;
template <typename T> bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1;} return 0; }
template <typename T> bool chmin(T &a, const T &b) { if (a>b) { a=b; return 1;} return 0; }

ll a[200001];
ll S[200010];
ll ans[2019];
int main() {
    string s; cin>>s;
    reverse(s.begin(),s.end());
    int j=1;
    rep(i,0,s.size()){
        j%=2019;
        a[i]=s[i]-'0';
        a[i]*=j;
        a[i]%=2019;
        j*=10;
        S[i+1]+=a[i]+S[i];
        S[i+1]%=2019;
    }
    //rep(i,0,s.size()+1) cout<<S[i]<<" ";
    
    
    rep(i,0,s.size()+1){
        ans[S[i]]++;
    }
    ll res=0;
    rep(i,0,2019){
        res+=ans[i]*(ans[i]-1)/2;
    }
    cout<<res<<endl;
    
}