CF1853A.Desorting

传统题 时间 2000 ms 内存 256 MiB 3 尝试 1 已通过 1 标签

Desorting

Call an array aa of length nn sorted if a1a2an1ana_1 \leq a_2 \leq \ldots \leq a_{n-1} \leq a_n.

Ntarsis has an array aa of length nn.

He is allowed to perform one type of operation on it (zero or more times):

  • Choose an index ii (1in11 \leq i \leq n-1).
  • Add 11 to a1,a2,,aia_1, a_2, \ldots, a_i.
  • Subtract 11 from ai+1,ai+2,,ana_{i+1}, a_{i+2}, \ldots, a_n.

The values of aa can be negative after an operation.

Determine the minimum operations needed to make aa not sorted.

Input

Each test contains multiple test cases. The first line contains the number of test cases tt (1t1001 \le t \le 100). The description of the test cases follows.

The first line of each test case contains a single integer nn (2n5002 \leq n \leq 500) — the length of the array aa.

The next line contains nn integers a1,a2,,ana_1, a_2, \ldots, a_n (1ai1091 \leq a_i \leq 10^9) — the values of array aa.

It is guaranteed that the sum of nn across all test cases does not exceed 500500.

Output

Output the minimum number of operations needed to make the array not sorted.

Note

In the first case, we can perform 11 operation to make the array not sorted:

  • Pick i=1i = 1. The array aa then becomes [2,0][2, 0], which is not sorted.

In the second case, we can perform 22 operations to make the array not sorted:

  • Pick i=3i = 3. The array aa then becomes [2,9,11,12][2, 9, 11, 12].
  • Pick i=3i = 3. The array aa then becomes [3,10,12,11][3, 10, 12, 11], which is not sorted.

It can be proven that 11 and 22 operations are the minimal numbers of operations in the first and second test cases, respectively.

In the third case, the array is already not sorted, so we perform 00 operations.

Samples

4
2
1 1
4
1 8 10 13
3
1 3 2
3
1 9 14
1
2
0
3

在线编程 IDE

建议全屏模式获得最佳体验