MSNG doubt

What is the approach to MSNG problem ?

https://discuss.codechef.com/t/msng-editorial/39511/19