Run-error in the code DIVISIBLE SUBATTAYS in Number Theory

Out of 5 two test cases 2 are correct and for rest 3 it shows run error .Plz check the code what is the mistake and correct that.

problem link : https://online.codingblocks.com/app/player/39658/content/37369/4829/code-challenge

code link :

Plz reply ASAP.

Hi,
So there are problems with the scenario in which the value of the prefix sum becomes negative, u were trying to access -ve array index
Do something like this
sum_arr[i+1]=(sum_arr[i]%n+arr[i]%n+n)%n;

then

		for(ll i=0;i<=n;i++)
		{
			freq[sum_arr[i]]+=1;
		}

this has to be corrected, since sum_arr ranges from [0,n] and not [0,n-1]

Also all the data type need to be changed to long long int.

I recommend u watch Prateek bhaiyas video TO optimize the code further
https://admin.codingblocks.online/contents/edit/43/video/17