We use cookies to ensure you have the best browsing experience on our website. Please read our cookie policy for more information about how we use cookies.
  • HackerRank Home
  • |
  • Prepare
  • Certify
  • Compete
  • Apply
  • Hiring developers?
  1. Prepare
  2. Algorithms
  3. Bit Manipulation
  4. Stone Game

Stone Game

Problem
Submissions
Leaderboard
Discussions
Editorial

Alice and Bob are playing the game of Nim with piles of stones with sizes . If Alice plays first, she loses if and only if the 'xor sum' (or 'Nim sum') of the piles is zero, i.e., .

Since Bob already knows who will win (assuming optimal play), he decides to cheat by removing some stones in some piles before the game starts. However, to reduce the risk of suspicion, he must keep at least one pile unchanged. Your task is to count the number of ways Bob can remove the stones to force Alice into losing the game. Since the number can be very large, output the number of ways modulo . Assume that both players will try to optimize their strategy and try to win the game.

Input Format

The first line of the input contains an integer denoting the number of piles. The next line contains space-separated integers indicating the sizes of the stone piles.

Constraints

Output Format

Print a single integer denoting the number of ways Bob can force Alice to lose the game, modulo .

Sample Input 0

3
1 2 3

Sample Output 0

4

Explanation 0

The answer is . The four possible resulting lists of piles is:

Note that is not allowed since he must keep one pile unchanged.

Sample Input 1

10
10 10 1 1 1 1 1 10 10 10

Sample Output 1

321616

Author

wanbo

Difficulty

Hard

Max Score

70

Submitted By

1319

Need Help?


View discussions
View editorial
View top submissions

rate this challenge

MORE DETAILS

Download problem statement
Download sample test cases
Suggest Edits
  • Blog
  • Scoring
  • Environment
  • FAQ
  • About Us
  • Helpdesk
  • Careers
  • Terms Of Service
  • Privacy Policy

Cookie support is required to access HackerRank

Seems like cookies are disabled on this browser, please enable them to open this website