Help AC run 2nd question

i am trying to solve this question but not getting the idea to solve ,could you guys help with this one:
https://www.codechef.com/ACRN2021/problems/STOP