There are two friends Alice and Bob. They have a packet of $n$ candies. They want to split the candies between them, and to do so, they kept them all in a single line. The $i^{\text{th}}$ candy in the line has a sweetness value of $a_i$. They decided to take turns in picking the candies. Alice has the first turn. In a person's turn, they either eat the leftmost candy or the rightmost candy with equal probability.
Can you find the expected value of sum of sweetness of the candies eaten by Alice?
Your answer is considered correct if its absolute or relative error doesn't exceed $10^{-6}$ .

-----Input:-----
- The first line will contain $T$, number of testcases. Then the testcases follow. 
- First line of each testcase contains a single integer $n$ denoting the number of candies.
- Second line of each testcase contains  $n$ space separated integers representing $a_1,a_2,a_3,...a_n$ respectively.

-----Output:-----
For each testcase, output the expected value of sum of sweetness of the candies which Alice eats.

-----Constraints-----
- $1 \leq T \leq 10$
- $1 \leq n \leq 10^3$
- $1 \leq a_i \leq 10^6$
- Sum of $n$ across all the tests $\leq 10^3$

-----Sample Input:-----
2
2
1 2
3
1 2 3

-----Sample Output:-----
1.500000000000000
4.000000000000000

-----EXPLANATION:-----
In the first sample, Alice eats either the first or the second candy with equal probability. Hence, expected value is $(1+2)/2 = 1.5$
For the second sample, expected value is $4$.

Source: codechef | Difficulty: UNKNOWN_DIFFICULTY


Solutions:
from sys import setrecursionlimit
setrecursionlimit(10 ** 9)

def solve(i, j, c=0):
	if i > j:
		return 0
	if (i, j) in dp:
		return dp[i, j]
	x0 = solve(i + 1, j, c ^ 1)
	x1 = solve(i, j - 1, c ^ 1)
	if c == 0:
		y = 1 << j - i
		x0 += a[i] * y
		x1 += a[j] * y
	dp[i, j] = x0 + x1
	return dp[i, j]
for _ in range(int(input())):
	n = int(input())
	a = list(map(int, input().split()))
	dp = {}
	total = solve(0, n - 1)
	print(total / (1 << n))


for _ in range(int(input())):
	n = int(input())
	a = list(map(int, input().split()))
	a1 = [list((0 for _ in range(n + 1))) for __ in range(n + 1)]
	a2 = [list((0 for _ in range(n + 1))) for __ in range(n + 1)]
	for i in range(n):
		a1[i][i] = a[i]
		a2[i][i] = 0
	for i in range(n - 1, -1, -1):
		for j in range(i, n):
			a1[i][j] = 0.5 * (a[i] + a2[i + 1][j]) + 0.5 * (a[j] + a2[i][j - 1])
			a2[i][j] = 0.5 * a1[i + 1][j] + 0.5 * a1[i][j - 1]
	print(a1[0][n - 1])


coeff = [[1], [0.5, 0.5]]
for i in range(2, 1001):
	l1 = []
	l1.append(1 - coeff[-1][0] / 2)
	for j in range(1, i):
		p = (coeff[-1][j] + coeff[-1][j - 1]) / 2
		l1.append(1 - p)
	l1.append(l1[0])
	coeff.append(l1)
for i in range(int(input())):
	n = int(input())
	arr = [int(i) for i in input().split()]
	ans = 0
	for i in range(n):
		ans += arr[i] * coeff[n - 1][i]
	print(ans)


def recSolve(a, dp, l, r):
	if l > r:
		return 0
	if dp[l][r] != 0.0:
		return dp[l][r]
	x = a[l] + (recSolve(a, dp, l + 2, r) + recSolve(a, dp, l + 1, r - 1)) * 0.5
	y = a[r] + (recSolve(a, dp, l + 1, r - 1) + recSolve(a, dp, l, r - 2)) * 0.5
	dp[l][r] = (x + y) * 0.5
	return dp[l][r]
for _ in range(int(input())):
	n = int(input())
	a = list(map(int, input().split()))
	dp = [[0.0] * (n + 1) for i in range(n + 1)]
	res = recSolve(a, dp, 0, n - 1)
	print(res)