#include<stdio.h>
#include<string.h>


int main(){
   int i=0;
  char s[200001];
   long long a=0,d=1LL,x=0,count[2019]={1LL};
    i=scanf("%s",s);
    i=strlen(s);
   while(i--){
           x=(x+(s[i]-'0')*d)%2019;
            a+=count[x]++;
               d=d*10%2019;
               }
        printf("%lld\n",a);
               return 0;
}
