#include<bits/stdc++.h>
using namespace std;
int main(){
    string S;
    cin>>S;
    long long N=S.size();
    vector<int>TEN(N+1);
    TEN.at(0)=1;
    for(int i=1;i<N+1;i++){
        TEN.at(i)=(TEN.at(i-1)*10)%2019;
    }
    vector<int>A(N);
    A.at(0)=S.at(N-1)-'0';
    for(int i=1;i<N;i++){
        int B=S.at(N-1-i)-'0';
        A.at(i)=(A.at(i-1)+(B*TEN.at(i)))%2019;
    }
    vector<long long>list(2019);
    for(int i=0;i<N;i++){
        list.at(A.at(i))=list.at(A.at(i))+1;
    }
    long long sum=0;
    for(int i=0;i<N;i++){
        sum=sum+list.at(i)+(list.at(i)*(list.at(i)-1))/2;
    }
    cout<<sum<<endl;
}