https://www.codechef.com/viewsolution/33620084 here is my code. not getting the BUG after so many manual check.