I guess I am not cleared about the input and output formats required with PHP. Not even able to find out any accepted solution in PHP! Any one can me point the proper solution in PHP or can you tell me the bug in my solution? This was my answer http://www.codechef.com/viewsolution/1143977
On getting a clear idea, I can proceed properly for the next problem! Thanks in advance for the help!!