100 atcoder#ABC105D. [ABC105D] Candy Distribution

[ABC105D] Candy Distribution

Score : 400400 points

Problem Statement

There are NN boxes arranged in a row from left to right. The ii-th box from the left contains AiA_i candies.

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

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

  • ll and rr are both integers and satisfy 1lrN1 \leq l \leq r \leq N.
  • Al+Al+1+...+ArA_l + A_{l+1} + ... + A_r is a multiple of MM.

Constraints

  • All values in input are integers.
  • 1N1051 \leq N \leq 10^5
  • 2M1092 \leq M \leq 10^9
  • 1Ai1091 \leq A_i \leq 10^9

Input

Input is given from Standard Input in the following format:

NN MM

A1A_1 A2A_2 ...... ANA_N

Output

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

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

3 2
4 1 5
3

The sum Al+Al+1+...+ArA_l + A_{l+1} + ... + A_r for each pair (l,r)(l, r) is as follows:

  • Sum for (1,1)(1, 1): 44
  • Sum for (1,2)(1, 2): 55
  • Sum for (1,3)(1, 3): 1010
  • Sum for (2,2)(2, 2): 11
  • Sum for (2,3)(2, 3): 66
  • Sum for (3,3)(3, 3): 55

Among these, three are multiples of 22.

13 17
29 7 5 7 9 51 7 13 8 55 42 9 81
6
10 400000000
1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000
25