COUNT=$(cat - |\
  sed 1d |\
  tr ' ' '\n' |\
  factor |\
  cut -d ' ' -f2-|\
  egrep '2( |$)' |\
  egrep -v '3( |$)' |\
  egrep -v '5( |$)' |\
  wc -l )

[ $COUNT -eq 0 ] && echo APPROVED || echo DENIED
