Output #1
6
5
185
739
In the first test case, $A$ itself is a "good sequence." For example, we can make all elements of $A$ equal to $0$ with the following steps:
1. Let $i=3$. Then, $S=A_3+A_4=5$. Replace $A_3$ and $A_4$ with $\left\lfloor \frac{5}{2} \right\rfloor = 2$, resulting in $A=(0,1,2,2)$.
2. Let $i=2$. Then, $S=A_2+A_3=3$. Replace $A_2$ and $A_3$ with $\left\lfloor \frac{3}{2} \right\rfloor = 1$, resulting in $A=(0,1,1,2)$.
3. Let $i=3$. Then, $S=A_3+A_4=3$. Replace $A_3$ and $A_4$ with $\left\lfloor \frac{3}{2} \right\rfloor = 1$, resulting in $A=(0,1,1,1)$.
4. Let $i=1$. Then, $S=A_1+A_2=1$. Replace $A_1$ and $A_2$ with $\left\lfloor \frac{1}{2} \right\rfloor = 0$, resulting in $A=(0,0,1,1)$.
5. Let $i=2$. Then, $S=A_2+A_3=1$. Replace $A_2$ and $A_3$ with $\left\lfloor \frac{1}{2} \right\rfloor = 0$, resulting in $A=(0,0,0,1)$.
6. Let $i=3$. Then, $S=A_3+A_4=1$. Replace $A_3$ and $A_4$ with $\left\lfloor \frac{1}{2} \right\rfloor = 0$, resulting in $A=(0,0,0,0)$.
Thus, taking $B = A$ achieves the maximum sum $0+1+2+3=6$.
In the second test case, $A$ is not a "good sequence." However, if we take $B = (0,0,2,3)$, then $B$ is a "good sequence" and satisfies the conditions.