#P1844C. Particles
Particles
No submission language available for this problem.
Description
You have discovered mysterious particles on a line with integer charges of . You have a device that allows you to perform the following operation:
- Choose a particle and remove it from the line. The remaining particles will shift to fill in the gap that is created. If there were particles with charges and directly to the left and right of the removed particle, they combine into a single particle of charge .
For example, if the line of particles had charges of , performing the operation on the th particle will transform the line into .

If we then use the device on the st particle in this new line, the line will turn into .
You will perform operations until there is only one particle left. What is the maximum charge of this remaining particle that you can obtain?
Each test contains multiple test cases. The first line contains the number of test cases (). The description of the test cases follows.
The first line of each test case contains a single integer ().
The second line of each test case contains integers ().
It is guaranteed that the sum of over all test cases does not exceed .
For each test case, output one integer, the maximum charge of the remaining particle.
Input
Each test contains multiple test cases. The first line contains the number of test cases (). The description of the test cases follows.
The first line of each test case contains a single integer ().
The second line of each test case contains integers ().
It is guaranteed that the sum of over all test cases does not exceed .
Output
For each test case, output one integer, the maximum charge of the remaining particle.
Note
In the first test case, the best strategy is to use the device on the th particle, then on the st particle (as described in the statement), and finally use the device on the new rd particle followed by the st particle.
In the second test case, the best strategy is to use the device on the th particle to transform the line into , then on the nd particle to transform the line into . Be wary of integer overflow.
In the third test case, there is only one particle, so no operations can be performed.