May I state it's YOUR exercise to define what has to be done for wich input combination ...

AND we're supposed to help for programming the PIC application ...

In short words :

The logics problem is yours ... not ours to solve.

Alain