#include <stdio.h>
#define dr 2019

int main(){
  int i,j=0,k=1,c[2020]={};
  char s[200005];
  long m=0;
  scanf("%s",&s);
  for(i=0;s[i]!=0;i++);
  for(i--;i>=0;i--){
    j+=k*(s[i]-'0');
    j%=dr;
    c[j]++;
    k*=10;
    k%=dr;
  }
  c[0]++;
  for(i=0;i<2019;i++){
    m+=(long)(c[i]-1)*c[i]>>1;
  }
  printf("%ld",m);
  return(0);
}