The above link is the submission I made to the question:

I think I have made the code as simple as possible. The solution is also matching and I verified it in my local compiler as well as by giving custom input. But codechef is giving WA. Please help me.