Why some cases are not passed please tell me the logical error in the code

Source code https://ide.codingblocks.com/s/224620

hello @the.shubham.sri
image
a)
replace sum+=ar[i]
with sum=(sum+ar[i])%n
to avoid overflow
b)
replace ar[i]=ar[i]%n
with ar[i]=(ar[i]+n)%n
to avoid negative modulo

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.