What could be going wrong if it only works for small values (ZCO20002)

I’ve done everything, practically declare all values as long long int and used ans%p at all steps. I’ve even declared extra space on each array. Also checked the value of each variable before using it as an index.
https://www.codechef.com/viewsolution/28497041

It seems memset has some memory constraints