LoC June 2017 PRATABHI Help

Can someone explain how to solve this problem .

problem link CodeChef: Practical coding for everyone

refer this -https://discuss.codechef.com/questions/104044/solution-for-pratabhi-loc-jun-17