AtCoder Beginner Contest 105
D
Candy Distribution
AtCoder
⌀ 1458
原题
← C→
翻译中…

Problem Statement

翻译中…

There are $N$ boxes arranged in a row from left to right. The $i$-th box from the left contains $A_i$ candies.

翻译中…

You will take out the candies from some consecutive boxes and distribute them evenly to $M$ children.

翻译中…

Such being the case, find the number of the pairs $(l, r)$ that satisfy the following:

翻译中…
  • $l$ and $r$ are both integers and satisfy $1 \leq l \leq r \leq N$.
  • $A_l + A_{l+1} + ... + A_r$ is a multiple of $M$.
翻译中…

Constraints

翻译中…
  • All values in input are integers.
  • $1 \leq N \leq 10^5$
  • $2 \leq M \leq 10^9$
  • $1 \leq A_i \leq 10^9$
翻译中…

Input

翻译中…

Input is given from Standard Input in the following format:

翻译中…

N M
A_1 A_2 ... A_N

翻译中…

Output

翻译中…

Print the number of the pairs $(l, r)$ that satisfy the conditions.

翻译中…

Note that the number may not fit into a $32$-bit integer type.

翻译中…

样例

Input #1
3 2
4 1 5
Output #1
3
The sum $A_l + A_{l+1} + ... + A_r$ for each pair $(l, r)$ is as follows: - Sum for $(1, 1)$: $4$ - Sum for $(1, 2)$: $5$ - Sum for $(1, 3)$: $10$ - Sum for $(2, 2)$: $1$ - Sum for $(2, 3)$: $6$ - Sum for $(3, 3)$: $5$ Among these, three are multiples of $2$.
Input #2
13 17
29 7 5 7 9 51 7 13 8 55 42 9 81
Output #2
6
Input #3
10 400000000
1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000
Output #3
25
题目信息
题号
abc105_d
时间限制
2 s
内存限制
1024 MB

题面与样例版权归 AtCoder 及出题人所有;中文翻译由 AI 生成(CI 管线),如有出入请以原文为准。