human
Count subarrays having sum modulo K same as the length of the subarray | Function that counts the subarrays s . t . sum of elements in the subarray modulo k is equal to size of subarray.
Stores the count of ( pref [ i ] - i ) % k.
Stores the count of subarray.
Stores prefix sum of the array.
Find prefix sum array.
Base Condition.
Remove the index at present after K indices from the current index.
Update the answer for subarrays ending at the i - th index.
Add the calculated value of current index to count.
Print the count of subarrays.
Given arr [ ].
Size of the array.
Given K.
Function call"
How can the above be solved in Python?

=====
Can you provide a code to count subarrays having sum modulo K same as the length of the subarray and the other steps required?
assistant
#Here is code to count subarrays having sum modulo K same as the length of the subarray and the other steps required.
 def countSubarrays ( a , n , k ) :
	cnt = { }
	ans = 0
	pref = [ ]
	pref . append ( 0 )
	for i in range ( n ) :
		pref . append ( ( a [ i ] + pref [ i ] ) % k )
	cnt [ 0 ] = 1
	for i in range ( 1 , n + 1 ) :
		remIdx = i - k
		if ( remIdx >= 0 ) :
			if ( ( pref [ remIdx ] - remIdx % k + k ) % k in cnt ) :
				cnt [ ( pref [ remIdx ] - remIdx % k + k ) % k ] -= 1
			else :
				cnt [ ( pref [ remIdx ] - remIdx % k + k ) % k ] = - 1
		if ( pref [ i ] - i % k + k ) % k in cnt :
			ans += cnt [ ( pref [ i ] - i % k + k ) % k ]
		if ( pref [ i ] - i % k + k ) % k in cnt :
			cnt [ ( pref [ i ] - i % k + k ) % k ] += 1
		else :
			cnt [ ( pref [ i ] - i % k + k ) % k ] = 1
	print ( ans , end = ' ▁ ' )
arr = [ 2 , 3 , 5 , 3 , 1 , 5 ]
N = len ( arr )
K = 4
countSubarrays ( arr , N , K )