cswork / OAOpen practice workspace

Point72OA #1

Get Triplet Count

Estimated MediumJudge-ready

Topics (AI-labelled)HashingBits & Math

Given daily stock prices arr and a positive integer d, count the triplets (i,j,k) of distinct indices with i<j<k such that arr[i]+arr[j]+arr[k] is divisible by d.

Input

The first line contains n and d, and the second line contains n integers arr. Ranges on this site: 0≤n≤2000, 1≤d≤1000, -2³¹≤arr[i]≤2³¹−1. The bounds n≤2000 and d≤1000 and the allowance for negative numbers were added by this site for the OJ; the original site did not give complete constraints.

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:

0 1

Output:

0

Example 3

Input:

1 1
1

Output:

0

Example notes

This problem follows OAMaster's explicit reference to LeetCode 2964 and counts distinct index combinations; triplets with equal values but different indices are still considered different.

Editorial

Loading solution…