cswork / OA打开练习工作台

AmazonOA #181

Find Number of Ways to Group Parcels (Also for Amazon Japan)

估计困难可在线判题

考点(AI 标注)位运算哈希计数

Each package has its own identity, so packages are distinct even when their weights are equal. Split all packages into unordered pairs, using every package exactly once; the absolute weight difference within each pair must be wt. Find the number of complete groupings modulo 1000000007, and return 0 if no complete grouping exists. A clause in the original text about "the number of single pairs" contradicts the main statement and the complete-grouping example whose output is 6; this site explicitly adopts the meaning of the main statement and that example, i.e. pairing up all packages.

输入格式

The first line contains n wt; the second line contains the weights. This site uses 1≤n≤100000, 0≤wt≤10^9, weights 1..10^9.

输出格式

Output a single integer, the answer.

样例 1

输入:

8 1
4 5 5 4 4 5 2 3

输出:

6

样例 2

输入:

4 0
1 1 1 1

输出:

3

样例 3

输入:

3 1
1 2 3

输出:

0

样例说明

The answers are 6, 3 and 0.