#include <bits/stdc++.h>
using namespace std;

#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define rept(i,k,n) for(int i = (k); i < (int)(n); i++)
#define all(v) v.begin(), v.end()
#define Sort(v) sort(v.begin(),v.end())
#define Reverse(v) reverse(v.begin(),v.end())
typedef long long ll;
typedef pair<int,int> Pii;
typedef pair<long long,long long> Pll;

template <typename T>
ostream& operator<<(ostream& s, const vector<T> &vec){
    for(int i=0;i<vec.size();i++){
        if(i) s << ',';
        else s << '{';
        s <<setw(2)<< vec[i];
    }
    s << '}' << endl;
    return s;
}
int ctoi(const char c){
    if('0' <= c && c <= '9') return (c-'0');
    return -1;
}

int main(){
    string s;
    cin>>s;
    int n=s.size();
    map<int,int> dp;
    int k=0,l=1;
    dp[0]=1;
    rep(i,n){
        k = (k+l*ctoi(s[n-1-i]))%2019;
        dp[k]++;
        l = l*10%2019;
    }
    ll ans =0;
    for(auto p:dp){
        ans += p.second*(p.second-1)/2;
    }
    cout<<ans<<endl;

    return 0;
}