CSES - Shared codeLink to this code:
https://cses.fi/paste/14c58a3815b187d71580ff/
"""
https://cses.fi/problemset/task/1662
5
3 1 2 7 4 should output 1
"""
divisor = int(input())
remainders_encountered = {}
sum_so_far = 0
for i in input().split():
sum_so_far += int(i)
remainder = sum_so_far % divisor
if remainder not in remainders_encountered:
remainders_encountered[remainder] = 0
remainders_encountered[remainder] += 1
total = 0
for r, i in remainders_encountered.items():
if r == 0:
total += i * (i + 1) // 2
else:
total += i * (i - 1) // 2
print(total)