#include<stdio.h>
#include<stdlib.h>
#include<math.h>
#include<string.h>
#define F(i,a,n) for(int i=a; i<n; i++)

int compare(const void *b1, const void *b2){ // 昇順
  if(b1 > b2) return 1;
  else if(b1 < b2) return -1;
  else return 0;
}

int main(){
  char cs[20010];
  scanf("%s",cs);
  int n=strlen(cs);
  int a[n];
  F(i,0,n){
    char ss[2];
    strncpy(ss,cs+i,1);
    a[i]=atoi(ss);
  }
  int tmod[n+1];
  int t10[n+1];
  tmod[n]=0;
  t10[n]=1;
  for(int i=n-1; i>=0; i--){
    t10[i]=(t10[i+1]*10)%2019;
    tmod[i]=(tmod[i+1]+t10[i]*a[i])%2019;
  }
  int count[n+1];
  F(i,0,n+1){
    count[i]=0;
  }
  int iter=0;
  qsort(tmod,n+1,sizeof(int),compare);
  F(i,0,n){
    if(tmod[i]==tmod[i+1]){
      count[iter]++;
    }else{
      iter++;
    }
  }
  int ans=0;
  F(j,0,n){
    ans+=(count[j]*(count[j]-1))/2;
  }
  printf("%d\n",ans);
  return 0;
}