|
||||||||||
Unfair NimTime Limit: 20000/10000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)Total Submission(s): 997 Accepted Submission(s): 411 Problem Description Alice and Bob are tired of playing the Nim game, because they are so clever that before the beginning of the game, they have already known the result. Here is their conversation: Bob: It's unfair. I am always the second player, but you know, if the number of stones in each pile are distributed uniformly, at most time the first player, i.e., you, will win. Alice: Yes, I agree with you. So I give you a chance to beat me, you are allowed to add some stones in some piles (but you can't create a new pile) before the game starts, so that you can win as the second player. Bob: Yeah, that's cool. I will win definitely. Alice: But note, you must add the minimum of the stones. If you add more stones than necessary to win, your winning will be cancelled. Bob: er... Let me see... For the readers who are not familiar with the Nim game (from Wikipedia): Nim is a mathematical game of strategy in which two players take turns removing stones from distinct heaps. On each turn, a player must remove at least one stone, and may remove any number of stones provided they all come from the same heap. The player who take the last stone wins. Input The first line of each test case contains an integer N (1 <= N <= 10), the number of piles at the beginning. The next line contains N positive integers, indicating the number of stones in each pile. The number of stones in each pile is no more than 1,000,000. Output Output one line for each test case, indicating the minimum number of stones to add. If it is impossible, just output "impossible". Sample Input
Sample Output
Author TJU Source | ||||||||||
|