Hard Arithmetic#12257

Hard Arithmetic

3 seconds
256 megabytes
Hard

MathModel is obsessed with arithmetic sequences. He has an array of positive integers of length . He wants to transform the array into an arithmetic sequence. To do that, he can perform the following operation any number of times:

He wants to know the minimum cost to transform his array into an arithmetic sequence.

An arithmetic sequence is an array of length such that a_i = m \cdot i + c for some integers and .

Input

The first line contains a single integer (1 \le t \le 10^4) — the number of test cases.

The first line of each test case contains a single integer (2 \le n \le 2 \cdot 10^5) — the length of the array .

The second line of each test case contains integers a_1, a_2, \ldots, a_n (1 \le a_1, a_2, \ldots, a_n \le 10^9) — the array .

It is guaranteed that the sum of over all test cases does not exceed 2 \cdot 10^5.

Output

For each test case, output a single integer: the minimum number of operations required so that becomes an arithmetic progression.

Examples

Example 1

Loading
Loading

Scoring

  1. Subtask 1 ( points): n = 3.

  2. Subtask 2 ( points): n \le 10.

  3. Subtask 3 ( points): \sum n \le 500.

  4. Subtask 4 ( points): \sum n \le 2000.

  5. Subtask 5 ( points): a_i \le 10.

  6. Subtask 6 ( points): a_i \le 100.

  7. Subtask 7 ( points): a_i \le 1000.

  8. Subtask 8 ( points): a_i \le 10^6.

  9. Subtask 9 ( points): No additional constraints