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

int main(void)
{
  int i, j, result = 0;
  char s[1][200000];
  
  
  scanf("%s", s[0]);
  
  for( i = 0; s[0][i] != '\0' ; i++ ){
      int sum = s[0][0] - '0';
    for( j = i+1; s[0][j] != '\0'; j++ ){
        sum += (sum * 9) + s[0][j] - '0';
        if( j - i >= 3 ){
            if( sum % 2019 == 0 ){
                result++;
            }
        }
        
    }
  }
  
  printf("%d\n", result);
  return 0;
}