#include<iostream>
#include<cstring>
#include<vector>
#include<cstdio>
#include<algorithm>
using namespace std;
const int N=2e5+5;
char s[N];
int mod[N];
int main(){
cin>>s;
int k=1,res=0,ans=0;
for(int i=strlen(s)-1;i>=0;i--){
    mod[res]++;
    res=(res+(s[i]-'0')*k)%2019;
    ans+=mod[res];
    k=k*10%2019;
}
cout<<ans;


return 0;
}
