Problem10949--ABC367 - D - Pedometer

10949: ABC367 - D - Pedometer

[Creator : ]
Time Limit : 1.000 sec  Memory Limit : 512 MiB

Description

There are $N$ rest areas around a lake.  
The rest areas are numbered $1$, $2$, ..., $N$ in clockwise order.  
It takes $A_i$ steps to walk clockwise from rest area $i$ to rest area $i+1$ (where rest area $N+1$ refers to rest area $1$).  
The minimum number of steps required to walk clockwise from rest area $s$ to rest area $t$ ($s \neq t$) is a multiple of $M$.  
Find the number of possible pairs $(s,t)$.

Input

The input is given from Standard Input in the following format:

```
$N$ $M$
$A_1$ $A_2$ $\dots$ $A_N$
```

Output

Print the answer as an integer.

Constraints

-   All input values are integers
-   $2 \le N \le 2 \times 10^5$
-   $1 \le A_i \le 10^9$
-   $1 \le M \le 10^6$

Sample 1 Input

4 3
2 1 4 3

Sample 1 Output

4
  • The minimum number of steps to walk clockwise from rest area $1$ to rest area $2$ is $2$, which is not a multiple of $3$.
  • The minimum number of steps to walk clockwise from rest area $1$ to rest area $3$ is $3$, which is a multiple of $3$.
  • The minimum number of steps to walk clockwise from rest area $1$ to rest area $4$ is $7$, which is not a multiple of $3$.
  • The minimum number of steps to walk clockwise from rest area $2$ to rest area $3$ is $1$, which is not a multiple of $3$.
  • The minimum number of steps to walk clockwise from rest area $2$ to rest area $4$ is $5$, which is not a multiple of $3$.
  • The minimum number of steps to walk clockwise from rest area $2$ to rest area $1$ is $8$, which is not a multiple of $3$.
  • The minimum number of steps to walk clockwise from rest area $3$ to rest area $4$ is $4$, which is not a multiple of $3$.
  • The minimum number of steps to walk clockwise from rest area $3$ to rest area $1$ is $7$, which is not a multiple of $3$.
  • The minimum number of steps to walk clockwise from rest area $3$ to rest area $2$ is $9$, which is a multiple of $3$.
  • The minimum number of steps to walk clockwise from rest area $4$ to rest area $1$ is $3$, which is a multiple of $3$.
  • The minimum number of steps to walk clockwise from rest area $4$ to rest area $2$ is $5$, which is not a multiple of $3$.
  • The minimum number of steps to walk clockwise from rest area $4$ to rest area $3$ is $6$, which is a multiple of $3$.

Therefore, there are four possible pairs $(s,t)$.

Sample 2 Input

2 1000000
1 1

Sample 2 Output

0

Sample 3 Input

9 5
9 9 8 2 4 4 3 5 3

Sample 3 Output

11

Source/Category