#include <stdio.h>
 
int main(void) {
  int S[6], Ans, N;
  Ans = 0;
  if(scanf("%d", S)==1);
  for(i=0,i<6,i++) {
    if (S[i] ='\n') {
      break;
    }
  }
  if (i>3) {
    N = S[0]*1000+S[1]*100+S[2]*10+S[3];
    if (N%2019==0) {
      Ans++;
    }
  }
  if (i>4) {
    N = S[1]*1000+S[2]*100+S[3]*10+S[4];
    if (N%2019==0) {
      Ans++;
    }
    N = S[0]*10000+S[1]*1000+S[2]*100+S[3]*10+S[4];
    if (N%2019==0) {
      Ans++;
    }
  }
  if (i=6) {
    N = S[2]*1000+S[3]*100+S[4]*10+S[5];
    if (N%2019==0) {
      Ans++;
    }
    N = S[0]*100000+S[1]*10000+S[2]*1000+S[3]*100+S[4]*10+S[5];
    if (N%2019==0) {
      Ans++;
    }
  }
  printf ("%d", Ans);
  return 0;
}