#abc367d. D - Pedometer

D - Pedometer

Score : 400400 points

问题陈述

湖边有 NN 个休息区。 休息区按顺时针方向编号为 11, 22, ..., NN。 从休息区 ii 顺时针走到休息区 i+1i+1(其中休息区 N+1N+1 指的是休息区 11)需要 AiA_i 步。 从休息区 ss 顺时针走到休息区 ttsts \neq t)所需的最少步数是 MM 的倍数。 找出可能的 (s,t)(s,t) 对数。

以上为大语言模型 kimi 翻译,仅供参考。

Problem Statement

There are NN rest areas around a lake.
The rest areas are numbered 11, 22, ..., NN in clockwise order.
It takes AiA_i steps to walk clockwise from rest area ii to rest area i+1i+1 (where rest area N+1N+1 refers to rest area 11).
The minimum number of steps required to walk clockwise from rest area ss to rest area tt (sts \neq t) is a multiple of MM.
Find the number of possible pairs (s,t)(s,t).

Constraints

  • All input values are integers
  • 2N2×1052 \le N \le 2 \times 10^5
  • 1Ai1091 \le A_i \le 10^9
  • 1M1061 \le M \le 10^6

Input

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

NN MM

A1A_1 A2A_2 \dots ANA_N

Output

Print the answer as an integer.

Sample Input 1

4 3
2 1 4 3

Sample Output 1

4
  • The minimum number of steps to walk clockwise from rest area 11 to rest area 22 is 22, which is not a multiple of 33.
  • The minimum number of steps to walk clockwise from rest area 11 to rest area 33 is 33, which is a multiple of 33.
  • The minimum number of steps to walk clockwise from rest area 11 to rest area 44 is 77, which is not a multiple of 33.
  • The minimum number of steps to walk clockwise from rest area 22 to rest area 33 is 11, which is not a multiple of 33.
  • The minimum number of steps to walk clockwise from rest area 22 to rest area 44 is 55, which is not a multiple of 33.
  • The minimum number of steps to walk clockwise from rest area 22 to rest area 11 is 88, which is not a multiple of 33.
  • The minimum number of steps to walk clockwise from rest area 33 to rest area 44 is 44, which is not a multiple of 33.
  • The minimum number of steps to walk clockwise from rest area 33 to rest area 11 is 77, which is not a multiple of 33.
  • The minimum number of steps to walk clockwise from rest area 33 to rest area 22 is 99, which is a multiple of 33.
  • The minimum number of steps to walk clockwise from rest area 44 to rest area 11 is 33, which is a multiple of 33.
  • The minimum number of steps to walk clockwise from rest area 44 to rest area 22 is 55, which is not a multiple of 33.
  • The minimum number of steps to walk clockwise from rest area 44 to rest area 33 is 66, which is a multiple of 33.

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

Sample Input 2

2 1000000
1 1

Sample Output 2

0

Sample Input 3

9 5
9 9 8 2 4 4 3 5 3

Sample Output 3

11