Add the calculated value of current index to count
if ( cnt . ContainsKey ( ( pref [ i ] - i % k + k ) % k ) ) cnt [ ( pref [ i ] - i % k + k ) % k ] = cnt [ ( pref [ i ] - i % k + k ) % k ] + 1 ; else cnt . Add ( ( pref [ i ] - i % k + k ) % k , 1 ) ; }