PAIRCNT Please help

https://www.codechef.com/viewsolution/48704894

I tried a lot of test cases and was getting the correct answers, but it was getting runtime errors while submitting in all the cases.

Please someone help!!