#ARC144F. [ARC144F] Arithmetic Sequence Nim

[ARC144F] Arithmetic Sequence Nim

Score : 900900 points

Problem Statement

You are given a positive integer mm, a non-negative integer aa (0a<m0\leq a < m), and a sequence of positive integers A=(A1,,AN)A = (A_1, \ldots, A_N).

A set XX of positive integers is defined as X={x>0xa(modm)}X = \{x>0\mid x\equiv a \pmod{m}\}.

Alice and Bob will play a game against each other. They will alternate turns performing the following operation, with Alice going first:

  • Choose a pair (i,x)(i,x) of an index ii (1iN1\leq i\leq N) and a positite integer xXx\in X such that xAix\leq A_i. Change AiA_i to AixA_i - x. If there is no such (i,x)(i, x), the current player loses and the game ends.

Find the number, modulo 998244353998244353, of pairs (i,x)(i, x) that Alice can choose in her first turn so that she wins if both players play optimally in subsequent turns.

Constraints

  • 1N3×1051\leq N\leq 3\times 10^5
  • 0a<m1090\leq a < m\leq 10^9
  • max(1,a)Ai1018\max(1, a) \leq A_i\leq 10^{18}

Input

Input is given from Standard Input in the following format:

NN mm aa

A1A_1 A2A_2 \ldots ANA_N

Output

Print the number, modulo 998244353998244353, of pairs (i,x)(i, x) that Alice can choose in her first turn so that she wins if both players play optimally in subsequent turns.

3 1 0
5 6 7
3

We have X={1,2,3,4,5,}X = \{1, 2, 3, 4, 5, \ldots\}. Three pairs (i,x)(i,x) satisfy the condition: (1,4)(1,4), (2,4)(2,4), (3,4)(3,4).

5 10 3
5 9 18 23 27
3

We have X={3,13,23,33,43,}X = \{3, 13, 23, 33, 43, \ldots\}. Three pairs (i,x)(i,x) satisfy the condition: (4,23)(4,23), (5,3)(5,3), (5,13)(5,13).

4 10 8
100 101 102 103
0

Alice cannot win even if she plays optimally. Thus, zero pairs (i,x)(i,x) satisfy the condition.

5 2 1
111111111111111 222222222222222 333333333333333 444444444444444 555555555555555
943937640

833333333333334833333333333334 pairs (i,x)(i,x) satisfy the condition. Print the count modulo 998244353998244353.