An interesting game

3.1

13 votes
2D dynamic programming, Algorithms, Bit Manipulation, C++, Dynamic Programming
Problem

Bob and Alice are playing with an array A[] of n elements with Bob starting the game. In each turn:

  1. A player picks a non-zero number of elements from A[] with the same value and remove it from A[].
  2. The player whose turn makes array A[] empty wins the game.

Alice modifies the game a bit. She selects some distinct elements that are present in A[] and removes all other elements that are not selected from A[]. Now, the game is played using this modified array. For example, if A=[1,1,3,12,2,34,2] and Alice selects values (1, 2, 34), then the array with which the game is played is [1, 1, 2, 34, 2].

Find the number of possible subsets of elements that Alice can select to modify A[] such that Alice must win if both the players play optimally.

Note 

  • Consider an empty subset as a valid answer.
  • Since the number of possible subsets can be large, print the answer modulo 109+7.

Input format

  • The first line contains N.
  • The next line contains N space-separated integers denoting the elements of A[].

Output format

Print the number of possible subsets of elements that Alice can select to modify A[] such that Alice must win if both the players play optimally modulo 109+7.

Constraints
1N1000001A[i]100

Sample Input
5
1 1 2 2 3
Sample Output
2
Time Limit: 1
Memory Limit: 256
Source Limit:
Explanation

Two possible solutions are:

  1. Empty Subset
  2. {1,2}
Editor Image

?