I just coded this today…the problem seems interesting. But after writing it I observer that there is no way I can check this. You know how it feels when you code and cannot verify whether it is correct/wrong. That’s why I am posting my code here in hope that someone will check my code and tell me whether it is correct or incorrect.
The pastebin link-
 Edit-1: The problem link - [PROBLEM] : http://pastebin.com/LwjJdYkg : https://www.codechef.com/CWAR2015/problems/CWAR02