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

int main(void){
  long long dp[2020]={0};
  long long result=0;
  char s[200010];
  scanf("%s",s);
  int n = strlen(s);
  
  long long tmp = 1;
  long long sum = 0;
  for(int i=n-1;i>=0;i--){
    sum += (tmp*(long long)(s[i]-'0'))%2019;
    sum %= 2019;
    dp[sum]++;
    tmp = (tmp*10)%2019;
  }
  result = dp[0];
  for(int i=0;i<2019;i++){
    result += dp[i]*(dp[i]-1)/2;
  }
  printf("%lld",result);
  
  return 0;
}