How to solve CHPLGNS problem?

Please tell me - How to solve CHPLGNS ?

I think you should refer this editorial. It is been explained nicely

//