Shoing tle and wrong answer for some cases

#include <bits/stdc++.h>
#define ll long long

using namespace std;

int counti(int arr[],int n,int k){
int mod[k];
memset(mod,0,sizeof(mod));
ll cumsum=0;

for(int i=0;i<n;i++){
    cumsum+=arr[i];
    mod[(cumsum%k)+k%k]++;
}
int result=0;
for(int i=0;i<k;i++)
    if(mod[i]>1)result+=(mod[i]*(mod[i]-1))/2;
result+=mod[0];
return result;

}
int main(){
int t;cin>>t;
while(t–){
int n;cin>>n;int arr[n];

            for(int i=0;i<n;i++)cin>>arr[i];
        cout<<counti(arr,n,n)<<endl;

}}

Hello @argus i have corrected your code :

if you have any doubt you can ask here:
Happy Learning!!

hey, thank you very much for always resolving my doubts

but what was bug in my code this time

@argus
mod[0]=1;// you have to count for sum 0 as well so for sum=0 make the count as 1
and this as well:
mod[((cumsum%k)+k)%k]++; //you are doing this in this way mod[(cumsum%k)+k%k]++i.e k%k for negative terms it would not evaluate the same way because everytime k%k will give you reamainder as 0.so you have to take bracket like the way i have made change:


Happy Learning!!

I hope I’ve cleared your doubt. I ask you to please rate your experience here
Your feedback is very important. It helps us improve our platform and hence provide you
the learning experience you deserve.

On the off chance, you still have some questions or not find the answers satisfactory, you may reopen
the doubt.