Test case 3 is not passing

#include
using namespace std;

long long int subarray(long long int cum[],int n)
{
int freq[n]={};
for(int i=0;i<=n;i++)
{
cum[i]=cum[i]%n;
if(cum[i]<0)
freq[((cum[i]%n) +n)%n]++;
else
freq[cum[i]%n]++;
}
long long int sum=0;
for(int i=0;i<n;i++)
{
if(freq[i]>=2)
sum+=((freq[i]*(freq[i]-1))/2);
}
return sum;
}
int32_t main()
{
int test;
cin>>test;
while(test–)
{
int n;
cin>>n;
long long int c;
long long int cum[n+1]={0};
for(int i=0;i<n;i++)
{
cin>>c;
cum[i+1]=cum[i]+c;
}

	cout<<subarray(cum,n)<<endl;
}	

}

Hi,

Consider the case of p[0]. You are leaving a case of taking the subarray from start point to a particular index in this case. In this case you should add m*(m-1)/2 + m to the sum.

I am not able to understand your point can you please elaborate…

Consider the case:

4
1 3 2 5.
After taking prefix sum : 1 4 6 11.
After taking modulo : 1 0 2 3.

Here freq[0]=1, freq[1]=1 freq[2]=1 freq[3]=1.
You code will give output 0. But answer is 1.
Because you should consider the subarray 1 3. This is what i was telling. If the sum%n is 0 at a particular index then you should take the subarray starting from index 0 to the current index.