I have tried a number of test cases but i still i cant figure out my mistake.Please help.Code link is below : http://www.codechef.com/viewsolution/2403899
Also when i was through some of the successful submissions of other users i saw that they have stored the variables with constraints around a lakh with "int".How is this possible ?