#arc144f. [arc144_f]Arithmetic Sequence Nim
[arc144_f]Arithmetic Sequence Nim
Problem Statement
You are given a positive integer , a non-negative integer (), and a sequence of positive integers .
A set of positive integers is defined as .
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 of an index () and a positite integer such that . Change to . If there is no such , the current player loses and the game ends.
Find the number, modulo , of pairs that Alice can choose in her first turn so that she wins if both players play optimally in subsequent turns.
Constraints
Input
Input is given from Standard Input in the following format:
Output
Print the number, modulo , of pairs that Alice can choose in her first turn so that she wins if both players play optimally in subsequent turns.
Sample Input 1
3 1 0
5 6 7
Sample Output 1
3
We have . Three pairs satisfy the condition: , , .
Sample Input 2
5 10 3
5 9 18 23 27
Sample Output 2
3
We have . Three pairs satisfy the condition: , , .
Sample Input 3
4 10 8
100 101 102 103
Sample Output 3
0
Alice cannot win even if she plays optimally. Thus, zero pairs satisfy the condition.
Sample Input 4
5 2 1
111111111111111 222222222222222 333333333333333 444444444444444 555555555555555
Sample Output 4
943937640
pairs satisfy the condition. Print the count modulo .