Link with Arithmetic Progression
时间限制:C/C++/Rust/Pascal 3秒,其他语言6秒
空间限制:C/C++/Rust/Pascal 256 M,其他语言512 M
Special Judge, 64bit IO Format: %lld

题目描述

The input size for this problem is huge, you may refer to the code in notes for faster input.

Be aware of the error caused by using floating point numbers.

Link has an array a of length n. NIO wants it to be an arithmetic progression(i.e., ).

Link can arbitrarily modify the value of a_i. For each i, he can modify at most once. Suppose Link changed the value from a_i to a_i', the cost is .

What is the minimum cost to make a an arithmetic progression?

输入描述:

Each test contains multiple test cases. The first line contains the number of test cases T (). Description of the test cases follows.

The first line contains an integer n ().

The second line contains n integers ().

It is guaranteed that the sum of n over all test cases does not exceed .

输出描述:

For each case, output your answer in one line.

Your answer is considered correct if its absolute or relative error does not exceed .

Formally, let your answer be a, and the jury's answer be b. Your answer is accepted if and only if .
示例1

输入

复制
3
3
-1 0 1
3
0 0 1
13
1 1 4 5 1 4 1 9 1 9 8 1 0

输出

复制
0.000000000000000
0.166666666666667
129.225274725274716

说明

In the second example, you may change a to [-\frac{1}{6},\frac{1}{3},\frac{5}{6}] to minimize the cost.

备注:

Reference code:

#include <cstdio>
#include <cctype>

namespace GTI
{
    char gc(void)
       {
        const int S = 1 << 16;
        static char buf[S], *s = buf, *t = buf;
        if (s == t) t = buf + fread(s = buf, 1, S, stdin);
        if (s == t) return EOF;
        return *s++;
    }
    int gti(void)
       {
        int a = 0, b = 1, c = gc();
        for (; !isdigit(c); c = gc()) b ^= (c == '-');
        for (; isdigit(c); c = gc()) a = a * 10 + c - '0';
        return b ? a : -a;
    }
}
using GTI::gti;

int main(){
    // Use gti() to get next int from standard input.
}