cswork / OAOpen practice workspace

RubrikOA #16

Stock Prices

Estimated MediumJudge-ready

Topics (AI-labelled)HashingBits & Math

Count the triplets of increasing indices (i,j,k) such that the sum of the prices on those three days is divisible by d. Different index combinations with the same prices are counted separately.

Input

The first line contains n d; the second line contains n positive integer prices. Original constraints: n≤1000, price≤10^9, 2≤d≤10^6.

Output

Output the number of index triplets that satisfy the condition.

Example 1

Input:

5 5
3 3 4 7 8

Output:

3

Example 2

Input:

3 3
1 1 1

Output:

1

Example 3

Input:

6 2
1 2 3 4 5 6

Output:

10

Editorial

Loading solution…