BLUEPRINT question AHAPH

can someone please help me out in this question https://www.codechef.com/BLUP2019/problems/AHAPH?
@vipulvikram
and also explain this solution: https://www.codechef.com/viewsolution/22917387
Thanks.