/* Problem 1--Simply Syntax
   This is a naturally recursive problem.  Just follow the rules and
   pull out appropriate sentences. */

#include <stdio.h>
#include <stdlib.h>

int main (int argc, char **argv);
int Valid (char *line);
int Process (char **t);

int main (int argc, char **argv) {

  int r;
  FILE *in, *out;
  char line[257];

 in = fopen ("prob1.in","r");
 out = fopen ("prob1.out","w");
 for (;;) {
  fscanf (in,"%s",line);
 if (feof (in)) break; /* Check for end-of-file */
  if (Valid (line)) {
   fprintf (out,"YES\n");
  } else {
   fprintf (out,"NO\n");
  }
 }
 fclose (in);
 fclose (out);
 r = EXIT_SUCCESS;
 return r;
}

/* Valid accepts a character array and returns a boolean value
   indicating the validity of the sentence. */
int Valid (char *line) {

  int v;

 v = Process (&line); /* start processing from beginning of array */
 v = v && *line == 0; /*make sure we have reached the end of the array*/
 return v;
}

/* Process tries to remove one complete sentence from the beginning of
   the array beginning with t.  It returns a boolean indicating whether
   it was successful. t is advanced beyond the valid sentence removed.*/
int Process (char **t) {

  int v;

 if (**t == 0) { /* Premature end of sentence */
  v = 0;
 } else {
  if (**t >= 'p' && **t <= 'z') { /* Valid 1-char sentence */
   (*t)++;
   v = 1;
  } else { /* N is followed by one full sentence, so try to do it. */
   if (**t == 'N') {
    (*t)++;
    v = Process (t);
   } else { /* All others are followed by two full sentences; try to */
    (*t)++; /* remove both. */
    v = Process (t);
    if (v) {
     v = Process (t);
    } else {
    }
   }
  }
 }
 return v;
}
