Codechef problem https://www.codechef.com/AUG19B/problems/KS1

How to approach this question
I am getting wrong answer