#include <stdio.h>
 
int main(void)
{
  int i, j;
  long int result = 0;
  char s[1][200000];
  
  scanf("%s", s[0]);
  
  for( i = 0; s[0][i] != '\0' ; i++ ){
      long long int sum = s[0][i] - '0';
    for( j = i+1; s[0][j] != '\0'; j++ ){
        sum += (sum * 9) + s[0][j] - '0';
            if( sum % 2019 == 0 ){
                result++;
            }
    }
  }
  
  printf("%ld\n", result);
  return 0;
}