Ethflow Round 1 (Codeforces Round 1001, Div. 1 + Div. 2)
C
Cirno and Operations
Codeforces
1200
原题
← BD →
翻译中…

Cirno has a sequence $a$ of length $n$. She can perform either of the following two operations for any (possibly, zero) times unless the current length of $a$ is $1$:

翻译中…
  • Reverse the sequence. Formally, $[a_1,a_2,\ldots,a_n]$ becomes $[a_n,a_{n-1},\ldots,a_1]$ after the operation.
  • Replace the sequence with its difference sequence. Formally, $[a_1,a_2,\ldots,a_n]$ becomes $[a_2-a_1,a_3-a_2,\ldots,a_n-a_{n-1}]$ after the operation.
翻译中…

Find the maximum possible sum of elements of $a$ after all operations.

翻译中…

Input

翻译中…

The first line of input contains a single integer $t$ ($1 \leq t \leq 100$) — the number of input test cases.

翻译中…

The first line of each test case contains a single integer $n$ ($1\le n\le 50$) — the length of sequence $a$.

翻译中…

The second line of each test case contains $n$ integers $a_1,a_2,\ldots,a_n$ ($|a_i|\le 1000$) — the sequence $a$.

翻译中…

Output

翻译中…

For each test case, print an integer representing the maximum possible sum.

翻译中…

Note

翻译中…

In the first test case, Cirno can not perform any operation, so the answer is $-1000$.

翻译中…

In the second test case, Cirno firstly reverses the sequence, then replaces the sequence with its difference sequence: $[5,-3]\to[-3,5]\to[8]$. It can be proven that this maximizes the sum, so the answer is $8$.

翻译中…

In the third test case, Cirno can choose not to operate, so the answer is $1001$.

翻译中…

样例

Input #1
5
1
-1000
2
5 -3
2
1000 1
9
9 7 9 -9 9 -8 7 -8 9
11
678 201 340 444 453 922 128 987 127 752 0
Output #1
-1000
8
1001
2056
269891
InputCopy OutputCopy
题目信息
题号
2062C
时间限制
2 s
内存限制
512 MB
标签
暴力
数学

题面与样例版权归 Codeforces 及出题人所有;中文翻译由 AI 生成(CI 管线),如有出入请以原文为准。