Solution seems fine to me. Please find where I am missing something.
link:- https://www.codechef.com/viewsolution/22020467