Dont know where it is wrong?
https://www.codechef.com/viewsolution/66187155
Check the following solution.
Accepted