class Solution:
def subarraysDivByK(self, nums: List[int], k: int) -> int:
prefixSum = 0
ans = 0
reminders = {}
reminders[0] = [1]
for i, num in enumerate(nums):
prefixSum += num
m = prefixSum % k
if m in reminders:
ans += len(reminders[m])
reminders[m].append(i)
else:
reminders[m] = [i]
return ans