#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<ll,ll> P;
string s;
int a[200005],d[200005],b[200005];
ll ans;
int main(void){
    cin>>s;
    d[s.size()-1]=1;
    for(int i=s.size()-1;i>=0;i--){
        a[i]=s[i]-48;
        if(i!=s.size()-1){
            d[i]=d[i+1]*10%2019;
            d[i+1]=d[i+1]*a[i+1]%2019;
        }
    }
    d[0]=d[0]*a[0];
    /*for(int i=0;i<s.size();i++){
        cout<<d[i]<<endl;
    }*/
    for(int i=0;i<s.size();i++){
        b[i+1]=(b[i]+d[i])%2019;
    }
    sort(b,b+s.size()+1);
    int t=1;
    for(int i=1;i<s.size()+1;i++){
        if(b[i]==b[i-1]){
            t++;
        }else{
            ans+=(t-1)*t/2;
            t=1;
        }
    }
    ans+=(t-1)*t/2;
    cout<<ans<<endl;
    
}
