Unable to understand Divisible SubArrays Problem

Problem
For the Below Solution https://ide.codingblocks.com/s/38549 of DivisibleSum SubArray @Prateek-Narang-10209 Bhaiya
Why we are doing sum=sum%n before sum=(sum+n)%n.I understand that the latter is used to calculate the Cs % n for negative numbers. But, why the former is used. What if I don’t use that line.

This is done just to prevent the overflow of number.

(a + b)%m = ( (a%m) + (b%m) ) % m

This important property has been used here.