Hey there! Actually I tried to solve this problem on UVA. I submitted this solution on vjudge but it is giving TLE. On local machine it is working for all test cases that I tried. I tried to debug as well initially. Now that I am getting correct answers but TLE as well I don't know what's going wrong. Please Help.
P.S. : This is my first blog entry.