Can someone please provide an editorial for the question A6?

I have no idea how to solve this question. A6 Problem - CodeChef. I can’t find the solution anywhere and haven’t got a reply from any forum for it till now
@admin, help