@admin post editorial for this question CodeChef: Practical coding for everyone
Its an external contest and admin won’t post any editorials for it!! You may request one though and community will be glad to help you out!!
I have given an explaination about the same problem in the following thread. You can have a look. What is logic behind this problem? - help - CodeChef Discuss