#159Medium
Subarray divisibility
Time: 1 s · Memory: 256 MB
- Prefix sums
Statement
You are given an array of integers. Count the non-empty subarrays whose sum is divisible by .
Input format
The first line contains (). The second line contains integers ().
Output format
A single number — the number of subarrays.
Examples
Input
5 3 1 2 7 4
Output
1
Note
The sum of is divisible by . So count the remainders of : a remainder that occurs times gives pairs. An array of counters is enough.
There are negative numbers: in C++, Go and Java % returns a negative remainder — use . The answer reaches — a 64-bit type is needed.
Source: CSES, problem 1662.
