1 test case gives wrong answer and two other gives runtime error

Can you pls add some comments in your code so that I could understand it well…

Jitendra, the approach you are trying to use is not correct… You need to apply the pigeonhole principle in your code as explained by prateek bhaiya in the online video lecture…
For reference , you need to create a prefixSum array …and you can apply the logic as,

long long int subarrays(long long int ar[],long long int n)
{
long long int sum=0;
long long int prefixsum[10000000]={0};
prefixsum[0]=1;
for(int i=0;i<n;i++)
{
sum=sum+ar[i];
sum=sum%n;
sum=(sum+n)%n;
prefixsum[sum]++;
}
long long int ans=0;
for(int i=0;i<n;i++)
{
long long int no=prefixsum[i];
ans=ans+(no*(no-1))/2;
}
return ans;
}