QOJ.ac

QOJ

Time Limit: 1 s Memory Limit: 256 MB Total points: 100

#13293. Stone Game

Statistics

After studying the Nim game and its various variants, Orez discovered a brand-new stone-taking game. The game is as follows:

There are $n$ piles of stones arranged in a row. The game is played by two players who take turns. In each turn, a player can take any number of stones from either the leftmost or the rightmost pile. A player may choose to remove the entire pile, but they must take at least one stone. The player who cannot make a move loses.

Orez asks: for any given initial configuration, does a winning strategy exist for the first player?

Input

The first line contains an integer $T$, representing the number of test cases. For each test case, the first line contains an integer $n$, representing the number of piles of stones; the second line contains $n$ integers $a_i$, representing the number of stones in each pile in order.

Output

For each test case, output a single integer, 0 or 1. Here, 1 indicates that the first player has a winning strategy, and 0 indicates that they do not.

Examples

Input 1

1
4
3 1 9 4

Output 1

0

Constraints

For 30% of the data: $n \le 5$, $a_i \le 10^5$.

For 100% of the data: $T \le 10$, $n \le 1000$, the number of stones in each pile $\le 10^9$.

Discussions

About Discussions

The discussion section is only for posting: General Discussions (problem-solving strategies, alternative approaches), and Off-topic conversations.

This is NOT for reporting issues! If you want to report bugs or errors, please use the Issues section below.

Open Discussions 0
No discussions in this category.

Issues

About Issues

If you find any issues with the problem (statement, scoring, time/memory limits, test cases, etc.), you may submit an issue here. A problem moderator will review your issue.

Guidelines:

  1. This is not a place to publish discussions, editorials, or requests to debug your code. Issues are only visible to you and problem moderators.
  2. Do not submit duplicated issues.
  3. Issues must be filed in English or Chinese only.
Active Issues 0
No issues in this category.
Closed/Resolved Issues 0
No issues in this category.