here is my solution https://www.codechef.com/viewsolution/27668779
Hi @tsuraj You can find the editorial here at