#P5970. [POI 2016] Nim z utrudnieniem

[POI 2016] Nim z utrudnieniem

Problem Description

Two players, A and B, play a game. There are mm stones in total. A splits them into nn piles, where the numbers of stones in each pile are a1,a2,...,ana_1,a_2,...,a_n. In each round, a player may choose one pile and remove any positive number of stones from it, but they cannot remove zero stones. The first player who cannot make a move loses.

Before the game starts, B may discard some piles of stones, but B must ensure that the number of discarded piles is a multiple of dd, and B cannot discard all stones.

A moves first. Ask how many ways B can discard piles such that B can win.

Input Format

The first line contains two positive integers n,dn,d.

The second line contains nn positive integers a1,a2,...,ana_1,a_2,...,a_n.

Output Format

Output one line with one integer, the number of valid ways modulo 109+710^9+7.

5 2
1 3 4 1 2
2

Hint

For 100%100\% of the testdata, 1n5×1051\le n\le 5\times 10^5, 1d101\le d\le 10, 1ai1061\le a_i\le 10^6. mm is not given directly, but the testdata guarantees that 1m1071\le m\le 10^7.

Translated by ChatGPT 5