#include <iostream>
#include <vector>
#include <map>
#include <algorithm>
#define ll long long
using namespace std;
int main(){
    string s;
    cin>>s;
    ll n=s.length();
    vector<ll> x(n+1,0);
    for(ll i=0;i<n;i++){
        for(ll j=i;j<n;j++){
            x[i]+=(s[j]-'0')*pow(10,n-j-1);
        }
    }
    map<ll,ll> rmap;
    for(ll i=0;i<n+1;i++){
        rmap[x[i]%2019]++;
    }
    
    ll ans=0;
    for(const auto& imap:rmap){
        ans+=imap.second*(imap.second-1)/2;
    }
    cout<<ans<<endl;
    return 0;
}