You can see my solution here and i can assure you that it is running correct on every possible test case . https://www.codechef.com/viewsolution/22513924
You can see my solution here and i can assure you that it is running correct on every possible test case . https://www.codechef.com/viewsolution/22513924