Can someone please suggesst me what i amdoing wrong

Sarthak, you are somewht following wrong approach in your code for calculating the values, the basic approach you will follow is that, you have to initialise sum=0 and prefixsum array to be 0.Then use a loop from 0 to N , and then calculate sum, both for positive and negative integers, and update the value of prefixsum, :
for(long long int i=0;i<N;i++)
{
sum=sum+ar[i];
sum=sum%N;
sum=(sum+N)%N;
prefixsum[sum]++;
}

Then take ans=(prefixsum[0](prefixsum[0]+1))/2;
for(long long int i=1;i<N;i++)
{
ans=ans+(prefixsum[i]
(prefixsum[i]-1))/2;
}

This is the approach as per pigeonhole principle.