Given an array of integers $Y=[y_1,y_2,\ldots,y_n]$, we have $n$ line segments, such that, the endpoints of $i^{\mbox{th}}$ segment  are $(i,0)$ and $(i,y_i)$. Imagine that from the top of each segment a horizontal ray is shot to the left, and this ray stops when it touches another segment or it hits the y-axis. We construct an array of $n$ integers, $[v_1,v_2,\ldots,v_n]$, where $v_i$ is equal to length of ray shot from the top of segment $\boldsymbol{i}$. We define $V(y_1,y_2,...,y_n)=v_1+v_2+…+v_n$. 

For example, if we have $Y=[3,2,5,3,3,4,1,2]$, then $v_1,v_2,...,v_8=[1,1,3,1,1,3,1,2]$, as shown in the picture below:

For each permutation $\boldsymbol{p}$ of $[1,2,\ldots,n]$, we can calculate $V(y_{p_1},y_{p_2},\ldots,y_{p_n})$. If we choose a uniformly random permutation $\boldsymbol{p}$ of $[1,2,\ldots,n]$, what is the expected value of $V(y_{p_1},y_{p_2},\ldots,y_{p_n})$?

Input Format

The first line contains a single integer T (1 <=T<= 100). T test cases follow. 

The first line of each test-case is a single integer N (1 <= n <= 50), and the next line contains positive integer numbers $y_1,y_2\ldots,y_n$ separated by a single space ($0<y_i<=1000$).

Output Format

For each test-case output expected value of $V(y_{p_1},y_{p_2},\ldots,y_{p_n})$, rounded to two digits after the decimal point.

Sample Input
6
3
1 2 3
3
3 3 3
3
2 2 3
4
10 2 4 4
5
10 10 10 5 10
6
1 2 3 4 5 6

Sample Output
4.33
3.00
4.00
6.00
5.80
11.15

Explanation

Case 1: We have $V(1,2,3)=1+2+3=6,V(1,3,2)=1+2+1=4,V(2,1,3)=1+1+3=5$, 

$V(2,3,1)=1+2+1=4,V(3,1,2)=1+1+2=4,V(3,2,1)=1+1+1=3$. 

Average of these values is 4.33. 

Case 2: No matter what the permutation is, $V(y_{p_1},y_{p_2},y_{p_3})=1+1+1=3$, so the answer is 3.00. 

Case 3: $V(y_1,y_2,y_3)=V(y_2,y_1,y_3)=5$, 

$V(y_1,y_3,y_2)=V(y_2,y_3,y_1)=4$, 

$V(y_3,y_1,y_2)=V(y_3,y_2,y_1)=3$, 

and average of these values is 4.00.

Source: hackerrank | Difficulty: MEDIUM
Tags: Probability


Solutions:
cs = int(input())
from functools import reduce

def perm(n, r):
	return reduce(lambda x, y: x * y, range(n - r + 1, n + 1), 1)

def fact(n):
	return perm(n, n)
for c in range(cs):
	n = int(input())
	li = [int(i) for i in input().strip().split()]
	li.sort()
	p = {}
	for i in li:
		p[li.index(i)] = li.count(i)
	rt = 0
	for i in p:
		r = 0
		for j in range(i + 1):
			r += (n - 1 - i) * perm(i, j) * (j + 1) * fact(n - j - 1)
		for j in range(i + 1):
			r += (j + 1) * perm(i, j) * fact(n - j - 1)
		r *= p[i]
		rt += r
	print('%0.2f' % (rt / fact(n)))


def EV(sticks):
	sticks.sort(reverse=True)
	(s, k) = (0, 0)
	while k < len(sticks):
		n = 0
		y = sticks[k]
		while k < len(sticks) and sticks[k] == y:
			k += 1
			n += 1
		s += n * ((len(sticks) + 1) / (k + 1))
	return s
T = int(input())
for t in range(0, T):
	N = int(input())
	sticks = [int(x) for x in input().split(' ')]
	print('{0:.2f}'.format(EV(sticks)))


from collections import Counter

def main():
	t = int(input())
	for _ in range(t):
		n = int(input())
		sticks = [int(i) for i in input().split()]
		print('%.2f' % expected_len(sticks))

def expected_len(sticks):
	expected = 0
	length = len(sticks)
	count = 0
	s = Counter(sticks)
	for stick in sorted(s, reverse=True):
		count += s[stick]
		expected += s[stick] * (length + 1) / (count + 1)
	return expected
main()


import sys
import collections
T = int(sys.stdin.readline())
for case in range(T):
	N = int(sys.stdin.readline())
	sticks = [int(X) for X in sys.stdin.readline().split()]
	totals = collections.defaultdict(int)
	for stick in sticks:
		totals[stick] += 1
	acc = N
	cum_distn = dict()
	for k in sorted(totals.keys()):
		cum_distn[k] = acc
		acc -= totals[k]
	greater_or_equals = [cum_distn[stick] for stick in sticks]
	print('%0.2f' % sum([(N + 1) / (k + 1) for k in greater_or_equals]))


import sys
data = sys.stdin.readlines()
nTestcases = int(data[0])
for iTest in range(nTestcases):
	nLines = int(data[iTest * 2 + 1])
	points = [int(p) for p in data[iTest * 2 + 2].split()]
	nPoints = len(points)
	nom = nPoints + 1
	Vsum = 0
	for y in points:
		k = 1
		for y2 in points:
			if y2 >= y:
				k += 1
		Vsum += nom / k
	Vmean = Vsum
	print('%.2f' % Vmean)


from itertools import groupby

def expected(stick):
	stick = sorted(stick, reverse=True)
	gp = groupby(stick)
	n = sum((1 for _ in next(gp)[1]))
	xp = float(n)
	for g in gp:
		k = sum((1 for _ in g[1]))
		xp += k * (xp / (n + 1) + 1)
		n += k
	return xp
ncases = int(input())
for _ in range(ncases):
	size = int(input())
	stick = [int(f) for f in input().split()]
	print('%.2f' % expected(stick))


T = int(input())
for t in range(T):
	N = int(input())
	Y = list(sorted(map(int, input().split())))

	def get_e(smaller):
		return (N + 1) / (N - smaller + 1)
	ans = 0
	neq_idx = None
	for (i, n) in enumerate(Y):
		if neq_idx == None or Y[neq_idx] != n:
			neq_idx = i
		ans += get_e(neq_idx)
	print('{0:.2f}'.format(ans))


def vertical_sticks(N, Y):
	return (N + 1) * sum((1 / (len([z for z in Y if z >= y]) + 1) for y in Y))

def main():
	T = int(input())
	for _ in range(T):
		N = int(input())
		Y = [int(i) for i in input().split()]
		print('%0.2f' % vertical_sticks(N, Y))
main()


t = int(input())
for i in range(t):
	n = int(input())
	a = [int(x) for x in input().split()]
	a.sort()
	s = 0
	while len(a):
		m = 1
		x = a.pop()
		while len(a) and x == a[len(a) - 1]:
			a.pop()
			m += 1
		s += m * (n + 1) / (n - len(a) + 1)
	print('%0.02f' % s)


T = int(input())
for _ in range(T):
	N = int(input())
	gt = []
	data = [int(x) for x in input().split()]
	for i in range(len(data)):
		gt.append(sum((1 for x in data if x >= data[i])))
	calc = (len(data) + 1) * sum([1 / (x + 1) for x in gt])
	print('{:.2f}'.format(calc))


for _ in range(int(input())):
	n = int(input())
	Y = list(map(int, input().split()))
	res = 0
	for y_i in Y:
		n_gte = len(list(filter(lambda x: x >= y_i, Y)))
		res += (n + 1) / (n_gte + 1)
	print('{:.2f}'.format(res))


import sys

def solve(Y, n):
	H = [0 for i in range(n)]
	for i in range(n):
		cnt = 0
		for j in range(n):
			if Y[i] <= Y[j]:
				cnt += 1
		H[i] = cnt
	res = 0.0
	for i in range(n):
		res += (n + 1) / float(H[i] + 1)
	return res
t = int(sys.stdin.readline().rstrip('\n'))
for i in range(t):
	n = int(sys.stdin.readline().rstrip('\n'))
	line = sys.stdin.readline().rstrip('\n')
	c = [int(x) for x in line.split(' ')]
	print('%.2f' % solve(c, n))


from collections import defaultdict
T = int(input())
for _ in range(T):
	N = int(input())
	iArr = tuple(map(int, input().split()))
	tDict = defaultdict(int)
	for i in iArr:
		tDict[i] += 1
	cArr = [(n, tDict[n]) for n in tDict]
	cArr.sort()
	GE = defaultdict(int)
	for i in range(len(cArr)):
		(n, val) = cArr[i]
		GE[n] = val + sum([cArr[x][1] for x in range(i + 1, len(cArr))])
	eSum = 0
	for i in range(N):
		k = GE[iArr[i]]
		eSum += (N + 1) / (k + 1)
	print('{:.2f}'.format(eSum))


t = int(input())
for i in range(t):
	n = int(input())
	arr = [int(x) for x in input().split(' ')]
	dat = []
	for x in arr:
		dat.append(len(list(filter(lambda y: y >= x, arr))))
	res = 0
	for x in dat:
		res += (n + 1) / (x + 1)
	print(format(res, '.2f'))


T = int(input())
for i in range(T):
	n = int(input())
	Y = [int(s) for s in input().split()]
	X = [sum((1 for y in Y if y >= i)) for i in Y]
	z = sum(((n + 1) / (x + 1) for x in X))
	print('%0.02f' % round(z, 2))


import itertools as it

def vertical(rays):
	l = len(rays) + 1
	ds = [sum(map(lambda i: i >= r, rays)) for r in rays]
	return round(sum([l / (d + 1) for d in ds]), 2)
times = int(input())
for _ in range(times):
	input()
	rays = list(map(int, input().split(' ')))
	print('{:.02f}'.format(vertical(rays)))


from os.path import basename, exists, expanduser, splitext, isfile
from os import getcwd
from sys import stdin
from array import array as ar
from collections import Counter
from functools import reduce as red
import math
import itertools as it
from itertools import accumulate as acc
lolPath = getcwd()
randid = '\\qosdjfoiz.txt'
home = isfile(lolPath + randid)

def inv(n):
	return pow(n, modo - 2, modo)
if home:
	filou = lolPath + '\\VertSticksInput00.txt'
	filin = 'D:\\ZeDaddy\\Documents\\Hack\\combinatorics\\JourneyOu03.txt'
	from mesures import ch
else:
	filou = None
modo = 10 ** 9 + 7
import math
N = 100001
trace = 0
if home:
	from mesures import ch, prof
rd = open(filou) if filou else stdin
for _ in range(int(rd.readline().strip())):
	rd.readline()
	A = sorted(map(int, rd.readline().strip().split()), reverse=True)
	nex = 1
	fracs = 0
	num = len(A) + 1
	for (a, b, c) in zip(A, A[1:], range(1, len(A) + 2)):
		if a == b:
			nex += 1
		else:
			fracs += num * nex / (c + 1)
			nex = 1
	fracs += num * nex / (len(A) + 1)
	res = fracs
	print('{:4.2f}'.format(res))


import collections
import math
t = int(input())
for _ in range(t):
	n = int(input())
	counts = collections.Counter(map(int, input().split()))
	num_smaller = 0
	lengths = 0
	for (_, count) in sorted(counts.items()):
		lengths += count * (1 + n) / (1 + n - num_smaller)
		num_smaller += count
	print(format(lengths, '.2f'))


def rank(list):
	buffer = []
	for i in range(len(list)):
		count = 0
		for j in range(len(list)):
			if list[j] >= list[i]:
				count += 1
		buffer.append(count)
	return buffer

def main():
	T = int(input())
	for t in range(T):
		N = int(input())
		string_values = input().split(' ')
		values = [int(el) for el in string_values]
		ranks = rank(values)
		total = 0
		for i in range(N):
			total += (N + 1) / (ranks[i] + 1)
		print('{:.2f}'.format(total))
main()


T = int(input())
for i in range(T):
	N = int(input())
	Y = input().split(' ')
	sumat = 0
	for i in range(N):
		count = 0
		for j in range(N):
			if int(Y[j]) >= int(Y[i]):
				count += 1
		sumat += float(N + 1) / float(count + 1)
	print('{0:.2f}'.format(sumat))


for _ in range(int(input())):
	n = int(input())
	Y = sorted([int(i) for i in input().strip().split()], reverse=True)
	D = [0] * n
	D[n - 1] = n
	for i in range(n - 2, -1, -1):
		if Y[i] == Y[i + 1]:
			D[i] = D[i + 1]
		else:
			D[i] = i + 1
	print('%.2f' % sum(((n + 1) / (d + 1) for d in D)))


t = int(input())
for i in range(t):
	n = int(input())
	sum = 0
	arr = []
	arr = input().split()
	arr = [float(a) for a in arr]
	arr.sort()
	temp = arr[0]
	arr[0] = n
	for k in range(1, n):
		if arr[k] == temp:
			temp = arr[k]
			arr[k] = arr[k - 1]
		else:
			temp = arr[k]
			arr[k] = n - k
	for m in range(n):
		sum += (n + 1.0) / float(arr[m] + 1.0)
	print('%.2f' % sum)


hist = {}

def exp_one(a, b, c):
	if a == 0:
		return 0.0
	if (a, b, c) in hist:
		return hist[a, b, c]
	pa = a / (a + b + c)
	pb = b / (a + b + c)
	pc = c / (a + b + c)
	va = 1.0 + exp_one(a - 1, b, c)
	vb = exp_one(a, b - 1, c) if b > 0 else 0.0
	vc = a / (a + b) + exp_one(a, b, c - 1) if c > 0 else 0.0
	rv = pa * va + pb * vb + pc * vc
	hist[a, b, c] = rv
	return rv

def exp_all(a):
	a = sorted(a)
	rv = 0
	pos = 0
	n = len(a)
	while pos < n:
		end = pos + 1
		while end < n and a[end] == a[pos]:
			end += 1
		rv += exp_one(end - pos, n - end, pos)
		pos = end
	return rv
num_probs = int(input())
for prob in range(num_probs):
	n = int(input())
	a = [int(x) for x in input().split()]
	print('%.2f' % exp_all(a))


T = int(input())
for t in range(T):
	n = int(input())
	arr = [int(x) for x in input().strip().split()]
	total = 0
	blah = []
	for a in arr:
		k = sum([a <= x for x in arr])
		blah.append((n + 1) / (k + 1))
	print('%2.2f' % sum(blah))


def run_test_case():
	count = int(input().strip())
	values = [int(val) for val in input().strip().split(' ')]
	count_gte = {x: sum([y >= x for y in values]) for x in values}
	ev = sum([(len(values) + 1) / (count_gte[x] + 1) for x in values])
	print('{:0.2f}'.format(ev))
test_cases = int(input().strip())
[run_test_case() for x in range(test_cases)]


import math

def calc_distances(a):
	distance = 0.0
	for ele in a:
		distance += float(len(a) + 1) / (sticks_ge(a, ele) + 1)
	return distance

def sticks_ge(a, val):
	count = 0
	for ele in a:
		if ele >= val:
			count += 1
	return count
t = int(input())
for _ in range(t):
	l = int(input())
	a = [int(n) for n in input().split(' ')]
	print('%0.2f' % float(calc_distances(a)))


def ex(y, n):
	grtr = [0 for i in range(n)]
	for i in range(n):
		for j in range(n):
			if y[i] <= y[j]:
				grtr[i] += 1
	sum = 0
	for i in range(n):
		sum += 1 / (grtr[i] + 1)
	return sum * (n + 1)
t = int(input())
for _ in range(t):
	n = int(input())
	y = list(map(int, input().split()))
	print('{:.2f}'.format(ex(y, n)))


for _ in range(int(input())):
	n = int(input())
	Y = list(map(int, input().split()))
	tot = 0.0
	for y in Y:
		k = sum((Y[i] >= y for i in range(n)))
		tot += (n + 1) / (k + 1)
	print('{:.2f}'.format(tot))


t = int(input())
for _ in range(t):
	n = int(input())
	arr = sorted(list(map(int, input().split())))
	sum = 0
	lastval = 0
	for i in range(len(arr)):
		if i > 0 and arr[i] == arr[i - 1]:
			sum += (n + 1) / (lastval + 1)
		else:
			lastval = n - i
			sum += (n + 1) / (lastval + 1)
	print('%.2f' % sum)


def facto(n):
	if n == 1 or n == 0:
		return 1
	indx = 1
	result = 1
	for i in range(1, n + 1):
		result *= i
	return result

def permut(n, m):
	d = facto(n - m)
	ans = facto(n) / d
	return ans

def dist(arr, ln):
	sm = 0
	for i in range(ln):
		if i != 0:
			(arr[0], arr[i]) = (arr[i], arr[0])
		count = 0
		for j in range(1, ln):
			if arr[0] - arr[j] < 1:
				count += 1
		x = ln - 1 - count
		y = ln - count
		for j in range(y):
			sm += (j + 1) * permut(ln - j - 2, count - 1) * facto(ln - 1 - count) * count * (ln - 1 - j) + (j + 1) * permut(ln - j - 1, count) * facto(ln - 1 - count)
		if i != 0:
			(arr[0], arr[i]) = (arr[i], arr[0])
	return sm
arr = []
ans = []
inp = input()
cases = int(inp)
for i in range(cases):
	inp = input()
	ln = int(inp)
	sm = 0
	inp = input()
	inp = inp.split(' ')
	for j in range(ln):
		arr.append(int(inp[j]))
	sm = dist(arr, ln)
	tot = facto(ln)
	ans.append(sm / tot)
	arr[:] = []
for i in range(cases):
	print('%.2f' % ans[i])


t = int(input())
for _ in range(t):
	n = int(input())
	arr = list(map(int, input().strip().split()))
	arr.sort()
	factor = n
	res = 1 / (factor + 1)
	for i in range(1, n):
		if arr[i] == arr[i - 1]:
			res += 1 / (factor + 1)
		else:
			factor = n - i
			res += 1 / (factor + 1)
	res *= n + 1
	print('%.2f' % res)


def getRankArr(arr):
	arr = sorted(arr)
	rank = [0] * N
	j = 0
	while j < N:
		if j == N - 1:
			rank[j] = 0
			break
		current_rank = N - j - 1
		rank[j] = current_rank
		while arr[j] == arr[j + 1]:
			j = j + 1
			rank[j] = current_rank
			if j == N - 1:
				break
		j = j + 1
	return rank

def getExpectation(element_rank, N, j):
	if element_rank == 0:
		return j
	if element_rank == N - 1:
		return 1
	if j == 1:
		return 1
	num_below = N - element_rank - 1
	N = N - 1
	s = 1
	p = 1
	j = j - 1
	while num_below > 0 and j > 0:
		p = p * (num_below / N)
		s = s + p
		num_below = num_below - 1
		N = N - 1
		j = j - 1
	return s
T = int(input())
for i in range(T):
	N = int(input())
	arr = [int(item) for item in input().split()]
	arr = sorted(arr)
	rank = getRankArr(arr)
	print('%.2f' % sum([sum([getExpectation(r, N, j) for j in range(1, N + 1)]) / N for r in rank]))


def getNumOccurencesEqualToOrHigher(m, A):
	count = 0
	for (i, v) in enumerate(A):
		if v >= m:
			count += 1
	return count

def main():
	times = int(input())
	for _ in range(times):
		size = int(input())
		data = list(map(int, input().split(' ')))
		expectedValue = 0.0
		for (i, m) in enumerate(data):
			expectedValue += (size + 1) / (getNumOccurencesEqualToOrHigher(m, data) + 1)
		print('%.2f' % expectedValue)
main()


T = int(input())
for _ in range(T):
	N = int(input())
	y = [int(x) for x in input().strip().split()]
	n = len(y)
	res = 0
	for yi in y:
		res += (n + 1) / (len([x for x in y if x >= yi]) + 1)
	print(format(res, '.2f'))


tests = int(input())
for test in range(tests):
	n = int(input())
	y = [int(x) for x in input().split()]
	s = y
	s.sort()
	h = [len(s) - s.index(x) for x in y]
	ans = sum([(n + 1) / (k + 1) for k in h])
	print('%.2f' % ans)


def factorial(n):
	result = 1
	for f in range(2, n + 1):
		result *= f
	return result

def permutations(a):
	if len(a) < 2:
		yield a
	else:
		for i in range(len(a)):
			for perm in permutations(a[0:i] + a[i + 1:]):
				yield ([a[i]] + perm)

def V(y):
	result = 0
	for i in range(len(y)):
		j = i - 1
		while j > -1 and y[j] < y[i]:
			j -= 1
		result += i - j
	return result
from functools import reduce
import operator

def prod(a):
	return reduce(operator.mul, a, 1)

def vsum(y):
	result = 0
	n = len(y)
	for i in range(n):
		num_lt = sum((y[j] < y[i] for j in range(n)))
		num_gte = n - num_lt - 1
		for pos in range(n):
			for points in range(min(pos, num_lt) + 1, 0, -1):
				result += points * prod((num_lt - k for k in range(0, points - 1))) * (factorial(n - points) if pos == points - 1 else num_gte * factorial(n - points - 1))
	return result
t = int(input().strip())
for i in range(t):
	n = int(input().strip())
	a = [int(j) for j in input().strip().split()]
	print('%0.2f' % (vsum(a) / factorial(n)))


i = int(input())
for j in range(i):
	m = int(input()) + 1
	q = list(map(int, input().split()))
	total = 0
	for qq in q:
		total += m / (sum((l >= qq for l in q)) + 1)
	print('%.2f' % total)


def get_avg(ys):
	avg = 0.0
	for y in ys:
		k = sum((1 for (i, _) in enumerate(ys) if ys[i] >= y))
		avg += (len(ys) + 1) / (k + 1)
	return avg
t = int(input())
for _ in range(t):
	n = int(input())
	y = [int(token) for token in input().split()]
	print('%0.2f' % get_avg(y))


import numbers

class Fraction(object):

	def __init__(self, num, den):
		if den == 0:
			raise ValueError('denominator must be non-zero')
		self.num = num
		self.den = den

	def __add__(self, other):
		if not isinstance(other, Fraction):
			raise ValueError('argument must be a Fraction')
		ans_num = self.num * other.den + self.den * other.num
		ans_den = self.den * other.den
		return Fraction(ans_num, ans_den)

	def __mul__(self, other):
		if not isinstance(other, Fraction):
			raise ValueError('argument must be a Fraction')
		ans_num = self.num * other.num
		ans_den = self.den * other.den
		return Fraction(ans_num, ans_den)

	def __str__(self):
		return '%.2f' % round(self.num / self.den, 2)
	__repr__ = __str__
P = [[[None for n in range(51)] for x in range(51)] for k in range(51)]
for k in range(51):
	for x in range(51):
		for n in range(51):
			if x < k or n <= k:
				rtn_value = Fraction(0, 1)
			elif k == 0:
				rtn_value = Fraction(n - x, n - k)
			else:
				rtn_value = P[k - 1][x][n] * Fraction(x - k + 1, n - k)
			P[k][x][n] = rtn_value

def e(x, n):
	ans = Fraction(1, 1)
	for k in range(1, x + 1):
		ans += Fraction(k, 1) * P[k][x][n]
	return ans
T = int(input())
for each in range(T):
	N = int(input())
	inp = input().split()
	bars = [int(num) for num in inp]
	bars.sort()
	ans = Fraction(0, 1)
	prev_pointer = 0
	for pointer in range(N):
		if pointer == 0:
			x = 0
		elif bars[pointer] == bars[prev_pointer]:
			x = prev_pointer
		else:
			x = pointer
			prev_pointer = pointer
		ans += e(x, N)
	print(ans)


def sub_p(y, n):
	y.sort()
	sted = y[::-1]
	not_lower_count = {sted[i]: i + 1 for i in range(len(sted))}
	return sum([(n + 1) / (not_lower_count[yi] + 1) for yi in y])
t = int(input())
for i in range(t):
	n = int(input())
	y = list(map(int, input().strip().split()))
	print('%.2f' % sub_p(y, n))


T = int(input())
for x in range(T):
	N = int(input())
	heights = [int(x) for x in input().split()]
	heights.sort(reverse=True)
	V = [0 for i in range(N)]
	for i in range(N):
		duplicates = 0
		for j in range(i + 1, N):
			if j >= N or heights[j] < heights[i]:
				break
			if heights[j] == heights[i]:
				duplicates += 1
		V[i] = (N + 1) / (i + duplicates + 2)
	print('%.2f' % sum(V))


for _ in range(int(input())):
	n = int(input())
	c = list(map(int, input().split()))
	greater = {x: i + 1 for (i, x) in enumerate(reversed(sorted(c)))}
	result = 0
	for x in c:
		result += (n + 1) / (greater[x] + 1)
	print('%.2f' % result)


t = int(input().strip())
while t > 0:
	ev = 0.0
	n = int(input().strip())
	sticks = [int(i) for i in input().split(' ')]
	hist = [0] * n
	for i in range(n):
		this_stick = sticks[i]
		for item in sticks:
			if item >= this_stick:
				hist[i] += 1
	for item in hist:
		ev += (n + 1) / (item + 1)
	print('{0:.2f}'.format(ev))
	t -= 1


import sys
data = sys.stdin.read()
data = data.splitlines()
n = int(data[0].strip())
for i in range(1, n + 1, 1):
	l = [int(x) for x in data[2 * i].strip().split(' ')]
	m = len(l)
	ans = 0
	for i in range(m):
		eq = 0
		for j in range(m):
			if l[j] >= l[i]:
				eq += 1
		ans += (m + 1) / (eq + 1)
	print(format(ans, '.2f'))


import sys
import itertools

def get_sum(arr):
	vs = [sum([i <= j for j in arr]) for i in arr]
	r = sum([(len(arr) + 1) / (v + 1) for v in vs])
	return r
test_count = int(input().strip())
for t in range(test_count):
	n = int(input().strip())
	ys = [int(a_temp) for a_temp in input().strip().split(' ')]
	print('{:.2f}'.format(get_sum(ys)))


for _ in range(int(input())):
	n = int(input().strip())
	a = list(map(int, input().strip().split()))
	b = [0 for _ in range(n)]
	for i in range(n):
		b[i] = sum((j >= a[i] for j in a))
	avg = 0
	for i in b:
		avg += (n + 1) / (i + 1)
	print('%.2f' % avg)


def calculate_ray_shot_value():
	_ = input()
	numbers = [int(num) for num in input().split()]
	gt_number_occurrence = {}
	greater_numbers_count = []
	for num in numbers:
		if num not in gt_number_occurrence:
			occurrence = len([_num for _num in numbers if _num >= num])
			gt_number_occurrence[num] = occurrence
		greater_numbers_count.append(gt_number_occurrence[num])
	modified_length = len(greater_numbers_count) + 1
	result = sum((modified_length / (gt_num_count + 1) for gt_num_count in greater_numbers_count))
	return result

def main():
	test_case_count = int(input())
	for _ in range(test_case_count):
		result = calculate_ray_shot_value()
		print('{:.2f}'.format(result))
main()


t = int(input())
for x in range(t):
	n = int(input())
	arr = [int(z) for z in input().split()]
	arr.sort()
	tray = []
	sum_ = 0
	for p in arr:
		count = 0
		for q in arr:
			if q >= p:
				count += 1
		tray.append(count)
	for k in tray:
		sum_ = sum_ + (n + 1) / (k + 1)
	print('%.2f' % sum_)


num_cases = int(input())
for i in range(num_cases):
	num_count = int(input())
	numbers = list(map(int, input().split(' ')))
	numbers.sort()
	counts = {}
	for n in numbers:
		if n in counts:
			counts[n] += 1
		else:
			counts[n] = 1
	running_greater_than = num_count
	ev_count = 0.0
	total_length = num_count + 1
	for (index, num) in enumerate(numbers):
		if index != 0 and num != numbers[index - 1]:
			running_greater_than -= counts[numbers[index - 1]]
		ev_count += total_length / (running_greater_than + 1)
	print(format(ev_count, '.2f'))


from math import factorial
T = int(input())

def left(i):
	return 0.5 + abs(1.5 - i)
for _ in range(T):
	N = int(input())
	Y = sorted([int(d) for d in input().split()])
	vSum = 0
	if N == 1:
		print('1.00')
		continue
	for d in Y:
		rank = Y.index(d) + 1
		for i in range(1, rank + 1):
			if i == 1:
				n1 = factorial(N - 1)
				n2 = (N - rank) * factorial(N - 2) * (N - 1)
			elif i == rank == N:
				n1 = factorial(rank - 1) / factorial(rank - i) * factorial(N - i) * (N - i + 1)
				n2 = 0
			elif i == rank:
				n1 = factorial(rank - 1) * factorial(N - i)
				n2 = factorial(rank - 1) * factorial(N - i) * (N - i)
			else:
				n1 = factorial(rank - 1) / factorial(rank - i) * factorial(N - i)
				n2 = factorial(rank - 1) / factorial(rank - i) * (N - rank) * factorial(N - i - 1) * (N - i)
			(n1, n2) = [int(j) * i for j in (n1, n2)]
			vSum += n1 + n2
	result = vSum / factorial(N)
	print('{:.2f}'.format(result))


t = int(input())
for t0 in range(t):
	n = int(input())
	y = [int(x) for x in input().split()]
	result = 0
	for i in y:
		k = 0
		for j in y:
			if j >= i:
				k += 1
		result += (n + 1) / (k + 1)
	print('{:.2f}'.format(result))


def expected_length(n, y):
	y.sort()
	block = 1
	i = 1
	k = n
	m = 0
	while i <= n:
		if i == n or y[i] > y[i - 1]:
			m += block * (n + 1) / (k + 1)
			k = n - i
			block = 1
		else:
			block += 1
		i += 1
	print('{:.2f}'.format(m))
t = int(input().strip())
for i in range(t):
	n = int(input().strip())
	y = [int(s) for s in input().strip().split()]
	expected_length(n, y)


def main():
	T = int(input())
	for i in range(T):
		m = int(input())
		Y = list(map(int, input().strip().split()))
		solve(m, Y)

def solve(m, Y):
	Y.sort()
	p = 1
	prev = Y[0]
	prevInd = 0
	for i in range(1, len(Y)):
		if prev == Y[i]:
			p += (m + 1) / (m - prevInd + 1)
		else:
			p += (m + 1) / (m - i + 1)
			prev = Y[i]
			prevInd = i
	print('%.2f' % p)
main()


import sys
test = int(input())
for nousar in range(0, test):
	n = int(input())
	vec = [int(ele) for ele in input().split(' ')]
	vec.sort(reverse=True)
	dic = {}
	for num in vec:
		dic[num] = 0
	for num in vec:
		dic[num] = dic[num] + 1
	media = 0
	k = 0
	for key in vec:
		k = k + dic[key]
		media = media + dic[key] * (n + 1) / (k + 1)
		dic[key] = 0
	print('{0:.2f}'.format(media))


t = int(input().strip())
for _ in range(t):
	n = int(input().strip())
	l = list(map(int, input().strip().split(' ')))
	v = 0
	for x in l:
		s = 0
		for y in l:
			if y >= x:
				s += 1
		v += 1 / (s + 1)
	print('%.2f' % (v * (n + 1)))


T = int(input())
for t in range(T):
	N = int(input())
	V = [int(v) for v in input().split()]
	_V = [len([1 for i in V if i >= v]) for v in V]
	E = 0
	for n in range(N):
		E += (N + 1) / (_V[n] + 1)
	print('{0:.2f}'.format(E))


T = int(input())
for t in range(T):
	N = int(input())
	V = [int(v) for v in input().split()]
	_V = [len([1 for i in V if i >= v]) for v in V]
	E = 0
	for n in range(N):
		E += (N + 1) / (_V[n] + 1)
	print('{0:.2f}'.format(E))


T = int(input())
cases = []
for t in range(T):
	size = int(input())
	array = [int(i) for i in input().split()]
	cases.append([size, array])
for case in cases:
	size = case[0]
	array = case[1]
	higher_array = [sum([i >= array[j] for i in array]) for j in range(size)]
	expectation = 0
	for elem in higher_array:
		expectation += (size + 1) / (elem + 1)
	print('{0:.2f}'.format(expectation))


T = int(input())
for _ in range(T):
	N = int(input())
	Y = [int(x) for x in input().split()]
	Y.sort()
	greater_equal = [N]
	sample_idx = 1
	i = 1
	while i < N:
		if Y[i] == Y[i - 1]:
			greater_equal.append(greater_equal[-1])
		else:
			greater_equal.append(N - i)
		i += 1
	result = 0
	for prob in greater_equal:
		result += (N + 1) / (prob + 1)
	print('%.2f' % result)


t = int(input().strip())
for tcase in range(t):
	n = int(input().strip())
	if n == 1:
		input()
		ans = 1.0
	else:
		a = [int(i) for i in input().strip().split()]
		a.sort()
		b = [0 for i in range(n)]
		b[0] = n + 1
		for i in range(1, n):
			b[i] = b[i - 1] if a[i] == a[i - 1] else n + 1 - i
		ans = 0.0
		for i in b:
			ans += (n + 1) / i
	print('%.2f' % round(ans, 2))


for _ in range(int(input())):
	n = int(input())
	ns = list(map(int, input().split()))
	acc = 0
	for i in ns:
		x = 1
		for j in ns:
			if j >= i:
				x += 1
		acc += (n + 1) / x
	print('{:0.2f}'.format(acc))


for i in range(int(input())):
	num_integers = int(input())
	integers = [int(j) for j in input().split(' ')]
	counts = {}
	for j in integers:
		counts[j] = counts.get(j, 0) + 1
	sort = sorted(counts, reverse=True)
	solution = 0
	num_line_matters = 0
	num_integers_one = num_integers + 1
	for j in sort:
		num_line_matters += counts[j]
		solution += num_integers_one / (num_line_matters + 1) * counts[j]
	print('{:.2f}'.format(solution))


q = int(input())
for foo in range(q):
	zed = int(input())
	arr = [int(x) for x in input().strip().split()]
	tosum = []
	for x in arr:
		avg = sum((i >= x for i in arr))
		tosum.append((zed + 1) / (1 + avg))
	print('{:.2f}'.format(sum(tosum)))


t = int(input())
for _ in range(t):
	n = int(input())
	l = sorted([int(i) for i in input().split()])
	ev = 0
	ind = 0
	ev += (n + 1) / (n - ind + 1)
	for i in range(1, n):
		if l[i] > l[i - 1]:
			ind = i
		ev += (n + 1) / (n - ind + 1)
	print('{:.2f}'.format(ev))


t = input().strip()
t = int(t)
for i in range(t):
	n = input().strip()
	n = int(n)
	v = [int(k) for k in input().strip().split()]
	count = 0
	for e in v:
		count += (n + 1) / (sum((i >= e for i in v)) + 1)
	print('%.2f' % count)


def v(n, y):
	h = [2] * n
	for i in range(n):
		for j in range(n):
			if i == j:
				continue
			if y[i] <= y[j]:
				h[i] += 1
	return (n + 1) * sum((1 / el for el in h))
t = int(input())
for _ in range(t):
	n = int(input())
	y = [int(el) for el in input().split()]
	print('{:.2f}'.format(v(n, y)))


import sys
T = int(input().strip())
for t in range(T):
	I = int(input().strip())
	y = [int(a_temp) for a_temp in input().strip().split(' ')]
	y.sort()
	n = [len(y)]
	for ind in range(len(y)):
		if ind > 0:
			if y[ind - 1] == y[ind]:
				n.append(n[ind - 1])
			else:
				n.append(len(y) - ind)
	exp = 0.0
	for num in n:
		exp += (len(y) + 1.0) / (num + 1.0)
	print('%.2f' % exp)


anzTestfaelle = int(input())
for i in range(int(anzTestfaelle)):
	anzListenelemente = int(input())
	inputListe = input().split()
	inputListe = [int(i) for i in inputListe]
	laenge = len(inputListe) + 1
	erwartung = 0.0
	for n in range(len(inputListe)):
		current = inputListe[n]
		ergebnis = sum([1 for i in range(len(inputListe)) if current <= inputListe[i]]) + 1
		erwartung = erwartung + laenge / float(ergebnis)
	print('%.2f' % erwartung)


import random
random.seed(15645)

def GetV(Y):
	n = len(Y)
	LesserList = []
	for i1 in Y:
		Count = 0
		for i2 in Y:
			if i2 >= i1:
				Count += 1
		LesserList.append(Count)
	print('{0:.2f}'.format(sum([(n + 1) / (m + 1) for m in LesserList])))
T = int(input().strip())
for i1 in range(T):
	input()
	Y = [int(m) for m in input().strip().split()]
	GetV(Y)


t = int(input())
for tt in range(0, t):
	n = int(input())
	x = []
	y = [int(i) for i in input().split(' ')]
	for j in range(0, n):
		c = 1
		for i in range(0, n):
			if y[i] >= y[j]:
				c = c + 1
		x.append(c)
	a = round(float(sum([(n + 1) / x[i] for i in range(0, n)])), 2)
	print('%.2f' % a)


def get_average(nums):
	counts = {}
	for num in nums:
		if num in counts:
			continue
		result = 0
		for other_num in nums:
			if other_num >= num:
				result += 1
		counts[num] = result
	compared = [counts[num] for num in nums]
	average = 0
	for num in compared:
		average += float(len(compared) + 1) / (num + 1)
	return average
num_tests = int(input())
for x in range(int(num_tests)):
	length = input()
	nums = [int(x) for x in input().split()]
	print('%.2f' % get_average(nums))


t = int(input())
for _ in range(t):
	n = int(input())
	a = [int(i) for i in input().split(' ')]
	exp = 0
	for i in range(len(a)):
		count = 0
		for j in range(len(a)):
			if a[j] >= a[i]:
				count += 1
		exp += (n + 1) / (count + 1)
	print('%.2f' % round(exp, 2))


t = int(input())
for _ in range(t):
	n = int(input())
	arr = [int(x) for x in input().split()]
	expected = [0] * n
	for i in range(n):
		for j in range(n):
			if arr[j] >= arr[i]:
				expected[i] += 1
	ans = 0
	for x in expected:
		ans += 1 / (x + 1)
	print('%.2f' % ((n + 1) * ans))


utsikt = {}

def E(m, k, n):
	if k == 0:
		return 1
	if m == 1:
		return 1
	if (m, k, n) not in utsikt:
		utsikt[m, n, k] = 1 + k / (n - 1) * E(m - 1, k - 1, n - 1)
	return utsikt[m, n, k]
q = int(input())
for _ in range(q):
	n = int(input())
	data = sorted([int(x) for x in input().split()])
	data.append(10000)
	expected = 0
	i = 0
	while i < n:
		counter = 1
		while i < n and data[i] == data[i + 1]:
			i += 1
			counter += 1
		k = i + 1 - counter
		expected += counter * sum([E(m, k, n) / n for m in range(1, n + 1)])
		i += 1
	print('%.2f' % expected)


for _ in range(int(input())):
	(n, arr) = (int(input()), [int(x) for x in input().split()])
	arr.sort(reverse=True)
	(ans, j) = (0, 1)
	arr.append(-1)
	for i in range(n):
		if arr[i] != arr[i + 1]:
			ans += j * (n + 1) / (i + 2)
			j = 1
		else:
			j += 1
	print('%.2f' % ans)


def stick_permutations(st, n):
	total_sum = 0.0
	for outer in st:
		sub_sum = 0
		for inner in st:
			if inner >= outer:
				sub_sum += 1
		total_sum += (n + 1) / (sub_sum + 1)
	return total_sum

def main():
	test_cases = int(input().strip())
	for _ in range(test_cases):
		n = int(input().strip())
		arr = list(map(int, input().strip().split()))
		stick_avg = stick_permutations(arr, n)
		print('{:.2f}'.format(stick_avg))
main()


t = int(input())
for i in range(t):
	v = 0
	n = int(input())
	nums = list(map(int, input().strip().split(' ')))
	nums.sort()
	for j in nums:
		v = v + (1 + n) / (1 + n - nums.index(j))
	v = float(v)
	print('%0.2f' % v)


from itertools import permutations
from decimal import Decimal
T = int(input())

def get_expectation(sticks):
	k = []
	for stick in sticks:
		k.append(sum([1 for _ in sticks if _ >= stick]))
	return k
for _ in range(T):
	N = int(input())
	Y = [int(i) for i in input().strip().split()]
	K = get_expectation(Y)
	print(round(Decimal(sum([(N + 1) / (k + 1) for k in K])), 2))


import sys
import array

def eval_V(y):
	l = len(y)
	V = []
	for i in y:
		v = 0
		for j in y:
			if i <= j:
				v += 1
		V.append(v)
	VV = [(l + 1) / (V_temp + 1) for V_temp in V]
	return sum(VV)
n = int(input())
for i in range(n):
	k = int(input())
	y = [int(y_temp) for y_temp in input().strip().split(' ')]
	print('%.2f' % eval_V(y))


for _ in range(int(input())):
	n = int(input())
	a = sorted(map(int, input().split()))
	assert len(a) == n
	(s, e) = (0, n)
	for i in range(1, n):
		if a[i] > a[i - 1]:
			s = i
		e += s / (n + 1 - s)
	print('%.2f' % e)


import itertools

def calc_list(sublist):
	total = 1
	for i in range(1, len(sublist)):
		tmp_index = i
		cur = sublist[i]
		while tmp_index > 0 and cur > sublist[tmp_index - 1]:
			tmp_index -= 1
		total += i - tmp_index + 1
	return total

def calc_prob(elm, my_list):
	tot = 0
	for l in my_list:
		if l >= elm:
			tot += 1
	return tot
tests = int(input())
for _ in range(tests):
	lookup = {}
	n = int(input())
	total = 0.0
	my_list = list(map(int, input().split()))
	for sublist in my_list:
		if str(sublist) in lookup:
			total += (n + 1) / (lookup[str(sublist)] + 1)
		else:
			lookup[str(sublist)] = calc_prob(sublist, my_list)
			total += (n + 1) / (lookup[str(sublist)] + 1)
	print('%0.2f' % total)


from collections import defaultdict

def solve(a):
	a.sort()
	d = defaultdict(int)
	N = len(a)
	dist = [0] * N
	for i in range(N):
		if d[a[i]] == 0:
			dist[i] = N - i
			d[a[i]] = dist[i]
		else:
			dist[i] = d[a[i]]
	res = 0
	for i in range(N):
		res += (N + 1) / (dist[i] + 1)
	return '%.2f' % res
for _ in range(int(input())):
	n = int(input())
	a = list(map(int, input().split()))
	print(solve(a))


def get_avg(arr0):
	sum = 0
	arr1 = []
	n = len(arr0)
	arr0.sort()
	arr1.append(n)
	for i in range(1, n):
		if arr0[i] == arr0[i - 1]:
			arr1.append(arr1[i - 1])
		else:
			arr1.append(n - i)
	for i1 in range(0, n):
		sum += (n + 1) / (arr1[i1] + 1)
	return sum
n = int(input())
for i in range(n):
	m = int(input())
	arr = [int(arr1) for arr1 in input().split()]
	average_v = get_avg(arr)
	print('%.2f' % average_v)


T = int(input().strip())
for t in range(T):
	n = int(input().strip())
	xs = list(map(int, input().split()))
	xs = sorted([-x for x in xs])
	xs = [-x for x in xs]
	j = 0
	s = 0
	for i in range(n):
		while j < n - 1 and xs[j + 1] >= xs[i]:
			j += 1
		s += (n + 1) / (j + 2)
	print('%.2f' % s)


import sys

def parse_input():
	infile = sys.stdin.readlines()
	return [list(map(int, line.split())) for line in infile[2::2]]

def ev_rays(v):
	gte_plus1 = []
	for i in range(len(v)):
		num_gte = 0
		for j in range(len(v)):
			if v[j] >= v[i]:
				num_gte += 1
		gte_plus1.append(num_gte)
	return sum(map(lambda x: (len(v) + 1) / (x + 1), gte_plus1))
vectors = parse_input()
for v in vectors:
	print('{0:.2f}'.format(ev_rays(v)))


T = int(input().strip())
for i in range(T):
	n = int(input().strip())
	Y = list(map(lambda x: int(x), input().strip().split()))
	v = list(map(lambda x: (n + 1) / (len(list(filter(lambda y: y >= x, Y))) + 1), Y))
	print('{0:.2f}'.format(sum(v)))


from math import factorial

def solve(arr):
	arr = sorted(arr, reverse=True)
	sum_ = 0
	same = 1
	for i in range(1, len(arr)):
		if arr[i] != arr[i - 1]:
			sum_ += (len(arr) + 1) / (i + 1) * same
			same = 0
		same += 1
	sum_ += (len(arr) + 1) / (len(arr) + 1) * same
	return sum_
t = int(input())
for _ in range(t):
	input()
	arr = [int(el) for el in input().split(' ')]
	print('{:.2f}'.format(solve(arr)))


def expect_y(n, m):
	expect = 0
	for k in range(1, n - m + 1):
		numerator = 1
		denominator = 1
		for num in range(1, k):
			numerator *= n - m - num
			denominator *= n - num
		expect += k * (m + 1) * numerator / denominator
	return expect / n

def sticks(n, y):
	y.sort()
	count = []
	current = None
	for ele in y:
		if ele == current:
			count[-1] += 1
		else:
			current = ele
			count.append(1)
	m = -1
	V = 0
	while count:
		mult = count.pop()
		m += mult
		V += mult * expect_y(n, m)
	return V
q = int(input())
for query in range(q):
	n = int(input())
	y = [int(temp) for temp in input().strip().split()]
	print('%.2f' % round(sticks(n, y), 2))


from itertools import permutations

def compute_score(array):
	score = len(array)
	for idx in range(1, len(array)):
		pos = idx
		while array[idx] > array[pos - 1] and pos >= 1:
			score += 1
			pos -= 1
	return score

def solve2(array):
	size = 0
	score = 0
	for permutation in permutations(array):
		size += 1
		score += compute_score(permutation)
	return score / size

def solve(array):
	bigger = []
	length = len(array)
	for idx in range(length):
		bigger_than_current_index = 0
		for idx2 in range(length):
			if array[idx2] >= array[idx]:
				bigger_than_current_index += 1
		bigger.append(bigger_than_current_index)
	return sum([(length + 1) / (value + 1) for value in bigger])
T = int(input())
for _ in range(T):
	input()
	array = [int(n) for n in input().split(' ')]
	print('%.2f' % solve(array))


import sys
import array

def getExpected(Y):
	Y_sort = sorted(Y)
	b = []
	n = len(Y_sort)
	for i in range(n):
		if i != 0 and Y_sort[i] == Y_sort[i - 1]:
			b.append(b[i - 1])
		else:
			b.append(n - i)
	sum = 0.0
	for i in range(n):
		sum += float(n + 1) / (b[i] + 1)
	return sum
t = int(sys.stdin.readline())
for i in range(t):
	N = int(sys.stdin.readline())
	Y = [int(j) for j in sys.stdin.readline().split(' ')]
	print('%.2f' % getExpected(Y))


def calc(y):
	t = []
	for i in range(n):
		ans = len(y) + 1
		for j in range(n):
			if y[i] > y[j]:
				ans -= 1
		t.append((len(y) + 1) / ans)
	return t
for _ in range(int(input())):
	n = int(input())
	y = list(map(int, input().split()))
	print('%.2f' % sum(calc(y)))


def expected_len(less, greater):
	total = 1
	for i in range(1, less + 1):
		total = 1 + total * i / (i + greater + 1)
	return total
num_tests = int(input())
for _ in range(num_tests):
	num_sticks = int(input())
	lengths = list(map(int, input().strip().split()))
	lengths.sort()
	num_less = 0
	prev_length = None
	total = 0
	for (idx, length) in enumerate(lengths):
		if length != prev_length:
			prev_length = length
			num_less = idx
		total += expected_len(num_less, num_sticks - num_less - 1)
	print('{:.2f}'.format(total))


import sys

def avgStickDistance(stickList):
	N = len(stickList) + 1
	newList = []
	for i in range(len(stickList)):
		newList.append(sum([1 for j in stickList if stickList[i] <= j]))
	newList = [N / (i + 1) for i in newList]
	return format(sum(newList), '.2f')
T = int(input().strip())
for t in range(T):
	Y = int(input().strip())
	y = [int(i) for i in input().split()]
	print(avgStickDistance(y))


T = int(input())
F = [1 for i in range(51)]
for i in range(2, 51):
	F[i] = i * F[i - 1]
for t in range(T):
	N = int(input())
	V = list(map(int, input().split()))
	V.sort()
	d = {}
	exp = 1
	for i in range(1, N):
		exp += 1.0 / N
		j = i + 1
		while j < N and V[i] == V[j]:
			j += 1
		k = i - 1
		while k >= 0 and V[k] == V[i]:
			k -= 1
		idem = j - k - 2
		nr_bigger = N - j + idem
		nr_smaller = k + 1
		for j in range(1, N):
			exp += 1.0 / N
			if nr_smaller >= j:
				k = 0
				exp += (j - k) * F[nr_smaller] / F[nr_smaller - (j - k)] / F[N - 1] * F[N - 1 - (j - k)] / N
			for k in range(1, j):
				if nr_smaller >= j - k and nr_bigger >= 1:
					exp += (j - k) * F[nr_smaller] / F[nr_smaller - (j - k)] / F[N - 1] * F[N - 1 - (j - k) - 1] * nr_bigger / N
	print('%.2f' % exp)


import sys
q = int(input().strip())
for a0 in range(q):
	n = int(input().strip())
	listS = list(map(int, input().strip().split(' ')))
	listBigSticks = []
	for s in listS:
		runTot = 0
		for p in listS:
			if p >= s:
				runTot += 1
		listBigSticks.append(runTot)
	expectedVal = 0
	for e in listBigSticks:
		expectedVal += (n + 1) / (e + 1)
	print('{0:.2f}'.format(expectedVal))


for _ in range(int(input())):
	N = int(input())
	(K, Y) = ([N + 1], sorted(list(map(int, input().split()))))
	for i in range(N - 1):
		K += [K[-1] if Y[i + 1] == Y[i] else N - i]
	print('%.2f' % sum(((N + 1) / k for k in K)))


tests = int(input())
for _ in range(tests):
	n = int(input())
	V = list(map(int, input().split()))
	V.sort()
	length = len(V)
	(avg, k) = (1, len(V))
	for i in range(1, length):
		if V[i] > V[i - 1]:
			k = len(V) - i
		avg += (length + 1) / (k + 1)
	print('{0:.2f}'.format(avg))


import itertools

def get_expected_value_of_V(y_numbers, N):
	expected_value = 0
	(last_y, y_count) = (-1, 0)
	y_numbers = sorted(y_numbers)
	for i in range(N):
		num = y_numbers[i]
		k = N - i
		if num == last_y:
			k += y_count
			y_count += 1
		else:
			y_count = 1
			last_y = num
		expected_value += (N + 1) / (k + 1)
	return format(expected_value, '.2f')
T = int(input())
for i in range(T):
	N = int(input())
	y_numbers = list(map(int, input().split()))
	print(get_expected_value_of_V(y_numbers, N))