Educational DP Contest - Sushi

There are N dishes, numbered 1, 2, \ldots, N. Initially, for each i (1 \leq i \leq N), Dish i has a_i (1 \leq a_i \leq 3) pieces of sushi on it.

Taro will perform the following operation repeatedly until all the pieces of sushi are eaten:

* Roll a die that shows the numbers 1, 2, \ldots, N with equal probabilities, and let i be the outcome. If there are some pieces of sushi on Dish i, eat one of them; if there is none, do nothing.



Find the expected number of times the operation is performed before all the pieces of sushi are eaten.

Constraints

* All values in input are integers.
* 1 \leq N \leq 300
* 1 \leq a_i \leq 3

Input

Input is given from Standard Input in the following format:


N
a_1 a_2 \ldots a_N


Output

Print the expected number of times the operation is performed before all the pieces of sushi are eaten. The output is considered correct when the relative difference is not greater than 10^{-9}.

Examples

Input

3
1 1 1


Output

5.5


Input

1
3


Output

3


Input

2
1 2


Output

4.5


Input

10
1 3 2 3 3 2 3 2 1 3


Output

54.48064457488221

Difficulty: UNKNOWN_DIFFICULTY

Starter code:

Solutions:
n = int(input())
k = [0, 0, 0]
(a, s, d) = (0, 0, 0)
for i in input().split():
	if i == '1':
		a += 1
	elif i == '2':
		s += 1
	else:
		d += 1
dp = [[[0] * (n + 1) for j in range(n + 1)] for i in range(n + 1)]
for i in range(d + 1):
	for j in range(d + s + 1):
		for k in range(n + 1 - i - j):
			su = i + j + k
			ret = 0
			if su:
				ret += n / su
				if i >= 1:
					ret += dp[i - 1][j + 1][k] * i / su
				if j >= 1:
					ret += dp[i][j - 1][k + 1] * j / su
				if k >= 1:
					ret += dp[i][j][k - 1] * k / su
			dp[i][j][k] = ret
print(dp[d][s][a])


n = int(input())
a = list(map(int, input().split()))
x = [0, 0, 0]
for i in range(n):
	x[a[i] - 1] += 1
dp = [[[0] * (n + 2) for i in range(n + 2)] for j in range(n + 2)]
for k in range(n + 1):
	for i in range(n + 1):
		for j in range(n + 1):
			v = k + i + j
			if 0 < v <= n:
				dp[k][i][j] += dp[k][i][j - 1] * (j / v) + dp[k][i - 1][j + 1] * (i / v) + dp[k - 1][i + 1][j] * (k / v) + n / v
print(dp[x[2]][x[1]][x[0]])


N = int(input())
A = list(map(int, input().split()))
a = A.count(1)
b = A.count(2)
c = A.count(3)
dp = [[[0.0] * (N + 1) for _ in range(N + 1)] for _ in range(N + 1)]
for k in range(c + 1):
	for j in range(b + c + 1 - k):
		for i in range(a + b + c + 1 - k - j):
			if i == 0 and j == 0 and (k == 0):
				continue
			tmp = N * 1.0
			if i > 0:
				tmp += i * dp[i - 1][j][k]
			if j > 0:
				tmp += j * dp[i + 1][j - 1][k]
			if k > 0:
				tmp += k * dp[i][j + 1][k - 1]
			dp[i][j][k] = tmp / (i + j + k)
print(dp[i][j][k])


import sys
input = sys.stdin.readline
N = int(input())
lst_a = list(map(float, input().split()))
(one, two, three) = (lst_a.count(1), lst_a.count(2), lst_a.count(3))
dp = [[[0.0 for _ in range(N + 1)] for _ in range(N + 1)] for _ in range(N + 1)]
for k in range(three + 1):
	for j in range(two + three + 1 - k):
		for i in range(one + two + three + 1 - k - j):
			if i == 0 and j == 0 and (k == 0):
				continue
			tmp = 1.0 * N
			if i > 0:
				tmp += dp[i - 1][j][k] * i
			if j > 0:
				tmp += dp[i + 1][j - 1][k] * j
			if k > 0:
				tmp += dp[i][j + 1][k - 1] * k
			dp[i][j][k] = tmp / (i + j + k)
print(dp[one][two][three])


import sys
sys.setrecursionlimit(10 ** 8)

def calc(N, i, j, k):
	if dp[i][j][k] >= 0:
		return dp[i][j][k]
	ans = 1
	if k - 1 >= 0 and j + 1 <= N:
		ans += calc(N, i, j + 1, k - 1) * k / N
	if j - 1 >= 0 and i + 1 <= N:
		ans += calc(N, i + 1, j - 1, k) * j / N
	if i - 1 >= 0:
		ans += calc(N, i - 1, j, k) * i / N
	ans *= N / (i + j + k)
	dp[i][j][k] = ans
	return ans
from collections import Counter
N = int(input())
A = list(map(int, input().split()))
c = Counter(A)
dp = [[[-1] * (N + 1) for _ in range(N + 1)] for _ in range(N + 1)]
dp[0][0][0] = 0
ans = calc(N, c[1], c[2], c[3])
print(ans)


n = int(input())
a = [int(x) for x in input().split()]
I = a.count(3)
J = a.count(2)
K = a.count(1)
dp = [[[0 for _ in range(I + J + K + 1)] for __ in range(I + J + 1)] for ___ in range(I + 1)]
for i in range(I + 1):
	for j in range(I + J + 1 - i):
		for k in range(I + J + K + 1 - i - j):
			if i + j + k == 0:
				continue
			tmp = 0
			if k - 1 > -1:
				tmp += n / (i + j + k) * (k / n) * dp[i][j][k - 1]
			if j - 1 > -1:
				tmp += n / (i + j + k) * (j / n) * dp[i][j - 1][k + 1]
			if i - 1 > -1:
				tmp += n / (i + j + k) * (i / n) * dp[i - 1][j + 1][k]
			dp[i][j][k] += n / (i + j + k) + tmp
print(dp[I][J][K])


from collections import defaultdict
N = int(input())
counts = [0, 0, 0]
for a in map(int, input().split()):
	counts[a - 1] += 1
(A, B, C) = counts
dp = [[[0] * (A + B + C + 1 - k - j) for j in range(B + C + 1 - k)] for k in range(C + 1)]
t1 = None
for k in range(C + 1):
	t0 = dp[k]
	for j in range(B + C + 1 - k):
		for i in range(A + B + C + 1 - k - j):
			try:
				dp[k][j][i] = ((i * t0[j][i - 1] if i else 0) + (j * t0[j - 1][i + 1] if j else 0) + (k * t1[j + 1][i] if k else 0) + N) / (i + j + k)
			except ZeroDivisionError:
				pass
	t1 = t0
print(dp[C][B][A])


from sys import setrecursionlimit
setrecursionlimit(10 ** 8)

def main():
	n = int(input())
	a = list(map(int, input().split()))
	dp = [[[-1] * (n + 1) for _ in range(n + 1)] for _ in range(n + 1)]
	dp[0][0][0] = 0.0

	def search(i, j, k):
		num = n
		if i > 0:
			if dp[i - 1][j][k] == -1:
				num += search(i - 1, j, k) * i
			else:
				num += dp[i - 1][j][k] * i
		if j > 0:
			if dp[i + 1][j - 1][k] == -1:
				num += search(i + 1, j - 1, k) * j
			else:
				num += dp[i + 1][j - 1][k] * j
		if k > 0:
			if dp[i][j + 1][k - 1] == -1:
				num += search(i, j + 1, k - 1) * k
			else:
				num += dp[i][j + 1][k - 1] * k
		num /= i + j + k
		dp[i][j][k] = num
		return num
	print(search(a.count(1), a.count(2), a.count(3)))
main()


import sys
input = lambda : sys.stdin.readline().rstrip()
sys.setrecursionlimit(max(1000, 10 ** 9))
write = lambda x: sys.stdout.write(x + '\n')
n = int(input())
a = list(map(int, input().split()))
from collections import Counter, defaultdict
c = Counter(a)
(n1, n2, n3) = (c[1], c[2], c[3])
n0 = c[0]

def glist(*l, fill=None):
	if len(l) == 1:
		return [fill] * l[0]
	ll = l[1:]
	return [glist(*ll) for _ in range(l[0])]
count = 0
S = sum(a)
sub = glist(n1 + n2 + n3 + 1, n2 + n3 + 1, n3 + 1)
sub[0][0][0] = 0
for i3 in range(n3 + 1):
	for i2 in range(n2 + n3 + 1 - i3):
		for i1 in range(n1 + n2 + n3 - (i2 + i3) + 1):
			if i1 == i2 == i3 == 0 or i1 + i2 + i3 > n:
				continue
			ans = n
			p = 0
			if i1 > 0:
				ans += i1 * sub[i1 - 1][i2][i3]
				p += i1
			if i2 > 0:
				ans += i2 * sub[i1 + 1][i2 - 1][i3]
				p += i2
			if i3 > 0:
				ans += i3 * sub[i1][i2 + 1][i3 - 1]
				p += i3
			ans = ans / p
			sub[i1][i2][i3] = ans
print(sub[n1][n2][n3])


n = int(input())
a = list(map(int, input().split()))
dp = [[[0] * (n + 1) for _ in range(n + 1)] for _ in range(n + 1)]
dp[0][0][0] = 0
cnt1 = a.count(1)
cnt2 = a.count(2)
cnt3 = a.count(3)
for i in range(cnt3 + 1):
	for j in range(cnt3 + cnt2 + 1 - i):
		for k in range(cnt3 + cnt2 + cnt1 + 1 - i - j):
			if i + j + k == 0:
				continue
			res = 1
			if k > 0:
				res += k / n * dp[i][j][k - 1]
			if j > 0:
				res += j / n * dp[i][j - 1][k + 1]
			if i > 0:
				res += i / n * dp[i - 1][j + 1][k]
			dp[i][j][k] = n / (i + k + j) * res
print(dp[cnt3][cnt2][cnt1])


import sys, queue, math, copy, itertools, bisect, collections, heapq
sys.setrecursionlimit(10 ** 7)
INF = 10 ** 18
MOD = 10 ** 9 + 7
LI = lambda : [int(x) for x in sys.stdin.readline().split()]
NI = lambda : int(sys.stdin.readline())
N = NI()
a = [0, 0, 0]
for x in LI():
	a[x - 1] += 1
dp = [[[0.0] * (N + 1) for _ in range(N + 1)] for _ in range(N + 1)]
for k in range(a[2] + 1):
	for j in range(a[1] + a[2] + 1):
		for i in range(N + 1):
			if not 0 < i + j + k <= N:
				continue
			x = 0.0
			if i > 0:
				x += dp[i - 1][j][k] * (i / N)
			if j > 0:
				x += dp[i + 1][j - 1][k] * (j / N)
			if k > 0:
				x += dp[i][j + 1][k - 1] * (k / N)
			x += 1.0
			x *= N / (i + j + k)
			dp[i][j][k] = x
print(dp[a[0]][a[1]][a[2]])


from collections import Counter
n = int(input())
A = [int(i) for i in input().split()]
C = Counter(A)
(a, b, c) = [C[i] for i in range(3, 0, -1)]
DP = [[[0] * (a + b + c - i - j + 1) for j in range(a + b - i + 1)] for i in range(a + 1)]
for i in range(a + 1):
	for j in range(a + b - i + 1):
		for k in range(a + b + c - i - j + 1):
			if i == j == k == 0:
				continue
			DP[i][j][k] = 1
			if i > 0:
				DP[i][j][k] += i / n * DP[i - 1][j + 1][k]
			if j > 0:
				DP[i][j][k] += j / n * DP[i][j - 1][k + 1]
			if k > 0:
				DP[i][j][k] += k / n * DP[i][j][k - 1]
			DP[i][j][k] *= n / (i + j + k)
print(DP[a][b][c])


def main():
	N = int(input())
	A = list(map(int, input().split()))
	a = A.count(1)
	b = A.count(2)
	c = A.count(3)
	floatN = N * 1.0
	dp = [[[0.0] * (N + 1) for i in range(N + 1)] for j in range(N + 1)]
	for k in range(c + 1):
		for j in range(b + c + 1 - k):
			for i in range(N + 1 - k - j):
				if i + j + k == 0:
					continue
				dp[i][j][k] = floatN
				if i > 0:
					dp[i][j][k] += dp[i - 1][j][k] * i
				if j > 0:
					dp[i][j][k] += dp[i + 1][j - 1][k] * j
				if k > 0:
					dp[i][j][k] += dp[i][j + 1][k - 1] * k
				dp[i][j][k] /= i + j + k
	print(dp[a][b][c])
main()


from collections import Counter
n = int(input())
a = list(map(int, input().split()))
c = Counter(a)
dp = [[[0.0 for _ in range(n + 1)] for _ in range(n + 1)] for _ in range(n + 1)]
for z in range(c[3] + 1):
	for y in range(c[2] + 1 + c[3] - z):
		for x in range(n + 1 - z - y):
			if x + y + z == 0:
				continue
			ret = 0.0
			if x > 0:
				ret += dp[x - 1][y][z] * x
			if y > 0:
				ret += dp[x + 1][y - 1][z] * y
			if z > 0:
				ret += dp[x][y + 1][z - 1] * z
			dp[x][y][z] = (ret + n) / (x + y + z)
print(dp[c[1]][c[2]][c[3]])


from collections import deque
from itertools import product
import sys
sys.setrecursionlimit(100000)
input = sys.stdin.readline

def read():
	N = int(input().strip())
	A = map(int, input().strip().split())
	return (N, A)

def dfs(I, J, K, N, dp):
	for k in range(0, K + 1):
		for j in range(0, J + K + 1):
			for i in range(0, N + 1):
				x = 0.0
				if not (i + j + k > N or (i == 0 and j == 0 and (k == 0))):
					x += dp[i - 1][j] * (i / N) if i > 0 else 0.0
					x += dp[i + 1][j - 1] * (j / N) if j > 0 else 0.0
					x += dp[i][j + 1] * (k / N) if k > 0 else 0.0
					x += 1.0
					x *= N / (i + j + k)
				dp[i][j] = x
	return dp[I][J]

def solve(N, A):
	dp = [[0.0 for j in range(N + 2)] for i in range(N + 2)]
	C = [0 for i in range(4)]
	for a in A:
		C[a] += 1
	return dfs(C[1], C[2], C[3], N, dp)
inputs = read()
print('%s' % solve(*inputs))


N = int(input())
A = list(map(int, input().split()))
d = {1: 0, 2: 0, 3: 0}
for a in A:
	d[a] += 1
dp = [[[0] * (N + 1) for j in range(d[2] + d[3] + 1)] for i in range(d[3] + 1)]
for i in range(d[3] + 1):
	for j in range(d[2] + d[3] - i + 1):
		for k in range(N - i - j + 1):
			if i + j + k == 0:
				continue
			dp[i][j][k] = N
			if i > 0:
				dp[i][j][k] += dp[i - 1][j + 1][k] * i
			if j > 0:
				dp[i][j][k] += dp[i][j - 1][k + 1] * j
			if k > 0:
				dp[i][j][k] += dp[i][j][k - 1] * k
			dp[i][j][k] /= i + j + k
print(dp[d[3]][d[2]][d[1]])


import sys
input = sys.stdin.readline

def main():
	n = int(input())
	alst = list(map(float, input().split()))
	dp = [[[0 for _ in range(n + 1)] for _ in range(n + 1)] for _ in range(n + 1)]
	one = alst.count(1)
	two = alst.count(2)
	three = alst.count(3)
	for k in range(three + 1):
		for j in range(two + three + 1):
			if k + j > n:
				continue
			for i in range(n + 1):
				if k + j + i > n:
					continue
				ijk = i + j + k
				if ijk == 0:
					continue
				tmp = n
				if i != 0:
					tmp += dp[i - 1][j][k] * i
				if j != 0 and i != n:
					tmp += dp[i + 1][j - 1][k] * j
				if k != 0 and j != n:
					tmp += dp[i][j + 1][k - 1] * k
				dp[i][j][k] = tmp / ijk
	print(dp[one][two][three])
main()


import sys

def rec(N, dp, i, j, k):
	if dp[i][j][k] >= 0.0:
		return dp[i][j][k]
	if all([i == 0, j == 0, k == 0]):
		return 0.0
	res = 0.0
	if i > 0:
		res += rec(N, dp, i - 1, j, k) * i
	if j > 0:
		res += rec(N, dp, i + 1, j - 1, k) * j
	if k > 0:
		res += rec(N, dp, i, j + 1, k - 1) * k
	res = (res + N) * 1.0 / (i + j + k)
	dp[i][j][k] = res
	return dp[i][j][k]

def main():
	N = int(sys.stdin.readline())
	a = tuple(map(int, sys.stdin.readline().split()))
	(n1, n2, n3) = (a.count(1), a.count(2), a.count(3))
	dp = [[[-1.0 for _ in range(n3 + 1)] for _ in range(n2 + n3 + 1)] for _ in range(n1 + n2 + n3 + 1)]
	print(rec(N, dp, n1, n2, n3))
main()


from collections import Counter
n = int(input())
a = list(map(int, input().split()))
cnt = Counter(a)
(p, q, r) = (cnt[1], cnt[2], cnt[3])
dp = [[[0.0] * (n + 1) for _ in range(n + 1)] for _ in range(n + 1)]
for k in range(r + 1):
	for j in range(r + q + 1):
		for i in range(n + 1):
			if not 0 < i + j + k <= n:
				continue
			if i > 0:
				dp[i][j][k] += dp[i - 1][j][k] * i
			if j > 0:
				dp[i][j][k] += dp[i + 1][j - 1][k] * j
			if k > 0:
				dp[i][j][k] += dp[i][j + 1][k - 1] * k
			dp[i][j][k] += n
			dp[i][j][k] /= i + j + k
print(dp[p][q][r])


N = int(input())
a = list(map(int, input().split()))
dp = [[[float(0)] * (N + 1) for _ in range(N + 1)] for _ in range(N + 2)]
ans = float(0)
count = [0] * 3
for i in a:
	count[i - 1] += 1
for k in range(N + 1):
	for j in range(N + 1):
		for i in range(N + 1):
			if i + j + k <= N:
				if i + j + k != 0:
					dp[i][j][k] = N / (i + j + k)
				if i > 0:
					dp[i][j][k] += dp[i - 1][j][k] * (i / (i + j + k))
				if j > 0:
					dp[i][j][k] += dp[i + 1][j - 1][k] * (j / (i + j + k))
				if k > 0:
					dp[i][j][k] += dp[i][j + 1][k - 1] * (k / (i + j + k))
ans = dp[count[0]][count[1]][count[2]]
print(ans)


N = int(input())
A = list(map(int, input().split()))
cnt = [0, 0, 0, 0]
for a in A:
	cnt[a] += 1
aaa = cnt[1]
bbb = cnt[2]
ccc = cnt[3]
dp = [[[0] * (N + 1) for j in range(bbb + ccc + 1)] for i in range(ccc + 1)]
for k in range(ccc + 1):
	for j in range(bbb + ccc - k + 1):
		for i in range(N - k - j + 1):
			tmp = i + j + k
			if tmp == 0:
				continue
			else:
				dp[k][j][i] = N / tmp
				if i > 0:
					dp[k][j][i] += i * dp[k][j][i - 1] / tmp
				if j > 0:
					dp[k][j][i] += j * dp[k][j - 1][i + 1] / tmp
				if k > 0:
					dp[k][j][i] += k * dp[k - 1][j + 1][i] / tmp
print(dp[ccc][bbb][aaa])


n = int(input())
a = list(map(int, input().split()))
cnt1 = a.count(1)
cnt2 = a.count(2)
cnt3 = a.count(3)
dp = [[[-1] * (cnt1 + cnt2 + cnt3 + 1) for _ in range(cnt2 + cnt3 + 1)] for _ in range(cnt3 + 1)]
dp[0][0][0] = 0
for c3 in range(cnt3 + 1):
	for c2 in range(cnt2 + cnt3 + 1 - c3):
		for c1 in range(cnt1 + cnt2 + cnt3 + 1 - c2 - c3):
			if c1 + c2 + c3 == 0:
				continue
			tmp = 0
			num = c1 + c2 + c3
			if c3 != 0:
				tmp += c3 / n * dp[c3 - 1][c2 + 1][c1]
			if c2 != 0:
				tmp += c2 / n * dp[c3][c2 - 1][c1 + 1]
			if c1 != 0:
				tmp += c1 / n * dp[c3][c2][c1 - 1]
			dp[c3][c2][c1] = n / num * (tmp + 1)
print(dp[cnt3][cnt2][cnt1])


n = int(input())
A = list(map(int, input().split()))
a = 0
b = 0
c = 0
d = sum(A)
for i in range(n):
	if A[i] == 1:
		a = a + 1
	elif A[i] == 2:
		b = b + 1
c = n - a - b
i = 1
dp = [[[0] * (n + 2) for i in range(n + 2)] for j in range(n + 2)]
for k in range(c + 1):
	for j in range(n - k - a + 1):
		for i in range(n - k - j + 1):
			if i == 0 and j == 0 and (k == 0):
				continue
			dp[k][j][i] = (dp[k][j][i - 1] * i + dp[k][j - 1][i + 1] * j + dp[k - 1][j + 1][i] * k + n) / (i + j + k)
print(dp[c][b][a])


def main():
	import sys
	input = sys.stdin.readline
	N = int(input())
	A = list(map(int, input().split()))
	cnt = [0] * 3
	for a in A:
		cnt[a - 1] += 1
	dp = [[[0.0] * (N + 1) for _ in range(N + 1)] for _ in range(N + 1)]
	for k in range(N + 1):
		for j in range(N + 1 - k):
			for i in range(N + 1 - j - k):
				ijk = float(i + j + k)
				if ijk == 0:
					continue
				x = N / ijk
				tmp = 0
				if i > 0:
					tmp += (dp[i - 1][j][k] + x) * (i / ijk)
				if j > 0 and i < N:
					tmp += (dp[i + 1][j - 1][k] + x) * (j / ijk)
				if k > 0 and j < N:
					tmp += (dp[i][j + 1][k - 1] + x) * (k / ijk)
				dp[i][j][k] = tmp
	print(dp[cnt[0]][cnt[1]][cnt[2]])
main()


def main():
	from collections import Counter

	def tami(i, j, k):
		if i is 0 and j is 0 and (k is 0):
			return
		res = fN
		if i is 0:
			pass
		else:
			res += dp[i - 1][j][k] * i
		if j is 0:
			pass
		else:
			res += dp[i + 1][j - 1][k] * j
		if k is 0:
			pass
		else:
			res += dp[i][j + 1][k - 1] * k
		res *= divTable[i + j + k]
		dp[i][j][k] = res
		return
	N = int(input())
	fN = float(N)
	a = list(map(int, input().split()))
	c = Counter(a)
	one = c[1]
	two = c[2]
	three = c[3]
	dp = tuple((tuple(([0.0] * (N + 1) for _ in range(N + 1))) for _ in range(N + 1)))
	divTable = [1]
	for i in range(1, N * 3 + 1):
		divTable.append(1.0 / i)
	for k in range(N + 1):
		for j in range(N - k + 1):
			for i in range(N - k - j + 1):
				tami(i, j, k)
	print(dp[one][two][three])
main()


import sys
input = sys.stdin.readline
N = int(input())
a = list(map(int, input().split()))
IJK = [0, 0, 0]
for i in range(N):
	IJK[a[i] - 1] += 1
dp = [[[float(0)] * (N + 3) for _ in range(N + 3)] for _ in range(N + 3)]
for k in range(N + 1):
	for j in range(N + 1):
		for i in range(N + 1):
			if i + j + k > N:
				continue
			if i + j + k == 0:
				continue
			tmp = 1.0 * N
			if i > 0:
				tmp += i * dp[i - 1][j][k] * 1.0
			if j > 0:
				tmp += j * dp[i + 1][j - 1][k] * 1.0
			if k > 0:
				tmp += k * dp[i][j + 1][k - 1] * 1.0
			dp[i][j][k] = tmp / (i + j + k)
print(dp[IJK[0]][IJK[1]][IJK[2]])


import sys
input = sys.stdin.readline

def main():
	n = int(input())
	al = tuple(map(int, input().split()))
	arr = [0, 0, 0]
	for i in al:
		arr[i - 1] += 1
	dp = [[[0 for k in range(n + 1)] for j in range(n + 1)] for i in range(n + 1)]
	for c in range(n + 1):
		for b in range(n + 1 - c):
			for a in range(n - b - c + 1):
				if a == b == c == 0:
					continue
				if 0 <= c - 1 <= n and 0 <= b + 1 <= n:
					dp[a][b][c] += dp[a][b + 1][c - 1] * c / n
				if 0 <= b - 1 <= n and 0 <= a + 1 <= n:
					dp[a][b][c] += dp[a + 1][b - 1][c] * b / n
				if 0 <= a - 1 <= n:
					dp[a][b][c] += dp[a - 1][b][c] * a / n
				dp[a][b][c] = (dp[a][b][c] + 1) * n / (a + b + c)
	print(dp[arr[0]][arr[1]][arr[2]])
main()


n = int(input())
b = [0, 0, 0]
for i in map(int, input().split()):
	b[i - 1] += 1
(k1, k2, k3) = b
dp = [[[None] * (k3 + 1) for _ in range(k2 + k3 + 1)] for _ in range(k1 + k2 + k3 + 1)]
dp[0][0][0] = 0
for k in range(k3 + 1):
	for j in range(k2 + k3 + 1 - k):
		for i in range(k1 + k2 + k3 + 1 - j - k):
			if not i + j + k:
				continue
			dp[i][j][k] = ((dp[i - 1][j][k] * i if i else 0) + (dp[i + 1][j - 1][k] * j if j else 0) + (dp[i][j + 1][k - 1] * k if k else 0) + n) / (i + j + k)
print(dp[k1][k2][k3])


n = int(input())
l = list(map(int, input().split()))
(ones, twos, threes) = (0, 0, 0)
for i in l:
	if i == 1:
		ones += 1
	elif i == 2:
		twos += 1
	else:
		threes += 1
max_ones = ones + twos + threes
max_twos = twos + threes
max_threes = threes
dp = [[[0.0] * (n + 1) for i in range(n + 1)] for j in range(n + 1)]
for k in range(max_threes + 1):
	for j in range(max_twos + 1 - k):
		for i in range(max_ones + 1 - j - k):
			if i + j + k == 0:
				continue
			else:
				dp[i][j][k] = n / (i + j + k)
				if i > 0:
					dp[i][j][k] += dp[i - 1][j][k] * i / (i + j + k)
				if j > 0:
					dp[i][j][k] += dp[i + 1][j - 1][k] * j / (i + j + k)
				if k > 0:
					dp[i][j][k] += dp[i][j + 1][k - 1] * k / (i + j + k)
print(dp[i][j][k])


N = int(input())
A = list(map(float, input().split()))
(a, b, c) = (0, 0, 0)
for i in range(N):
	if A[i] == 1:
		a += 1
	elif A[i] == 2:
		b += 1
c = N - a - b
i = 1
dp = [[[0] * (N + 2) for i in range(N + 2)] for j in range(N + 2)]
for k in range(c + 1):
	for j in range(N - k - a + 1):
		for i in range(N - k - j + 1):
			if i == 0 and j == 0 and (k == 0):
				continue
			dp[k][j][i] = (dp[k][j][i - 1] * i + dp[k][j - 1][i + 1] * j + dp[k - 1][j + 1][i] * k + N) / (i + j + k)
print(dp[c][b][a])


import sys
from collections import Counter
sys.setrecursionlimit(10 ** 6)
input = sys.stdin.readline
int1 = lambda x: int(x) - 1
p2D = lambda x: print(*x, sep='\n')

def main():
	n = int(input())
	aa = list(map(int, input().split()))
	cnt_aa = Counter(aa)
	nc3 = cnt_aa[3]
	nc2 = cnt_aa[2]
	nc1 = cnt_aa[1]
	dp = [[[0] * (n + 1) for _ in range(nc3 + nc2 + 1)] for _ in range(nc3 + 1)]
	for c3 in range(nc3 + 1):
		for c2 in range(nc2 + nc3 - c3 + 1):
			if c3 + c2 > n:
				break
			for c1 in range(n + 1):
				s = c1 + c2 + c3
				if s > n:
					break
				if c1 > 0:
					dp[c3][c2][c1] += (dp[c3][c2][c1 - 1] + n / s) * c1 / s
				if c2 > 0:
					dp[c3][c2][c1] += (dp[c3][c2 - 1][c1 + 1] + n / s) * c2 / s
				if c3 > 0:
					dp[c3][c2][c1] += (dp[c3 - 1][c2 + 1][c1] + n / s) * c3 / s
	print(dp[nc3][nc2][nc1])
main()


from collections import Counter
import sys

def main():
	sys.setrecursionlimit(10 ** 6)
	readline = sys.stdin.buffer.readline
	N = int(readline())
	A = list(map(int, readline().split()))
	C = Counter(A)
	(l, m, n) = (C[3], C[2], C[1])
	dp = [[[-1] * (N + 1) for _ in range(N + 1)] for _ in range(N + 1)]
	dp[0][0][0] = 0

	def exval(i, j, k):
		if dp[i][j][k] != -1:
			return dp[i][j][k]
		s = N
		if i > 0:
			s += i * exval(i - 1, j + 1, k)
		if j > 0:
			s += j * exval(i, j - 1, k + 1)
		if k > 0:
			s += k * exval(i, j, k - 1)
		dp[i][j][k] = s / (i + j + k)
		return dp[i][j][k]
	print(exval(l, m, n))
main()


N = int(input())
a = list(map(float, input().split()))
dp = [[[0.0] * (N + 2) for _ in range(N + 2)] for _ in range(N + 2)]
(one, two, three) = (a.count(1), a.count(2), a.count(3))
for k in range(three + 1):
	for j in range(two + three + 1 - k):
		for i in range(N + 1):
			if k == 0 and j == 0 and (i == 0):
				continue
			num = N
			if i > 0:
				num += dp[i - 1][j][k] * i
			if j > 0:
				num += dp[i + 1][j - 1][k] * j
			if k > 0:
				num += dp[i][j + 1][k - 1] * k
			dp[i][j][k] = num / (k + j + i)
print(dp[one][two][three])


from collections import Counter
n = int(input())
c = Counter(map(int, input().split()))
dp = [[[0] * (n + 1) for _ in range(n + 1)] for _ in range(n + 1)]
for i in range(n + 1):
	for j in range(n + 1 - i):
		for k in range(n + 1 - i - j):
			non_zero = i + j + k
			if non_zero == 0:
				continue
			dp[i][j][k] = n
			if 0 <= i - 1 and j + 1 <= n:
				dp[i][j][k] += dp[i - 1][j + 1][k] * i
			if 0 <= j - 1 and k + 1 <= n:
				dp[i][j][k] += dp[i][j - 1][k + 1] * j
			if 0 <= k - 1:
				dp[i][j][k] += dp[i][j][k - 1] * k
			dp[i][j][k] /= non_zero
print(dp[c[3]][c[2]][c[1]])


import sys
input = sys.stdin.readline
n = int(input())
a = tuple(map(int, input().split()))
c1 = a.count(1)
c2 = a.count(2)
c3 = a.count(3)
dp = [[[0.0] * (n + 1) for i in range(n + 1)] for j in range(n + 1)]
dp[0][0][0] = 0
for i in range(c3 + 1):
	for j in range(c2 + c3 - i + 1):
		for k in range(n - i - j + 1):
			if i == j == k == 0:
				continue
			tmp = n
			if k != 0:
				tmp += k * dp[k - 1][j][i]
			if j != 0:
				tmp += j * dp[k + 1][j - 1][i]
			if i != 0:
				tmp += i * dp[k][j + 1][i - 1]
			dp[k][j][i] = tmp / (i + j + k)
print(dp[c1][c2][c3])


import sys
import math
from bisect import bisect_right as br
from bisect import bisect_left as bl
sys.setrecursionlimit(1000000000)
from heapq import heappush, heappop, heappushpop
from collections import defaultdict
from itertools import accumulate
from collections import Counter
from collections import deque
from operator import itemgetter
from itertools import permutations
mod = 10 ** 9 + 7
inf = float('inf')

def I():
	return int(sys.stdin.readline())

def LI():
	return list(map(int, sys.stdin.readline().split()))
n = I()
a = LI()
dp = [[[0.0] * (n + 1) for _ in range(n + 1)] for _ in range(n + 1)]
(x, y, z) = (0, 0, 0)
for i in range(n):
	if a[i] == 1:
		x += 1
	elif a[i] == 2:
		y += 1
	else:
		z += 1
s = x + y + z
for k in range(z + 1):
	for j in range(y + z + 1 - k):
		for i in range(s + 1 - k - j):
			if i == 0 and j == 0 and (k == 0):
				continue
			tmp = 1.0 * n
			if i > 0:
				tmp += i * dp[i - 1][j][k]
			if j > 0:
				tmp += j * dp[i + 1][j - 1][k]
			if k > 0:
				tmp += k * dp[i][j + 1][k - 1]
			dp[i][j][k] = tmp / (i + j + k)
print(dp[x][y][z])


N = int(input())
A = list(map(int, input().split()))
abc = [0, 0, 0]
for i in A:
	abc[i - 1] += 1
total = sum(A)
dp = [[[0.0] * (N + 1) for _ in range(N + 1)] for i in range(N + 1)]
for k in range(abc[2] + 1):
	for j in range(abc[2] + abc[1] + 1 - k):
		for i in range(sum(abc) + 1 - j - k):
			if i == 0 and j == 0 and (k == 0):
				continue
			if i - 1 >= 0:
				dp[i][j][k] += dp[i - 1][j][k] * i
			if j - 1 >= 0:
				dp[i][j][k] += dp[i + 1][j - 1][k] * j
			if k - 1 >= 0:
				dp[i][j][k] += dp[i][j + 1][k - 1] * k
			dp[i][j][k] += N
			dp[i][j][k] /= i + j + k
print(dp[abc[0]][abc[1]][abc[2]])


def main():
	import sys
	sys.setrecursionlimit(10 ** 6)
	N = int(input())
	A = [int(i) for i in input().split()]
	dp = [0] * (N * (N + 1) ** 2 + N * (N + 1) + N + 1)
	c = [0] * 4
	for a in A:
		c[a] += 1

	def rec(c1, c2, c3):
		if c1 == c2 == c3 == 0:
			return 0
		if dp[c1 * (N + 1) ** 2 + c2 * (N + 1) + c3] != 0:
			return dp[c1 * (N + 1) ** 2 + c2 * (N + 1) + c3]
		ret = N
		if c1 > 0:
			ret += rec(c1 - 1, c2, c3) * c1
		if c2 > 0:
			ret += rec(c1 + 1, c2 - 1, c3) * c2
		if c3 > 0:
			ret += rec(c1, c2 + 1, c3 - 1) * c3
		ret /= c1 + c2 + c3
		dp[c1 * (N + 1) ** 2 + c2 * (N + 1) + c3] = ret
		return ret
	print(rec(*c[1:]))
main()


n = int(input())
a = list(map(int, input().split()))
(num1, num2, num3) = (0, 0, 0)
for i in range(n):
	if a[i] == 1:
		num1 += 1
	elif a[i] == 2:
		num2 += 1
	else:
		num3 += 1
dp = [[[-1.0 for k in range(n + 1)] for i in range(n + 1)] for j in range(n + 1)]

def f(n1, n2, n3):
	if dp[n1][n2][n3] >= 0.0:
		return dp[n1][n2][n3]
	if n1 == n2 == n3 == 0:
		return 0.0
	ret = n
	if n1 > 0:
		ret += f(n1 - 1, n2, n3) * n1
	if n2 > 0:
		ret += f(n1 + 1, n2 - 1, n3) * n2
	if n3 > 0:
		ret += f(n1, n2 + 1, n3 - 1) * n3
	ret *= 1.0 / (n1 + n2 + n3)
	dp[n1][n2][n3] = ret
	return dp[n1][n2][n3]
print(f(num1, num2, num3))


def main():
	n = int(input())
	A = [0] * 3
	for i in map(int, input().split()):
		A[i - 1] += 1
	dp = [[[0] * (n + 2) for _ in range(n + 2)] for __ in range(n + 2)]
	for i in range(A[2] + 1):
		for j in range(n - A[0] - i + 1):
			for k in range(n - i - j + 1):
				if i + j + k != 0:
					dp[i][j][k] = (dp[i - 1][j + 1][k] * i + dp[i][j - 1][k + 1] * j + dp[i][j][k - 1] * k + n) / (i + j + k)
	(i, j, k) = A
	print(dp[k][j][i])
main()


N = int(input())
A = list(map(int, input().split()))
cnt1 = A.count(1)
cnt2 = A.count(2)
cnt3 = A.count(3)
dp = [[[-1] * (N + 1) for _ in range(N + 1)] for _ in range(N + 1)]
dp[0][0][0] = 0

def func(c1, c2, c3):
	if dp[c1][c2][c3] != -1:
		return dp[c1][c2][c3]
	prob0 = (N - c1 - c2 - c3) / N
	temp = 1 / (1 - prob0)
	if c1 > 0:
		temp += func(c1 - 1, c2, c3) * (c1 / N) / (1 - prob0)
	if c2 > 0:
		temp += func(c1 + 1, c2 - 1, c3) * (c2 / N) / (1 - prob0)
	if c3 > 0:
		temp += func(c1, c2 + 1, c3 - 1) * (c3 / N) / (1 - prob0)
	dp[c1][c2][c3] = temp
	return temp
print(func(cnt1, cnt2, cnt3))


N = int(input())
a = list(map(int, input().split()))
m = d = t = 0
for i in range(len(a)):
	if a[i] == 1:
		m += 1
	elif a[i] == 2:
		d += 1
	else:
		t += 1
M = t + d + m
D = [[[0] * (M + 1) for i in range(d + t + 1)] for j in range(t + 1)]
su = 0
D[t][d][m] = 1
divTable = [1]
for i in range(1, 10000):
	divTable.append(1.0 / i)
for i in range(t, -1, -1):
	for j in range(d + t - i, -1, -1):
		for k in range(M - i - j, -1, -1):
			y = D[i][j][k]
			if y != 0:
				div = y * divTable[i + j + k]
				if i + j + k != 0:
					su += N * div
				if i >= 1:
					D[i - 1][j + 1][k] += i * div
				if j >= 1:
					D[i][j - 1][k + 1] += j * div
				if k >= 1:
					D[i][j][k - 1] += k * div
print(su)


import sys

def input():
	return sys.stdin.readline().rstrip()
from collections import Counter

def main():
	n = int(input())
	A = list(map(int, input().split()))
	ac = Counter(A)
	dp = [[[0.0] * (n + 1) for j in range(n + 1)] for i in range(n + 1)]
	(max_i, max_j, max_k) = (ac[1], ac[2], ac[3])
	for k in range(max_k + 1):
		for j in range(max_j + max_k + 1):
			for i in range(min(max_i + max_j + max_k + 1, n - (j + k) + 1)):
				if i + j + k == 0:
					continue
				res = n
				if i > 0:
					res += dp[i - 1][j][k] * i
				if j > 0:
					res += dp[i + 1][j - 1][k] * j
				if k > 0:
					res += dp[i][j + 1][k - 1] * k
				res /= i + j + k
				dp[i][j][k] = res
	print(dp[max_i][max_j][max_k])
main()


def main():
	n = int(input())
	dp = [[[0] * (n - k - j + 1) for j in range(n - k + 1)] for k in range(n + 1)]
	for thr in range(n + 1):
		for two in range(n + 1):
			for one in range(n + 1):
				su = thr + two + one
				if su > n or su == 0:
					continue
				dp[thr][two][one] += n / su
				if thr:
					dp[thr][two][one] += dp[thr - 1][two + 1][one] * thr / su
				if two:
					dp[thr][two][one] += dp[thr][two - 1][one + 1] * two / su
				if one:
					dp[thr][two][one] += dp[thr][two][one - 1] * one / su
	a = b = c = 0
	for x in map(int, input().split()):
		if x == 3:
			a += 1
		elif x == 2:
			b += 1
		elif x == 1:
			c += 1
	print(dp[a][b][c])
main()


def main():
	import sys
	input = sys.stdin.readline
	N = int(input())
	A = tuple(map(int, input().split()))
	I = 0
	J = 0
	K = 0
	for a in A:
		if a == 1:
			I += 1
		elif a == 2:
			J += 1
		else:
			K += 1
	dp = [[[0] * (N + 1) for _ in range(N + 1)] for _ in range(N + 1)]
	for k in range(K + 1):
		for j in range(K + J + 1 - k):
			for i in range(N + 1 - k - j):
				if i == j == k == 0:
					continue
				tmp = N
				if i > 0:
					tmp += i * dp[k][j][i - 1]
				if j > 0:
					tmp += j * dp[k][j - 1][i + 1]
				if k > 0:
					tmp += k * dp[k - 1][j + 1][i]
				dp[k][j][i] = tmp / (i + j + k)
	print(dp[K][J][I])
main()


N = int(input())
A = [int(i) for i in input().split()]
(I, J, K) = (0, 0, 0)
for a in A:
	if a == 1:
		I += 1
	if a == 2:
		J += 1
	if a == 3:
		K += 1
L = I + J + K
M = J + K
dp = [[[0.0] * (K + 1) for i in range(M + 1)] for i in range(L + 1)]
for n in range(1, L + 1):
	for m in range(min(n, M) + 1):
		for k in range(min(m, K) + 1):
			j = m - k
			i = n - m
			ret = N / (i + j + k)
			if i > 0:
				ret += dp[i - 1][j][k] * (i / (i + j + k))
			if j > 0:
				ret += dp[i + 1][j - 1][k] * (j / (i + j + k))
			if k > 0:
				ret += dp[i][j + 1][k - 1] * (k / (i + j + k))
			dp[i][j][k] = ret
print(dp[I][J][K])


from collections import Counter

def solve():
	N = int(input())
	As = list(map(int, input().split()))
	cnt = Counter(As)
	dp = [[[0.0] * (N + 1) for j in range(N + 1)] for i in range(N + 1)]
	for k in range(N + 1):
		for j in range(N + 1):
			if j + k > N:
				break
			for i in range(N + 1):
				if i + j + k > N:
					break
				expe = 0.0
				if i > 0:
					expe += i / N * dp[i - 1][j][k]
				if j > 0:
					expe += j / N * dp[i + 1][j - 1][k]
				if k > 0:
					expe += k / N * dp[i][j + 1][k - 1]
				if i + j + k:
					expe = (expe + 1) * N / (i + j + k)
				dp[i][j][k] = expe
	ans = dp[cnt[1]][cnt[2]][cnt[3]]
	print(ans)
solve()


n = int(input())
lst_a = list(map(int, input().split()))
(one, two, three) = (lst_a.count(1), lst_a.count(2), lst_a.count(3))
dp = [[[0.0] * (n + 1) for _ in range(n + 1)] for _ in range(n + 1)]
for k in range(three + 1):
	for j in range(two + three + 1 - k):
		for i in range(one + two + three + 1 - k - j):
			if i == 0 and j == 0 and (k == 0):
				continue
			tmp = n * 1.0
			if i > 0:
				tmp += i * dp[i - 1][j][k]
			if j > 0:
				tmp += j * dp[i + 1][j - 1][k]
			if k > 0:
				tmp += k * dp[i][j + 1][k - 1]
			dp[i][j][k] = tmp / (i + j + k)
print(dp[one][two][three])


def main():
	from collections import Counter
	import sys
	input = sys.stdin.buffer.readline
	N = int(input())
	a = list(map(int, input().split()))
	dp = [[[0] * (N + 1) for _ in range(N + 1)] for _ in range(N + 1)]
	c = Counter(a)
	for k in range(c[3] + 1):
		for j in range(c[3] + c[2] - k + 1):
			for i in range(N - j - k + 1):
				if i == j == k == 0:
					continue
				else:
					tmp = N
					if i > 0:
						tmp += dp[i - 1][j][k] * i
					if j > 0:
						tmp += dp[i + 1][j - 1][k] * j
					if k > 0:
						tmp += dp[i][j + 1][k - 1] * k
					dp[i][j][k] = tmp / (i + j + k)
	print(dp[c[1]][c[2]][c[3]])
main()


import sys
input = sys.stdin.readline
N = int(input())
A = list(map(int, input().split()))
D = {0: 0, 1: 0, 2: 0, 3: 0}
for a in A:
	D[a] += 1
one = D[1]
two = D[2]
three = D[3]
dp = [[[0.0] * (N + 1) for j in range(N + 1)] for i in range(N + 1)]

def f(c1, c2, c3):
	res = N
	if c1 > 0:
		res += dp[c1 - 1][c2][c3] * c1
	if c2 > 0:
		res += dp[c1 + 1][c2 - 1][c3] * c2
	if c3 > 0:
		res += dp[c1][c2 + 1][c3 - 1] * c3
	dp[c1][c2][c3] = res / (c1 + c2 + c3)
for k in range(three + 1):
	for j in range(two + three + 1 - k):
		for i in range(one + two + three + 1 - (j + k)):
			if i + j + k == 0:
				continue
			f(i, j, k)
print(dp[one][two][three])


import sys

def tami(i, j, k):
	if i == j == k == 0:
		return 0
	else:
		res = N
		if i > 0:
			res += dp[i - 1][j][k] * i
		if j > 0:
			res += dp[i + 1][j - 1][k] * j
		if k > 0:
			res += dp[i][j + 1][k - 1] * k
		res *= divTable[i + j + k]
		dp[i][j][k] = res
		return res
N = int(input())
a = list(map(float, input().split()))
one = a.count(1)
two = a.count(2)
three = a.count(3)
num = max(one, two, three)
dp = [[[-1] * (N + 1) for i in range(N + 1)] for i in range(N + 1)]
divTable = [1]
for i in range(1, 10000):
	divTable.append(1.0 / i)
for k in range(0, N + 1):
	for j in range(0, N - k + 1):
		for i in range(0, N - k - j + 1):
			tami(i, j, k)
print(dp[one][two][three] + 1)


import sys
from collections import Counter
sys.setrecursionlimit(10000)
N = int(input())
a = list(map(int, input().split()))
dp = [[[-1 for i in range(N + 1)] for j in range(N + 1)] for k in range(N + 1)]

def rec(i, j, k):
	if dp[i][j][k] >= 0:
		return dp[i][j][k]
	if i == 0 and j == 0 and (k == 0):
		return 0.0
	res = 0.0
	if i > 0:
		res += rec(i - 1, j, k) * i
	if j > 0:
		res += rec(i + 1, j - 1, k) * j
	if k > 0:
		res += rec(i, j + 1, k - 1) * k
	res += N
	res *= 1.0 / (i + j + k)
	dp[i][j][k] = res
	return res
c = Counter(a)
(one, two, three) = (c[1], c[2], c[3])
print(rec(one, two, three))


N = int(input())
As = list(map(int, input().split()))
d = dict()

def encode(i, j, k):
	return i + j * (N + 1) + k * (N + 1) ** 2

def decode(x):
	return [x // (N + 1) ** i % (N + 1) for i in range(3)]
B = 0
for a in As:
	B += (N + 1) ** (a - 1)
d[0] = 0
for k in range(N + 1):
	for j in range(N + 1 - k):
		for i in range(N + 1 - k - j):
			E = 0
			x = encode(i, j, k)
			s0 = N - i - j - k
			if i:
				E += i * N / (N - s0) ** 2 + d[x - 1] * (i / (N - s0))
			if j:
				E += j * N / (N - s0) ** 2 + d[x - N] * (j / (N - s0))
			if k:
				E += k * N / (N - s0) ** 2 + d[x - N ** 2 - N] * (k / (N - s0))
			d[x] = E
print(d[B])


from sys import stdin
input = stdin.readline
n = int(input())
c = [0] * 4
l = list(map(int, input().split()))
for i in l:
	c[i] += 1
dp = [[[0.0] * (n + 1) for i in range(n + 1)] for j in range(n + 1)]
dp[0][0][0] = 0
for n3 in range(0, c[3] + 1):
	for n2 in range(0, c[2] + c[3] - n3 + 1):
		for n1 in range(0, n - c[0] - n3 - n2 + 1):
			if n1 == n2 == n3 == 0:
				continue
			temp = n
			if n1 != 0:
				temp += n1 * dp[n1 - 1][n2][n3]
			if n2 != 0:
				temp += n2 * dp[n1 + 1][n2 - 1][n3]
			if n3 != 0:
				temp += n3 * dp[n1][n2 + 1][n3 - 1]
			dp[n1][n2][n3] = temp / (n1 + n2 + n3)
print(dp[c[1]][c[2]][c[3]])


n = int(input())
(*A,) = map(int, input().split())
(a, b, c) = (A.count(1), A.count(2), A.count(3))
DP = [[[0.0 for k in range(n + 1)] for j in range(n + 1)] for i in range(n + 1)]
for k in range(c + 1):
	for j in range(b + c - k + 1):
		for i in range(n - j - k + 1):
			if i + j + k == 0:
				continue
			tmp = n
			if i > 0:
				tmp += DP[i - 1][j][k] * i
			if j > 0:
				tmp += DP[i + 1][j - 1][k] * j
			if k > 0:
				tmp += DP[i][j + 1][k - 1] * k
			DP[i][j][k] = tmp / (i + j + k)
print(DP[a][b][c])


from collections import Counter, defaultdict
N = int(input())
A = list(map(int, input().split()))
C = Counter(A)
U = N + 1
inf = 1e+18
dp = [[[inf] * U for _ in range(U)] for _ in range(U)]
dp[0][0][0] = 0.0
for c in range(N + 1):
	for b in range(N + 1):
		if c + b > N:
			break
		for a in range(N + 1):
			if a + b + c == 0:
				continue
			if a + b + c > N:
				break
			prob = 0
			E = N
			if a > 0:
				E += a * dp[a - 1][b][c]
				prob += a
			if b > 0 and a < N:
				E += b * dp[a + 1][b - 1][c]
				prob += b
			if c > 0 and b < N:
				E += c * dp[a][b + 1][c - 1]
				prob += c
			dp[a][b][c] = E / prob
x = C[1]
y = C[2]
z = C[3]
print(dp[x][y][z])


def p_j_dp():
	n = int(input())
	(*a,) = map(int, input().split())
	c1 = a.count(1)
	c2 = a.count(2)
	c3 = a.count(3)
	dp = [[[0] * (n + 1) for _ in range(n + 1)] for _ in range(n + 1)]
	for k in range(c3 + 1):
		for j in range(c3 + c2 + 1 - k):
			for i in range(n + 1 - k - j):
				if i + j + k == 0:
					continue
				res = n
				if i > 0:
					res += i * dp[i - 1][j][k]
				if j > 0:
					res += j * dp[i + 1][j - 1][k]
				if k > 0:
					res += k * dp[i][j + 1][k - 1]
				res /= i + j + k
				dp[i][j][k] = res
	print(dp[c1][c2][c3])
p_j_dp()


import sys
input = sys.stdin.readline
from collections import Counter
n = int(input())
A = tuple(input().split())
C = Counter(A)
(c1, c2, c3) = [C[s] for s in ('1', '2', '3')]
DP = [[[0.0] * (n + 1) for _ in range(n + 1)] for _ in range(n + 1)]
for i in range(c3 + 1):
	for j in range(c3 + c2 - i + 1):
		for k in range(n - i - j + 1):
			if i == j == k == 0:
				continue
			tmp = n
			if i > 0:
				tmp += DP[k][j + 1][i - 1] * i
			if j > 0:
				tmp += DP[k + 1][j - 1][i] * j
			if k > 0:
				tmp += DP[k - 1][j][i] * k
			DP[k][j][i] = tmp / (i + j + k)
print(DP[c1][c2][c3])


import sys
input = sys.stdin.readline
N = int(input())
a = list(map(int, input().split()))
a.sort(reverse=True)
dp = [[[0] * (N + 1) for _ in range(N + 1)] for _ in range(N + 1)]
(i3, i2, i1) = (0, 0, 0)
for i in range(N):
	if a[i] == 3:
		i3 = i + 1
		i2 = i3
		i1 = i3
	elif a[i] == 2:
		i2 = i + 1
		i1 = i2
	elif a[i] == 1:
		i1 = i + 1
(c1, c2, c3) = (0, 0, 0)
for j3 in range(0, i3 + 1):
	for j2 in range(j3, i2 + 1):
		for j1 in range(j2, i1 + 1):
			if j3 > 0:
				c3 = dp[j3 - 1][j2][j1]
				p3 = j3 / N
			else:
				p3 = 0
			if j2 > j3:
				c2 = dp[j3][j2 - 1][j1]
				p2 = (j2 - j3) / N
			else:
				p2 = 0
			if j1 > j2:
				c1 = dp[j3][j2][j1 - 1]
				p1 = (j1 - j2) / N
			else:
				p1 = 0
			p = p3 + p2 + p1
			if p > 0:
				dp[j3][j2][j1] = (c3 * p3 + c2 * p2 + c1 * p1) / p + 1 / p
print(dp[i3][i2][i1])


N = int(input())
A = list(map(int, input().split()))
S = [0] * 3
for a in A:
	S[a - 1] += 1
(I, J, K) = S
dp = [[[0.0] * (N + 1) for j in range(N + 1)] for i in range(N + 1)]
for k in range(S[2] + 1):
	for j in range(S[1] + S[2] - k + 1):
		for i in range(S[0] + S[1] + S[2] - j - k + 1):
			if i == j == k == 0:
				continue
			dp[i][j][k] = (i * (dp[i - 1][j][k] if i > 0 else 0) + j * (dp[i + 1][j - 1][k] if j > 0 else 0) + k * (dp[i][j + 1][k - 1] if k > 0 else 0) + N) / (i + j + k)
print(dp[I][J][K])


N = int(input())
C = [0] * 4
for i in map(int, input().split()):
	if i == 1:
		C[1] += 1
	elif i == 2:
		C[2] += 1
	else:
		C[3] += 1
dp = [[[0.0] * (N + 2) for _ in range(N + 2)] for _ in range(N + 2)]
for i in range(C[3] + 1):
	for j in range(N - C[1] - i + 1):
		for k in range(N - i - j + 1):
			if i + j + k != 0:
				dp[i][j][k] = (N + i * dp[i - 1][j + 1][k] + j * dp[i][j - 1][k + 1] + k * dp[i][j][k - 1]) / (i + j + k)
print(dp[C[3]][C[2]][C[1]])


from collections import Counter
n = int(input())
cnt = Counter(input().split())
(c1, c2, c3) = (cnt['1'], cnt['2'], cnt['3'])
total = c1 + 2 * c2 + 3 * c3
c23 = c2 + c3
dp = [[[0.0] * (c3 + 1) for _ in range(c2 + c3 + 1)] for _ in range(n + 2)]
for k in range(1, n + 1):
	still = n / k
	for a1 in range(k, max(-1, 2 * k - total - 1, k - c23 - 1), -1):
		(dpap, dpac, dpan) = (dp[a1 - 1], dp[a1], dp[a1 + 1])
		for a2 in range(min(k - a1, c2 + c3), max(-1, 3 * k - 2 * a1 - total - 1, k - a1 - c3 - 1), -1):
			a3 = k - a1 - a2
			tmp = 0
			if a1:
				tmp += dpap[a2][a3] * a1
			if a2:
				tmp += dpan[a2 - 1][a3] * a2
			if a3:
				tmp += dpac[a2 + 1][a3 - 1] * a3
			dpac[a2][a3] = tmp / k + still
print(dp[c1][c2][c3])


n = int(input())
l1 = l2 = l3 = 0
l = [int(i) for i in input().split()]
for i in l:
	if i == 1:
		l1 += 1
	elif i == 2:
		l2 += 1
	else:
		l3 += 1
a = l2 + l3
dp = [[[0.0] * (l3 + 1) for i in range(a + 1)] for j in range(n + 1)]
for i in range(1, n + 1):
	for j in range(min(i, a) + 1):
		for k in range(min(j, l3) + 1):
			s = i - j
			t = j - k
			count = n / (s + t + k)
			if s > 0:
				count += dp[s - 1][t][k] * (s / (s + t + k))
			if t > 0:
				count += dp[s + 1][t - 1][k] * (t / (s + t + k))
			if k > 0:
				count += dp[s][t + 1][k - 1] * (k / (s + t + k))
			dp[s][t][k] = count
print(dp[l1][l2][l3])


n = int(input())
a = list(map(int, input().split()))
uno = a.count(1)
dos = a.count(2)
tres = n - uno - dos
dp = [[[0.0] * (n + 1) for _ in range(dos + tres + 1)] for j in range(tres + 1)]
for k in range(tres + 1):
	for j in range(dos + tres - k + 1):
		for i in range(n + 1 - j - k):
			if i + j + k == 0:
				continue
			v = i + j + k
			res = n
			if i:
				res += i * dp[k][j][i - 1]
			if j:
				res += j * dp[k][j - 1][i + 1]
			if k:
				res += k * dp[k - 1][j + 1][i]
			dp[k][j][i] = res / v
print(dp[tres][dos][uno])


import sys

def LI():
	return [int(x) for x in sys.stdin.readline().split()]

def NI():
	return int(sys.stdin.readline())
N = NI()
a = [0, 0, 0]
for x in LI():
	a[x - 1] += 1
dp = [[[0.0] * (N + 1) for _ in range(N + 1)] for _ in range(N + 1)]
for k in range(a[2] + 1):
	for j in range(a[1] + a[2] + 1):
		for i in range(N + 1):
			if not 0 < i + j + k <= N:
				continue
			x = 0.0
			if i > 0:
				x += dp[i - 1][j][k] * (i / N)
			if j > 0:
				x += dp[i + 1][j - 1][k] * (j / N)
			if k > 0:
				x += dp[i][j + 1][k - 1] * (k / N)
			x += 1.0
			x *= N / (i + j + k)
			dp[i][j][k] = x
print(dp[a[0]][a[1]][a[2]])


import sys
input = sys.stdin.readline
sys.setrecursionlimit(10 ** 7)
N = int(input())
a = list(map(int, input().split()))
one = a.count(1)
two = a.count(2)
three = a.count(3)
dp = [[[0.0] * (N + 1) for _ in range(N + 1)] for _ in range(N + 1)]
max_one = one + two + three
max_two = two + three
max_three = three
for k in range(max_three + 1):
	for j in range(max_two + 1 - k):
		for i in range(max_one + 1 - j - k):
			if i + j + k == 0:
				continue
			else:
				r = N
			if i > 0:
				r += dp[i - 1][j][k] * i
			if j > 0:
				r += dp[i + 1][j - 1][k] * j
			if k > 0:
				r += dp[i][j + 1][k - 1] * k
			dp[i][j][k] = r / (i + j + k)
print(dp[one][two][three])


import sys
input = sys.stdin.readline
N = int(input())
dp = [[[float(0)] * (N + 1) for _ in range(N + 1)] for _ in range(N + 1)]
a = list(map(int, input().split()))
(I, J, K) = (a.count(1), a.count(2), a.count(3))
for k in range(N + 1):
	for j in range(N + 1):
		for i in range(N + 1):
			if i + j + k <= N:
				if i + j + k != 0:
					dp[i][j][k] = float(N) / float(i + j + k)
				if i > 0:
					dp[i][j][k] += dp[i - 1][j][k] * float(i) / float(i + j + k)
				if j > 0:
					dp[i][j][k] += dp[i + 1][j - 1][k] * float(j) / float(i + j + k)
				if k > 0:
					dp[i][j][k] += dp[i][j + 1][k - 1] * float(k) / float(i + j + k)
print(dp[I][J][K])


n = int(input())
dp = [[[0.0] * (n + 1) for i in range(n + 1)] for j in range(n + 1)]
for i in range(n + 1):
	for j in range(n - i + 1):
		for k in range(n - i - j + 1):
			ext = i + j + k
			if ext == 0:
				continue
			dp[i][j][k] = n / ext
			if i > 0:
				dp[i][j][k] += i / ext * dp[i - 1][j + 1][k]
			if j > 0:
				dp[i][j][k] += j / ext * dp[i][j - 1][k + 1]
			if k > 0:
				dp[i][j][k] += k / ext * dp[i][j][k - 1]
a = list(map(int, input().split()))
q = [0, 0, 0, 0]
for i in a:
	q[i] += 1
print(dp[q[3]][q[2]][q[1]])


def main():
	from collections import Counter
	n = int(input())
	a = tuple((int(x) for x in input().split()))
	c = Counter(a)
	c1 = c[1]
	c2 = c[2]
	c3 = c[3]
	x1 = 310 ** 2
	x2 = 310
	dp = [0.0] * 310 ** 3
	dp[0] = 0.0
	for r3 in range(c3 + 1):
		d3 = c3 - r3
		for r2 in range(c2 + d3 + 1):
			for r1 in range(c1 + d3 + c2 - r2 + 1):
				ind = r1 * x1 + r2 * x2 + r3
				if ind != 0:
					dp[ind] = (n + (dp[ind - x1] * r1 if r1 > 0 else 0) + (dp[ind + x1 - x2] * r2 if r2 > 0 else 0) + (dp[ind + x2 - 1] * r3 if r3 > 0 else 0)) / (r1 + r2 + r3)
	print(dp[c1 * x1 + c2 * x2 + c3])
main()


N = int(input())
(*A,) = map(int, input().split())
C = [0] * 4
for a in A:
	C[a] += 1
(c1, c2, c3) = C[1:]
dp = [[[0] * (c1 + c2 + c3 + 1) for i in range(c2 + c3 + 2)] for j in range(c3 + 2)]
for c in range(c3 + 1):
	M1 = c2 + c3 - c
	T = dp[c - 1]
	S = dp[c]
	for b in range(M1 + 1):
		M2 = N - b - c
		X = S[b - 1]
		Y = S[b]
		Z = T[b + 1]
		for a in range(M2 == N, M2 + 1):
			r = N
			if a:
				r += a * Y[a - 1]
			if b:
				r += b * X[a + 1]
			if c:
				r += c * Z[a]
			Y[a] = r / (a + b + c)
print('%.10f' % dp[c3][c2][c1])


import sys

class JSushi:

	def solve(self):
		n = int(input())
		a = [int(_) for _ in input().split()]
		(u, v, w) = (a.count(1), a.count(2), a.count(3))
		dp = [[[0] * (n + 2) for _ in range(n + 2)] for _ in range(n + 2)]
		for k in range(n + 1):
			for j in range(n + 1 - k):
				for i in range(n + 1 - j - k):
					if i == j == k == 0:
						continue
					s = i + j + k
					x = 0
					x += dp[i][j + 1][k - 1] * k
					x += dp[i + 1][j - 1][k] * j
					x += dp[i - 1][j][k] * i
					x += n
					x /= s
					dp[i][j][k] = x
		print(dp[u][v][w])
solver = JSushi()
input = sys.stdin.readline
solver.solve()


import sys
sys.setrecursionlimit(2147483647)
INF = float('inf')
MOD = 10 ** 9 + 7
input = lambda : sys.stdin.readline().rstrip()

def resolve():
	n = int(input())
	counter = [0] * 3
	for a in map(int, input().split()):
		counter[a - 1] += 1
	dp = [[[None] * (n + 1) for _ in range(n + 1)] for _ in range(n + 1)]
	dp[0][0][0] = 0
	for s in range(1, n + 1):
		for k in range(n + 1):
			for j in range(n + 1):
				i = s - j - k
				if i < 0:
					break
				res = n
				if i:
					res += i * dp[i - 1][j][k]
				if j:
					res += j * dp[i + 1][j - 1][k]
				if k:
					res += k * dp[i][j + 1][k - 1]
				res /= s
				dp[i][j][k] = res
	(i, j, k) = counter
	print(dp[i][j][k])
resolve()


import sys
readline = sys.stdin.readline
N = int(readline())
A = list(map(int, readline().split()))
cnt = [0] * 4
for a in A:
	cnt[a] += 1
dp = [[[0 for k in range(N + 2)] for j in range(N + 2)] for i in range(N + 2)]
for i in range(N + 1):
	for j in range(N + 1):
		for k in range(N + 1):
			nonzero = i + j + k
			if nonzero == 0:
				continue
			dp[i][j][k] = N / nonzero
			if i - 1 >= 0:
				dp[i][j][k] += dp[i - 1][j + 1][k] * i / nonzero
			if j - 1 >= 0:
				dp[i][j][k] += dp[i][j - 1][k + 1] * j / nonzero
			if k - 1 >= 0:
				dp[i][j][k] += dp[i][j][k - 1] * k / nonzero
print(dp[cnt[3]][cnt[2]][cnt[1]])


n = int(input())
a = list(map(int, input().split()))
d = [0 for i in range(3)]
dp = [[[0 for i in range(n + 1)] for j in range(n + 1)] for k in range(n + 1)]
for i in a:
	d[i - 1] += 1
for k in range(n + 1):
	for j in range(n + 1):
		for i in range(n + 1):
			if i + j + k == 0 or i + j + k > n:
				continue
			ans = n / (i + j + k)
			x = i / (i + j + k)
			if x:
				ans += x * dp[k][j][i - 1]
			x = j / (i + j + k)
			if x:
				ans += x * dp[k][j - 1][i + 1]
			x = k / (i + j + k)
			if x:
				ans += x * dp[k - 1][j + 1][i]
			dp[k][j][i] = ans
print(dp[d[2]][d[1]][d[0]])


n = int(input())
a = list(map(int, input().split()))
dp = [[[float(0)] * (n + 1) for _ in range(n + 1)] for _ in range(n + 1)]
(I, J, K) = (0, 0, 0)
for i in a:
	if i == 1:
		I += 1
	elif i == 2:
		J += 1
	else:
		K += 1
for k in range(n + 1):
	for j in range(n + 1):
		for i in range(n + 1):
			if i + j + k <= n:
				if i + j + k != 0:
					dp[i][j][k] = float(n) / float(i + j + k)
				if i > 0:
					dp[i][j][k] += dp[i - 1][j][k] * float(i) / float(i + j + k)
				if j > 0:
					dp[i][j][k] += dp[i + 1][j - 1][k] * float(j) / float(i + j + k)
				if k > 0:
					dp[i][j][k] += dp[i][j + 1][k - 1] * float(k) / float(i + j + k)
print(dp[I][J][K])


N = int(input())
a_list = list(map(int, input().split()))
dp = [[[0] * (N + 2) for _ in range(N + 2)] for _ in range(N + 2)]
cnt = {1: 0, 2: 0, 3: 0}
for a in a_list:
	cnt[a] += 1
for i in range(N + 1):
	for j in range(N + 1):
		for k in range(N + 1):
			if i == 0 and j == 0 and (k == 0):
				continue
			dp[i][j][k] += N / (i + j + k)
			if k >= 1:
				dp[i][j][k] += dp[i][j][k - 1] * (k / (i + j + k))
			if j >= 1:
				dp[i][j][k] += dp[i][j - 1][k + 1] * (j / (i + j + k))
			if i >= 1:
				dp[i][j][k] += dp[i - 1][j + 1][k] * (i / (i + j + k))
print(dp[cnt[3]][cnt[2]][cnt[1]])


N = int(input())
a = list(map(int, input().split()))
(one, two, three) = (0, 0, 0)
for ai in a:
	if ai == 1:
		one += 1
	if ai == 2:
		two += 1
	if ai == 3:
		three += 1
u = N + 1
dp = [[[-1] * u for _ in range(u)] for _ in range(u)]
dp[0][0][0] = 0

def rec(i, j, k):
	if dp[i][j][k] >= 0:
		return dp[i][j][k]
	res = N
	if i > 0:
		res += rec(i - 1, j, k) * i
	if j > 0:
		res += rec(i + 1, j - 1, k) * j
	if k > 0:
		res += rec(i, j + 1, k - 1) * k
	res /= i + j + k
	dp[i][j][k] = res
	return res
print(rec(one, two, three))


import sys
n = int(input())
a = list(map(int, sys.stdin.readline().split()))
cnt = [0, 0, 0]
for i in range(n):
	cnt[3 - a[i]] += 1
dp = [[[0 for _ in range(n + 1)] for __ in range(n + 1)] for ___ in range(n + 1)]
dp[n][n][n] = 0
divT = [1 / i for i in range(1, n + 1)]
for x in range(n, cnt[1] + cnt[2] - 1, -1):
	for y in range(x, cnt[2] - 1, -1):
		for z in range(y, -1, -1):
			delta = n * divT[n - z - 1]
			if x != n:
				dp[x][y][z] += (dp[x + 1][y][z] + delta) * (n - x)
			if y != x:
				dp[x][y][z] += (dp[x][y + 1][z] + delta) * (x - y)
			if z != y:
				dp[x][y][z] += (dp[x][y][z + 1] + delta) * (y - z)
			dp[x][y][z] *= divT[n - z - 1]
print(dp[cnt[1] + cnt[2]][cnt[2]][0])


def resolve():
	N = int(input())
	A = list(map(int, input().split()))
	one = A.count(1)
	two = A.count(2)
	three = A.count(3)
	dp = [[[0.0] * (N + 1) for _ in range(N + 1)] for _ in range(N + 1)]
	for c3 in range(N + 1):
		for c2 in range(N + 1):
			for c1 in range(N + 1):
				if c3 + c2 + c1 <= N:
					nozero = float(c3 + c2 + c1)
					if nozero == 0.0:
						continue
					dp[c3][c2][c1] = float(N) / nozero
					if c3 - 1 >= 0:
						dp[c3][c2][c1] += dp[c3 - 1][c2 + 1][c1] * float(c3) / nozero
					if c2 - 1 >= 0:
						dp[c3][c2][c1] += dp[c3][c2 - 1][c1 + 1] * float(c2) / nozero
					if c1 - 1 >= 0:
						dp[c3][c2][c1] += dp[c3][c2][c1 - 1] * float(c1) / nozero
	print(dp[three][two][one])
resolve()


def main():
	from collections import Counter
	import sys
	sys.setrecursionlimit(10 ** 7)
	readline = sys.stdin.readline

	def prob(c1, c2, c3):
		if memo[c1][c2][c3] != -1.0:
			return
		ret = n
		if c1 > 0:
			ret += c1 * memo[c1 - 1][c2][c3]
		if c2 > 0:
			ret += c2 * memo[c1 + 1][c2 - 1][c3]
		if c3 > 0:
			ret += c3 * memo[c1][c2 + 1][c3 - 1]
		ret /= c1 + c2 + c3
		memo[c1][c2][c3] = ret
		return
	n = int(readline())
	(*a,) = map(int, readline().split())
	ctr = Counter(a)
	memo = [[[-1.0] * (n + 1) for _ in range(n + 1)] for _ in range(n + 1)]
	memo[0][0][0] = 0.0
	for c3 in range(n + 1):
		for c2 in range(n - c3 + 1):
			for c1 in range(n - c2 - c3 + 1):
				prob(c1, c2, c3)
	print(memo[ctr[1]][ctr[2]][ctr[3]])
main()


import sys

def I():
	return int(sys.stdin.readline())

def LI():
	return list(map(int, sys.stdin.readline().split()))

def main():
	N = I()
	a = LI()
	t = [0, 0, 0]
	for ai in a:
		t[ai - 1] += 1
	(A, B, C) = t
	E = B + C
	dp = [[0 if not i | j else N / (i + j) for j in range(E + 1)] for i in range(N + 1)]
	for k in range(C + 1):
		for i in range(N + 1):
			dp[i][E] = 0 if not i | E | k else N / (i + E + k)
		for j in range(E + 1 - k):
			for i in range(N + 1 - k - j):
				z = i + j + k
				if not z:
					continue
				d = dp[i][j]
				if i < N:
					dp[i + 1][j] += (i + 1) * d / (z + 1)
				if (i > 0) & (j < E):
					dp[i - 1][j + 1] += (j + 1) * d / z
				if (j > 0) & (k < C):
					dp[i][j - 1] = (k + 1) * d / z + N / z
	print(dp[A][B])
main()


n = int(input())
a = [int(i) for i in input().split()]
import sys
sys.setrecursionlimit(10 ** 7)
ko = [0] * 4
for i in a:
	ko[i] += 1
dp = [[[0.0] * (n + 1) for i in range(n + 1)] for j in range(n + 1)]
cc = ko[1] + ko[2] + ko[3]
ccc = ko[2] + ko[3]
for k in range(ko[3] + 1):
	for j in range(ccc + 1 - k):
		for i in range(cc + 1 - k - j):
			t = i + j + k
			if i != 0:
				dp[i][j][k] += (dp[i - 1][j][k] + n / t) * i / t
			if j != 0 and i < n:
				dp[i][j][k] += (dp[i + 1][j - 1][k] + n / t) * j / t
			if k != 0 and j < n:
				dp[i][j][k] += (dp[i][j + 1][k - 1] + n / t) * k / t
print(dp[ko[1]][ko[2]][ko[3]])


from collections import Counter
N = int(input())
a = list(map(int, input().split()))
c = Counter(a)
dp = [[[0] * (N + 1) for _ in range(N + 1)] for _ in range(N + 1)]
for k in range(c[3] + 1):
	for j in range(c[3] + c[2] - k + 1):
		for i in range(N - j - k + 1):
			if i == j == k == 0:
				continue
			else:
				tmp = N
				if i > 0:
					tmp += dp[k][j][i - 1] * i
				if j > 0:
					tmp += dp[k][j - 1][i + 1] * j
				if k > 0:
					tmp += dp[k - 1][j + 1][i] * k
				dp[k][j][i] = tmp / (i + j + k)
print(dp[c[3]][c[2]][c[1]])


import collections
n = int(input())
arr = list(map(int, input().split()))
dp = [[[0] * (n + 1) for _ in range(n + 1)] for _ in range(n + 1)]
cnt = collections.Counter(arr)
for total in range(1, n + 1):
	for three in range(total + 1):
		for two in range(total - three + 1):
			one = total - two - three
			dp[one][two][three] += n / total
			if one != 0:
				dp[one][two][three] += dp[one - 1][two][three] * one / total
			if two != 0:
				dp[one][two][three] += dp[one + 1][two - 1][three] * two / total
			if three != 0:
				dp[one][two][three] += dp[one][two + 1][three - 1] * three / total
print(dp[cnt[1]][cnt[2]][cnt[3]])


from collections import Counter
N = int(input())
A = Counter(map(int, input().split()))
S = [None, A[3] + A[2] + A[1], A[3] + A[2], A[3]]
dp = [[[0] * (S[3] + 1) for _ in range(S[2] + 1)] for __ in range(S[1] + 1)]
for l in range(1, S[1] + 1):
	for m in range(S[2] + 1):
		if l < m:
			break
		for k in range(S[3] + 1):
			if m < k:
				break
			dp[l][m][k] = (dp[l - 1][m][k] * (l - m) + dp[l][m - 1][k] * (m - k) + dp[l][m][k - 1] * k + N) / l
print(dp[S[1]][S[2]][S[3]])


def main():
	n = int(input())
	num = [int(i) for i in input().split()]
	(c1, c2, c3) = (0, 0, 0)
	for i in range(n):
		if num[i] == 1:
			c1 += 1
		elif num[i] == 2:
			c2 += 1
		else:
			c3 += 1
	a = c1 + c2 + c3 + 1
	b = c2 + c3 + 1
	c = c3 + 1
	dp = [[[0] * a for _ in range(b)] for _ in range(c)]
	for i in range(c):
		for j in range(b - i):
			for k in range(a - i - j):
				tmp = i + j + k
				if tmp == 0:
					continue
				else:
					dp[i][j][k] = n / tmp
					if i > 0:
						dp[i][j][k] += i * dp[i - 1][j + 1][k] / tmp
					if j > 0:
						dp[i][j][k] += j * dp[i][j - 1][k + 1] / tmp
					if k > 0:
						dp[i][j][k] += k * dp[i][j][k - 1] / tmp
	print(dp[c3][c2][c1])
main()


import sys
sys.setrecursionlimit(10 ** 6)
readline = sys.stdin.buffer.readline

def read_int():
	return int(readline())

def read_int_n():
	return list(map(int, readline().split()))

def f(c1, c2, c3):
	if memo[c1][c2][c3] != -1:
		return memo[c1][c2][c3]
	c0 = N - (c1 + c2 + c3)
	p0 = c0 / N
	ip0 = 1 - p0
	ret = 1 / ip0
	if c1 > 0:
		p1 = c1 / N
		ret += f(c1 - 1, c2, c3) * p1 / ip0
	if c2 > 0:
		p2 = c2 / N
		ret += f(c1 + 1, c2 - 1, c3) * p2 / ip0
	if c3 > 0:
		p3 = c3 / N
		ret += f(c1, c2 + 1, c3 - 1) * p3 / ip0
	memo[c1][c2][c3] = ret
	return ret
N = read_int()
A = read_int_n()
memo = [[[-1] * (N + 1) for _ in range(N + 1)] for _ in range(N + 1)]
memo[0][0][0] = 0
print(f(A.count(1), A.count(2), A.count(3)))


import sys
sys.setrecursionlimit(10 ** 7)
input = sys.stdin.readline

def main():
	n = int(input())
	a = list(map(int, input().split()))
	ca = {1: a.count(1), 2: a.count(2), 3: a.count(3)}
	memo = [[[-1] * (n + 2) for _ in range(n + 2)] for _ in range(n + 2)]
	memo[0][0][0] = 0
	for x3 in range(ca[3] + 1):
		for x2 in range(ca[2] + ca[3] + 1 - x3):
			for x1 in range(ca[1] + ca[2] + ca[3] + 1 - x3 - x2):
				if (x1, x2, x3) == (0, 0, 0):
					continue
				tmp = 0
				if x1 > 0:
					tmp += memo[x1 - 1][x2][x3] * x1
				if x2 > 0:
					tmp += memo[x1 + 1][x2 - 1][x3] * x2
				if x3 > 0:
					tmp += memo[x1][x2 + 1][x3 - 1] * x3
				tmp += n
				tmp /= x1 + x2 + x3
				memo[x1][x2][x3] = tmp
	print(memo[ca[1]][ca[2]][ca[3]])
main()


from collections import Counter
n = int(input())
a = list(map(int, input().split()))
c = Counter(a)
(c1, c2, c3) = (c[1], c[2], c[3])
dp = [[[0 for i in range(c3 + 1)] for j in range(c2 + c3 + 1)] for k in range(c1 + c2 + c3 + 1)]
for k in range(c3 + 1):
	for j in range(c2 + c3 + 1):
		for i in range(n + 1):
			if i + j + k > n or i == j == k == 0:
				continue
			x = (n - i - j - k) / n
			dp[i][j][k] = 1
			if 0 < i:
				dp[i][j][k] += dp[i - 1][j][k] * (i / n)
			if 0 < j and i + 1 <= n:
				dp[i][j][k] += dp[i + 1][j - 1][k] * (j / n)
			if 0 < k and j + 1 <= c2 + c3:
				dp[i][j][k] += dp[i][j + 1][k - 1] * (k / n)
			dp[i][j][k] /= 1 - x
print(dp[c1][c2][c3])


import sys
input = sys.stdin.readline
n = int(input())
a = list(map(int, input().split()))
A = a.count(1)
B = a.count(2)
C = a.count(3)
dp = [[[0.0] * (n + 1) for _ in range(n + 1)] for _ in range(n + 1)]

def c():
	for k in range(C + 1):
		for j in range(B + C + 1 - k):
			for i in range(n + 1 - k - j):
				if i == 0 and j == 0 and (k == 0):
					continue
				res = 1.0 * n
				if i > 0:
					res += i * dp[i - 1][j][k]
				if j > 0:
					res += j * dp[i + 1][j - 1][k]
				if k > 0:
					res += k * dp[i][j + 1][k - 1]
				dp[i][j][k] = res / (i + j + k)
	print(dp[A][B][C])
c()


from collections import Counter
(N, *A) = map(int, open(0).read().split())
C = Counter(A)
dp = [[[0.0] * (N + 2) for _ in range(N + 2)] for _ in range(N + 2)]
for i in range(C[3] + 1):
	for j in range(N - C[1] - i + 1):
		for k in range(N - i - j + 1):
			if i + j + k != 0:
				dp[i][j][k] = (N + i * dp[i - 1][j + 1][k] + j * dp[i][j - 1][k + 1] + k * dp[i][j][k - 1]) / (i + j + k)
print(dp[C[3]][C[2]][C[1]])


import sys

def input():
	return sys.stdin.readline().rstrip()

def main():
	n = int(input())
	A = list(map(int, input().split()))
	dp = [[[0.0] * (n + 1) for j in range(n + 1)] for i in range(n + 1)]
	(max_i, max_j) = (A.count(1), A.count(2))
	max_k = n - max_i - max_j
	for k in range(max_k + 1):
		for j in range(max_j + max_k + 1):
			for i in range(min(max_i + max_j + max_k + 1, n - (j + k) + 1)):
				if i + j + k == 0:
					continue
				res = n
				if i > 0:
					res += dp[i - 1][j][k] * i
				if j > 0:
					res += dp[i + 1][j - 1][k] * j
				if k > 0:
					res += dp[i][j + 1][k - 1] * k
				res /= i + j + k
				dp[i][j][k] = res
	print(dp[max_i][max_j][max_k])
main()


import sys
input = sys.stdin.readline
sys.setrecursionlimit(10 ** 7)
n = int(input())
A = tuple(map(int, input().split()))
C = [0] * 3
for a in A:
	C[a - 1] += 1
dp = [[[-1] * (n + 1) for i in range(n + 1)] for j in range(n + 1)]
dp[0][0][0] = 0

def f(i, j, k):
	if dp[i][j][k] != -1:
		return dp[i][j][k]
	res = 1
	if i:
		res += f(i - 1, j, k) * (i / n)
	if j:
		res += f(i + 1, j - 1, k) * (j / n)
	if k:
		res += f(i, j + 1, k - 1) * (k / n)
	res /= (i + j + k) / n
	dp[i][j][k] = res
	return res
ans = f(C[0], C[1], C[2])
print(ans)


N = int(input())
a = tuple((int(i) for i in input().split()))
dp = [[[0.0] * (N + 1) for _ in range(N + 1)] for _ in range(N + 1)]
dp[0][0][0] = 0.0
C_1 = a.count(1)
C_2 = a.count(2)
C_3 = a.count(3)
for i in range(C_3 + 1):
	for j in range(C_2 + C_3 - i + 1):
		for k in range(N - i - j + 1):
			if i == j == k == 0:
				continue
			tmp = N
			if i > 0:
				tmp += dp[i - 1][j + 1][k] * i
			if j > 0:
				tmp += dp[i][j - 1][k + 1] * j
			if k > 0:
				tmp += dp[i][j][k - 1] * k
			dp[i][j][k] = tmp / (i + j + k)
print(dp[C_3][C_2][C_1])


from collections import Counter
N = int(input())
A = list(map(int, input().split()))
dp = [[[0.0] * (N + 2) for _ in range(N + 2)] for _ in range(N + 2)]
CA = Counter(A)
SA = CA[1]
SB = CA[2]
SC = CA[3]
for c in range(SC + 1):
	for b in range(SB + SC + 1):
		if b + c > N:
			break
		for a in range(N + 1):
			if a + b + c > N:
				break
			S = a + b + c
			if S == 0:
				continue
			dp[a][b][c] = N / S + a / S * dp[a - 1][b][c] + b / S * dp[a + 1][b - 1][c] + c / S * dp[a][b + 1][c - 1]
print(dp[SA][SB][SC])


import collections
n = int(input())
a = list(map(int, input().split()))
d = collections.Counter(a)
s = sum(a)
(n1, n2, n3) = (d[1], d[2], d[3])
dp = [[0] * (n2 + n3 + 1) for _ in range(n3 + 1)]
dp[n3][n2] = 1.0
ans = 0
for i in range(s, 0, -1):
	dp2 = [[0] * (n2 + n3 + 1) for _ in range(n3 + 1)]
	for i3 in range(n3, -1, -1):
		for i2 in range(min(n2 + n3, (i - i3 * 3) // 2), -1, -1):
			i1 = i - i3 * 3 - i2 * 2
			i0 = n - i1 - i2 - i3
			if i2 < 0 or i1 < 0 or i0 < 0:
				continue
			e0 = n / (i1 + i2 + i3)
			dp2[i3][i2] += dp[i3][i2] * i1 / (i1 + i2 + i3)
			ans += dp[i3][i2] * e0 * (i1 / (i1 + i2 + i3))
			if i2 > 0:
				dp2[i3][i2 - 1] += dp[i3][i2] * i2 / (i1 + i2 + i3)
				ans += dp[i3][i2] * e0 * (i2 / (i1 + i2 + i3))
			if i3 > 0 and i2 < n2 + n3:
				dp2[i3 - 1][i2 + 1] += dp[i3][i2] * i3 / (i1 + i2 + i3)
				ans += dp[i3][i2] * e0 * (i3 / (i1 + i2 + i3))
	dp = dp2
print(ans)


import collections
import sys
sys.setrecursionlimit(10 ** 8)
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines
N = int(readline())
A = [int(x) for x in readline().split()]
ac = collections.Counter(A)
assert set(ac.keys()).issubset({1, 2, 3})

def solve(c1, c2, c3):
	K = c1 + c2 + c3
	L = K + 1
	L2 = L ** 2
	dp = [0.0] * L ** 3
	for i3 in range(c3 + 1):
		for i2 in range(c2 + c3 + 1):
			for i1 in range(N - i2 - i3 + 1):
				isum = i1 + i2 + i3
				if isum == 0:
					continue
				i0 = N - i1 - i2 - i3
				if i0 < 0:
					continue
				e = i0
				if i1 > 0:
					e += i1 * (1.0 + dp[(i1 - 1) * L2 + i2 * L + i3])
				if i2 > 0 and i1 <= K:
					e += i2 * (1.0 + dp[(i1 + 1) * L2 + (i2 - 1) * L + i3])
				if i3 > 0 and i2 + 1 <= c2 + c3:
					e += i3 * (1.0 + dp[i1 * L2 + (i2 + 1) * L + i3 - 1])
				dp[i1 * L2 + i2 * L + i3] = e / isum
	return dp[c1 * L2 + c2 * L + c3]
print(solve(ac[1], ac[2], ac[3]))


import sys
import bisect
input = sys.stdin.readline

def LI():
	return list(map(int, input().split()))

def LIR(n):
	return [LI() for _ in range(n)]

def J():
	n = int(input())
	a = LI()
	a.sort()
	one = bisect.bisect_right(a, 1)
	two = bisect.bisect_right(a, 2) - one
	three = n - one - two
	dp = [[[0.0] * (n + 1) for _ in range(n + 1)] for _ in range(n + 1)]
	for k in range(three + 1):
		for j in range(two + three + 1 - k):
			for i in range(one + two + three + 1 - k - j):
				if i == 0 and j == 0 and (k == 0):
					continue
				tmp = n * 1.0
				if i > 0:
					tmp += i * dp[i - 1][j][k]
				if j > 0:
					tmp += j * dp[i + 1][j - 1][k]
				if k > 0:
					tmp += k * dp[i][j + 1][k - 1]
				dp[i][j][k] = tmp / (i + j + k)
	print(dp[one][two][three])
J()


N = int(input())
A = input().split()
px = py = pz = 0
for a in A:
	if a == '1':
		px += 1
	elif a == '2':
		py += 1
	elif a == '3':
		pz += 1
nx = px + py + pz
ny = py + pz
nz = pz
dp = [[[0] * (nx + 1) for y in range(ny + 1)] for z in range(nz + 1)]
for z in range(nz + 1):
	for y in range(ny + 1 - z):
		for x in range(nx + 1 - z - y):
			if x == y == z == 0:
				continue
			else:
				s = x + y + z
				t = N / s
				if x > 0:
					t += dp[z][y][x - 1] * x / s
				if y > 0:
					t += dp[z][y - 1][x + 1] * y / s
				if z > 0:
					t += dp[z - 1][y + 1][x] * z / s
				dp[z][y][x] += t
print(dp[pz][py][px])


N = int(input())
A = list(map(int, input().split()))
dp = [[[-1] * (N + 1) for _ in range(N + 1)] for _ in range(N + 1)]
dp[0][0][0] = 0

def mem_rec(i, j, k):
	if dp[i][j][k] != -1:
		return dp[i][j][k]
	ans = 0
	if i > 0:
		ans += mem_rec(i - 1, j, k) * i
	if j > 0:
		ans += mem_rec(i + 1, j - 1, k) * j
	if k > 0:
		ans += mem_rec(i, j + 1, k - 1) * k
	ans += N
	ans /= i + j + k
	dp[i][j][k] = ans
	return ans
print(mem_rec(A.count(1), A.count(2), A.count(3)))


from collections import defaultdict
import sys
from functools import lru_cache
sys.setrecursionlimit(100000)
N = int(input())
counts = [0, 0, 0]
for a in map(int, input().split()):
	counts[a - 1] += 1
(A, B, C) = counts
dp = [[[None] * (C + 1) for _ in range(B + C + 1)] for _ in range(A + B + C + 1)]
dp[0][0][0] = 0
for k in range(C + 1):
	for j in range(B + C + 1 - k):
		for i in range(A + B + C + 1 - k - j):
			try:
				dp[i][j][k] = ((i * dp[i - 1][j][k] if i else 0) + (j * dp[i + 1][j - 1][k] if j else 0) + (k * dp[i][j + 1][k - 1] if k else 0) + N) / (i + j + k)
			except ZeroDivisionError:
				pass
print(dp[A][B][C])


from collections import Counter
import sys
input = sys.stdin.buffer.readline

def main():
	n = int(input())
	m = float(n)
	a = Counter(map(int, input().split()))
	dp = [[[0.0] * (n + 1) for _ in range(n + 1)] for _ in range(n + 1)]
	for k in range(a[3] + 1):
		for j in range(a[2] + a[3] - k + 1):
			for i in range(n - j - k + 1):
				if i + j + k == 0:
					continue
				tmp = m
				if i > 0:
					tmp += i * dp[i - 1][j][k]
				if j > 0:
					tmp += j * dp[i + 1][j - 1][k]
				if k > 0:
					tmp += k * dp[i][j + 1][k - 1]
				dp[i][j][k] = tmp / (i + j + k)
	print(dp[a[1]][a[2]][a[3]])
main()


N = int(input())
a = list(map(int, input().split()))
c1 = 0
c2 = 0
c3 = 0
for i in range(N):
	if a[i] == 1:
		c1 += 1
	if a[i] == 2:
		c2 += 1
	if a[i] == 3:
		c3 += 1
dp = [[[0] * (N + 1) for i in range(N + 1)] for j in range(N + 1)]
for k in range(c3 + 1):
	for j in range(c3 + c2 - k + 1):
		for i in range(N - j - k + 1):
			if i == j == k == 0:
				continue
			else:
				res = N
				if i > 0:
					res += dp[k][j][i - 1] * i
				if j > 0:
					res += dp[k][j - 1][i + 1] * j
				if k > 0:
					res += dp[k - 1][j + 1][i] * k
				dp[k][j][i] = res / (i + j + k)
print(dp[c3][c2][c1])


N = int(input())
A = list(map(int, input().split()))
C = [0, A.count(1), A.count(2), A.count(3)]
dp = [[[0.0] * (N + 1) for _ in range(N + 1)] for _ in range(N + 1)]
for k in range(C[3] + 1):
	for j in range(C[3] + C[2] + 1 - k):
		for i in range(N + 1 - j - k):
			if i + j + k == 0:
				continue
			res = N
			if i > 0:
				res += i * dp[i - 1][j][k]
			if j > 0:
				res += j * dp[i + 1][j - 1][k]
			if k > 0:
				res += k * dp[i][j + 1][k - 1]
			dp[i][j][k] = res / (i + j + k)
print(dp[C[1]][C[2]][C[3]])


from collections import Counter
N = int(input())
A = list(map(int, input().split()))
B = Counter(A)
DP = [[[0.0] * (B[3] + 1) for _ in range(N + 1)] for __ in range(N + 2)]
for k in range(B[3] + 1):
	for j in range(B[2] + B[3] + 1 - k):
		for i in range(B[1] + B[2] + B[3] + 1 - k - j):
			if i == j == k == 0:
				continue
			tmp = float(N)
			if i > 0:
				tmp += i * DP[i - 1][j][k]
			if j > 0:
				tmp += j * DP[i + 1][j - 1][k]
			if k > 0:
				tmp += k * DP[i][j + 1][k - 1]
			DP[i][j][k] = tmp / (i + j + k)
print(DP[B[1]][B[2]][B[3]])


import sys

def solve(N: int, a: 'List[int]'):
	c = [0] * 4
	for A in a:
		c[A] += 1
	J = min(c[2] + c[3] + 1, N + 1)
	I = min(c[1] + c[2] + c[3] + 1, N + 1)
	kitai = [[[0] * (I + 1) for _ in range(J + 1)] for _ in range(c[3] + 1)]
	for k in range(c[3] + 1):
		for j in range(J):
			for i in range(I):
				tot = i + j + k
				if tot == 0 or tot > N:
					continue
				res = N + kitai[k][j][i - 1] * i + kitai[k][j - 1][i + 1] * j + kitai[k - 1][j + 1][i] * k
				kitai[k][j][i] = res / tot
	print(kitai[c[3]][c[2]][c[1]])
	return

def main():

	def iterate_tokens():
		for line in sys.stdin:
			for word in line.split():
				yield word
	tokens = iterate_tokens()
	N = int(next(tokens))
	a = [int(next(tokens)) for _ in range(N)]
	solve(N, a)
main()


def main():
	import sys
	input = sys.stdin.readline
	sys.setrecursionlimit(10000000)
	from collections import Counter, deque
	from itertools import combinations, permutations, accumulate
	from bisect import bisect_left, bisect_right
	import heapq
	from math import floor, ceil
	N = int(input())
	a = tuple(map(int, input().split()))
	c1 = a.count(1)
	c2 = a.count(2)
	c3 = a.count(3)
	dp = [[[0.0] * (N + 1) for _ in range(N + 1)] for __ in range(N + 1)]
	for i in range(c3 + 1):
		for j in range(c2 + c3 - i + 1):
			for k in range(N - i - j + 1):
				if i == j == k == 0:
					continue
				tmp = N
				if k != 0:
					tmp += k * dp[k - 1][j][i]
				if j != 0:
					tmp += j * dp[k + 1][j - 1][i]
				if i != 0:
					tmp += i * dp[k][j + 1][i - 1]
				dp[k][j][i] = tmp / (i + j + k)
	print(dp[c1][c2][c3])
main()


import sys, math, itertools, collections, bisect
input = lambda : sys.stdin.buffer.readline().rstrip().decode('utf-8')
inf = float('inf')
mod = 10 ** 9 + 7
mans = inf
ans = 0
count = 0
pro = 1
n = int(input())
L = list(map(int, input().split()))
A = L.count(1)
B = L.count(2)
C = L.count(3)
dp = [[[0.0] * (n + 1) for i in range(n + 1)] for i in range(n + 1)]
for c in range(C + 1):
	for b in range(B + C + 1 - c):
		for a in range(A + B + C + 1 - c - b):
			if a == b == c == 0:
				continue
			result = n
			result += dp[a - 1][b][c] * a if a - 1 >= 0 else 0
			result += dp[a + 1][b - 1][c] * b if b - 1 >= 0 else 0
			result += dp[a][b + 1][c - 1] * c if c - 1 >= 0 else 0
			dp[a][b][c] = result / (a + b + c)
print(dp[A][B][C])


import sys
input = sys.stdin.readline
n = int(input())
a = list(map(int, input().split()))
cnt = [0, 0, 0]
for ai in a:
	cnt[ai - 1] += 1
(p, q, r) = (cnt[0], cnt[1], cnt[2])
dp = [[[0.0] * (n + 1) for _ in range(n + 1)] for _ in range(n + 1)]
for k in range(r + 1):
	for j in range(r + q + 1):
		for i in range(n + 1):
			if not 0 < i + j + k <= n:
				continue
			tmp = 0.0
			if i > 0:
				tmp += dp[i - 1][j][k] * i
			if j > 0:
				tmp += dp[i + 1][j - 1][k] * j
			if k > 0:
				tmp += dp[i][j + 1][k - 1] * k
			tmp += n
			dp[i][j][k] = tmp / (i + j + k)
print(dp[p][q][r])


N = int(input())
a = [int(x) for x in input().split()]
p = [0] * 3
for i in a:
	p[3 - i] += 1
dp = [[[0] * (N + 1 - i - j) for j in range(N + 1 - i)] for i in range(N + 1)]
for i in range(N + 1):
	for j in range(N + 1 - i):
		for k in range(N + 1 - i - j):
			if i + j + k == 0:
				continue
			if i > 0:
				dp[i][j][k] += dp[i - 1][j + 1][k] * i
			if j > 0:
				dp[i][j][k] += dp[i][j - 1][k + 1] * j
			if k > 0:
				dp[i][j][k] += dp[i][j][k - 1] * k
			dp[i][j][k] += N
			dp[i][j][k] /= i + j + k
print(dp[p[0]][p[1]][p[2]])


(n, a) = (int(input()), map(int, input().split()))
c = [0] * 3
for i in a:
	c[i - 1] += 1
(x, y, z) = c
dp = [[[None] * (z + 2) for i in range(n - x + 2)] for i in range(n + 2)]
dp[0][0][0] = 0
for k in range(z + 1):
	for j in range(n - x - k + 1):
		for i in range(n - k - j + 1):
			if i + j + k:
				dp[i][j][k] = ((dp[i - 1][j][k] * i if i else 0) + (dp[i + 1][j - 1][k] * j if j else 0) + (dp[i][j + 1][k - 1] * k if k else 0) + n) / (i + j + k)
print(dp[x][y][z])


n = int(input())
dp = [[[0.0] * (n + 1) for i in range(n + 1)] for j in range(n + 1)]
dp[0][0][0] = 0
a = [float(i) for i in input().split()]
p = a.count(1)
q = a.count(2)
r = a.count(3)
l = [1]
for i in range(1, 1000):
	l.append(1.0 / i)
for k in range(r + 1):
	for j in range(q + r - k + 1):
		for i in range(n - k - j + 1):
			if i == j == k == 0:
				continue
			res = n
			if i > 0:
				res += i * dp[i - 1][j][k]
			if j > 0:
				res += j * dp[i + 1][j - 1][k]
			if k > 0:
				res += k * dp[i][j + 1][k - 1]
			res *= 1 / (i + j + k)
			dp[i][j][k] = res
print(dp[p][q][r])


n = int(input())
A = list(map(int, input().split()))
one = A.count(1)
two = A.count(2)
three = A.count(3)
dp = [[[0] * (n + 1) for _ in range(n + 1)] for _ in range(n + 1)]
for sushi in range(1, n + 1):
	for k in range(sushi + 1):
		for j in range(sushi - k + 1):
			i = sushi - k - j
			if i != 0:
				dp[i][j][k] += dp[i - 1][j][k] * i / sushi
			if j != 0:
				dp[i][j][k] += dp[i + 1][j - 1][k] * j / sushi
			if k != 0:
				dp[i][j][k] += dp[i][j + 1][k - 1] * k / sushi
			dp[i][j][k] += n / sushi
print(dp[one][two][three])


n = int(input())
ns = list(map(int, input().split()))
one = ns.count(1)
two = ns.count(2)
three = n - one - two
dp = [[[0 for _ in range(n + 1)] for _ in range(two + three + 1)] for _ in range(three + 1)]
for k in range(three + 1):
	for j in range(two + three - k + 1):
		for i in range(n - j - k + 1):
			v = k + i + j
			if v == 0:
				continue
			res = n
			if i:
				res += i * dp[k][j][i - 1]
			if j:
				res += j * dp[k][j - 1][i + 1]
			if k:
				res += k * dp[k - 1][j + 1][i]
			dp[k][j][i] = res / v
print(dp[three][two][one])


def main():
	import sys
	input = sys.stdin.buffer.readline
	N = int(input())
	a = list(map(int, input().split()))
	(c1, c2, c3) = (0, 0, 0)
	for aa in a:
		if aa == 1:
			c1 += 1
		elif aa == 2:
			c2 += 1
		else:
			c3 += 1
	dp = [[[0] * (N + 1) for _ in range(N + 1)] for _ in range(N + 1)]
	for k in range(c3 + 1):
		for j in range(c3 + c2 - k + 1):
			for i in range(N - j - k + 1):
				if i == j == k == 0:
					continue
				else:
					tmp = N
					if i > 0:
						tmp += dp[k][j][i - 1] * i
					if j > 0:
						tmp += dp[k][j - 1][i + 1] * j
					if k > 0:
						tmp += dp[k - 1][j + 1][i] * k
					dp[k][j][i] = tmp / (i + j + k)
	print(dp[c3][c2][c1])
main()


n = int(input())
dp = [[[0] * (n + 1) for _ in range(n + 1)] for _ in range(n + 1)]
for thr in range(n + 1):
	for two in range(n + 1):
		for one in range(n + 1):
			su = thr + two + one
			if su > n or su == 0:
				continue
			dp[thr][two][one] += n / su
			if thr:
				dp[thr][two][one] += dp[thr - 1][two + 1][one] * thr / su
			if two:
				dp[thr][two][one] += dp[thr][two - 1][one + 1] * two / su
			if one:
				dp[thr][two][one] += dp[thr][two][one - 1] * one / su
a = b = c = 0
for x in map(int, input().split()):
	if x == 3:
		a += 1
	elif x == 2:
		b += 1
	elif x == 1:
		c += 1
print(dp[a][b][c])


n = int(input())
a = input().split()
c1 = a.count('1')
c2 = a.count('2')
c3 = a.count('3')
dp = [[[0] * (n + 1) for _ in range(c3 + c2 + 1)] for __ in range(c3 + 1)]
for i in range(c3 + 1):
	for j in range(c3 + c2 + 1 - i):
		for k in range(n + 1 - i - j):
			if i + j + k == 0:
				dp[i][j][k] = 0
			else:
				temp = 0
				if i > 0:
					temp += dp[i - 1][j + 1][k] * i / (k + j + i)
				if j > 0:
					temp += dp[i][j - 1][k + 1] * j / (k + j + i)
				if k > 0:
					temp += dp[i][j][k - 1] * k / (k + j + i)
				dp[i][j][k] = temp + n / (k + j + i)
print(dp[c3][c2][c1])


def main():
	N = int(input())
	a = map(int, input().split())
	single = double = triple = 0
	for sushi in a:
		if sushi == 1:
			single += 1
		elif sushi == 2:
			double += 1
		elif sushi == 3:
			triple += 1
	dp = [[[0 for i in range(1 + single + double + triple - j - k)] for j in range(double + triple + 1 - k)] for k in range(triple + 1)]
	for k in range(triple + 1):
		for j in range(double + triple + 1 - k):
			for i in range(1 + single + double + triple - j - k):
				if i == 0 and j == 0 and (k == 0):
					continue
				first = second = third = 0
				if i - 1 >= 0 and j >= 0 and (k >= 0):
					first = dp[k][j][i - 1]
				if i + 1 >= 0 and j - 1 >= 0 and (k >= 0):
					second = dp[k][j - 1][i + 1]
				if i >= 0 and j + 1 >= 0 and (k - 1 >= 0):
					third = dp[k - 1][j + 1][i]
				dp[k][j][i] = (first * i + second * j + third * k + N) / (i + j + k)
	print(dp[triple][double][single])
main()


N = int(input())
dp = [[[0.0] * (N + 1) for _ in range(N + 1)] for _ in range(N + 1)]
dic = {}
dic[0] = 0
dic[1] = 0
dic[2] = 0
dic[3] = 0
for a in map(int, input().split(' ')):
	dic[a] += 1
for k in range(dic[3] + 1):
	for j in range(dic[2] + 1 + dic[3] - k):
		for i in range(dic[1] + 1 + dic[2] - j + dic[3] - k):
			if i == 0 and j == 0 and (k == 0):
				continue
			res = 0.0
			if i > 0:
				res += dp[i - 1][j][k] * i
			if j > 0:
				res += dp[i + 1][j - 1][k] * j
			if k > 0:
				res += dp[i][j + 1][k - 1] * k
			res += N
			res *= 1.0 / (i + j + k)
			dp[i][j][k] = res
print(dp[dic[1]][dic[2]][dic[3]])


N = int(input())

def main():
	a = list(map(int, input().split()))
	d = {0: 0, 1: 0, 2: 0, 3: 0}
	for i in a:
		d[i] += 1
	d1 = d[1]
	d123 = d[1] + d[2] + d[3]
	d23 = d[2] + d[3]
	d3 = d[3]
	d2 = d[2]
	l = [[[0] * (d123 + 1) for _ in range(d23 + 1)] for _ in range(d3 + 1)]
	for i in range(d3 + 1):
		for j in range(d23 + 1):
			for k in range(d123 + 1):
				if i + j + k == 0:
					continue
				if i + j + k > d123:
					continue
				if i + j > d23:
					continue
				total = i + j + k
				a = b = c = 0
				if k > 0:
					a = k * l[i][j][k - 1]
				if j > 0:
					b = j * l[i][j - 1][k + 1]
				if i > 0:
					c = i * l[i - 1][j + 1][k]
				l[i][j][k] = (a + b + c + N) / total
	print(l[d3][d2][d1])
main()


from collections import Counter

def main():
	N = int(input())
	a = Counter(map(int, input().split()))
	(a1, a2, a3) = (a.get(1, 0), a.get(2, 0), a.get(3, 0))
	a123 = a1 + a2 + a3 + 1
	u = [[0.0] * (a123 - c2) for c2 in range(a123)]
	v = [[0.0] * (a123 - c2) for c2 in range(a123)]
	t1 = 0.0
	v2 = v[0]
	for c1 in range(1, a123):
		v2[c1] = t1 = N / c1 + t1
	for c2 in range(1, a123):
		v2 = v[c2]
		for (c1, t2) in zip(range(301 - c2), v[c2 - 1][1:]):
			v2[c1] = t1 = (N + c1 * t1 + c2 * t2) / (c1 + c2)
	for c3 in range(1, a3 + 1):
		(u, v) = (v, u)
		v2 = v[0]
		for (c1, t3) in zip(range(a123 - c3), u[1]):
			v2[c1] = t1 = (N + c1 * t1 + c3 * t3) / (c1 + c3)
		for c2 in range(1, a123 - c3):
			v2 = v[c2]
			c23 = c2 + c3
			for (c1, t2, t3) in zip(range(a123 - c3 - c2), v[c2 - 1][1:], u[c2 + 1]):
				v2[c1] = t1 = (N + c1 * t1 + c2 * t2 + c3 * t3) / (c1 + c23)
	print(v[a2][a1])
main()


import sys
sys.setrecursionlimit(10 ** 8)

def ii():
	return int(sys.stdin.readline())

def mi():
	return map(int, sys.stdin.readline().split())

def li():
	return list(map(int, sys.stdin.readline().split()))

def li2(N):
	return [list(map(int, sys.stdin.readline().split())) for i in range(N)]

def dp2(ini, i, j):
	return [[ini] * i for i2 in range(j)]

def dp3(ini, i, j, k):
	return [[[ini] * i for i2 in range(j)] for i3 in range(k)]
N = ii()
N_f = float(N)
A = li()
cnt = [0, 0, 0]
for a in A:
	cnt[a - 1] += 1
dp = dp3(0.0, cnt[2] + 1, cnt[1] + cnt[2] + 1, N + 1)
dp[0][0][0] = 0
for k in range(cnt[2] + 1):
	for j in range(cnt[1] + cnt[2] + 1 - k):
		for i in range(N + 1 - j - k):
			if i + j + k == 0:
				continue
			num = i + j + k
			dp[i][j][k] = N_f
			if i > 0:
				dp[i][j][k] += dp[i - 1][j][k] * i
			if j > 0:
				dp[i][j][k] += dp[i + 1][j - 1][k] * j
			if k > 0:
				dp[i][j][k] += dp[i][j + 1][k - 1] * k
			dp[i][j][k] /= num
print(dp[cnt[0]][cnt[1]][cnt[2]])


n = int(input())
arr = list(map(int, input().split()))
one = two = three = 0
for i in arr:
	if i == 1:
		one += 1
	elif i == 2:
		two += 1
	elif i == 3:
		three += 1
max_one = one + two + three
max_two = two + three
max_three = three
dp = [[[0.0] * (n + 1) for i in range(n + 1)] for j in range(n + 1)]
for k in range(max_three + 1):
	for j in range(max_two + 1 - k):
		for i in range(max_one + 1 - j - k):
			if i + j + k == 0:
				continue
			else:
				dp[i][j][k] = n / (i + j + k)
			if i > 0:
				dp[i][j][k] += dp[i - 1][j][k] * i / (i + j + k)
			if j > 0:
				dp[i][j][k] += dp[i + 1][j - 1][k] * j / (i + j + k)
			if k > 0:
				dp[i][j][k] += dp[i][j + 1][k - 1] * k / (i + j + k)
print(dp[i][j][k])


N = int(input())
A = list(map(int, input().split()))
C = {1: 0, 2: 0, 3: 0}
for i in range(N):
	C[A[i]] += 1
dp = [[[0 for _ in range(N + 1)] for _ in range(N + 1)] for _ in range(N + 1)]
for k in range(1, N + 1):
	dp[0][0][k] = N / k + dp[0][0][k - 1]
for j in range(1, N + 1):
	for k in range(N + 1 - j):
		if k + 1 <= N and k >= 1:
			dp[0][j][k] = N / (j + k) + j / (j + k) * dp[0][j - 1][k + 1] + k / (j + k) * dp[0][j][k - 1]
		elif k == 0:
			dp[0][j][0] = N / j + dp[0][j - 1][1]
for i in range(1, N + 1):
	for j in range(N + 1 - i):
		for k in range(N + 1 - i - j):
			if j - 1 >= 0 and k - 1 >= 0:
				dp[i][j][k] = N / (i + j + k) + i / (i + j + k) * dp[i - 1][j + 1][k] + j / (i + j + k) * dp[i][j - 1][k + 1] + k / (i + j + k) * dp[i][j][k - 1]
			elif j == 0 and k - 1 >= 0:
				dp[i][0][k] = N / (i + k) + i / (i + k) * dp[i - 1][1][k] + k / (i + k) * dp[i][0][k - 1]
			elif j - 1 >= 0 and k == 0:
				dp[i][j][0] = N / (i + j) + i / (i + j) * dp[i - 1][j + 1][0] + j / (i + j) * dp[i][j - 1][1]
			elif j == 0 and k == 0:
				dp[i][j][0] = N / i + dp[i - 1][1][0]
print(dp[C[3]][C[2]][C[1]])


N = int(input())
A = [int(a) for a in input().split()]
I = 0
J = 0
K = 0
for a in A:
	if a == 1:
		J += 1
		K += 1
	elif a == 2:
		K += 1
X = [[[0.0] * (j + 1) for j in range(k + 1)] for k in range(N + 1)]
for k in range(N + 1)[::-1]:
	for j in range(k + 1)[::-1]:
		for i in range(j + 1)[::-1]:
			if i == N:
				X[k][j][i] = 0
			else:
				X[k][j][i] = N / (N - i)
				if i < j:
					X[k][j][i] += X[k][j][i + 1] * (j - i) / (N - i)
				if j < k:
					X[k][j][i] += X[k][j + 1][i] * (k - j) / (N - i)
				if k < N:
					X[k][j][i] += X[k + 1][j][i] * (N - k) / (N - i)
print(X[K][J][I])


import sys
from collections import Counter
input = sys.stdin.readline
N = int(input())
memo = [[[-1] * (N + 1) for _ in range(N + 1)] for _ in range(N + 1)]

def dp(a, b, c):
	if a == b == c == 0:
		return 0
	if memo[a][b][c] != -1:
		return memo[a][b][c]
	res = N
	if a > 0:
		res += a * dp(a - 1, b, c)
	if b > 0:
		res += b * dp(a + 1, b - 1, c)
	if c > 0:
		res += c * dp(a, b + 1, c - 1)
	res /= a + b + c
	memo[a][b][c] = res
	return res

def main():
	A = list(map(int, input().split()))
	count = Counter(A)
	for i in range(1, 4):
		if not i in count:
			count[i] = 0
	(x, y, z) = (count[1], count[2], count[3])
	ans = dp(x, y, z)
	print(ans)
main()


N = int(input())
a = list(map(int, input().split()))
m = d = t = 0
for i in range(len(a)):
	if a[i] == 1:
		m += 1
	elif a[i] == 2:
		d += 1
	else:
		t += 1
D = [[[0] * (N + 1) for i in range(d + t + 1)] for j in range(t + 1)]
su = 0
D[t][d][m] = 1
for i in range(t, -1, -1):
	for j in range(d + t - i, -1, -1):
		for k in range(N - i - j, -1, -1):
			y = D[i][j][k]
			if i + j + k != 0:
				su += y * N / (i + j + k)
			if i >= 1:
				D[i - 1][j + 1][k] += y * i / (i + j + k)
			if j >= 1:
				D[i][j - 1][k + 1] += y * j / (i + j + k)
			if k >= 1:
				D[i][j][k - 1] += y * k / (i + j + k)
print(su)


N = int(input())
A = list(map(float, input().split()))

def solve():
	dp = [[[0] * (N + 1 - i - j) for j in range(N + 1 - i)] for i in range(N + 1)]
	dp[N][0][0] = 0
	for i in range(N - 1, -1, -1):
		for j in range(N - i, -1, -1):
			for k in range(N - i - j, -1, -1):
				dp[i][j][k] = 1 / (1 - i / N)
				if j != 0:
					dp[i][j][k] += dp[i + 1][j - 1][k] * (j / (N - i))
				if k != 0:
					dp[i][j][k] += dp[i][j + 1][k - 1] * (k / (N - i))
				if i + j + k != N:
					dp[i][j][k] += dp[i][j][k + 1] * (1 - (j + k) / (N - i))
	c = {}
	for i in range(1, 3):
		c[i] = A.count(i)
	ans = dp[0][c[1]][c[2]]
	return ans
print(solve())


def main():
	N = int(input())
	a = list(map(int, input().split()))
	(c1, c2, c3) = (0, 0, 0)
	for ai in a:
		if ai == 1:
			c1 += 1
		elif ai == 2:
			c2 += 1
		else:
			c3 += 1
	dp = [[[0] * (c1 + c2 + c3 + 1) for i in range(c2 + c3 + 1)] for j in range(c3 + 1)]
	for i in range(c3 + 1):
		for j in range(c2 + c3 + 1):
			for k in range(c1 + c2 + c3 + 1):
				if i + j + k > N:
					continue
				if i > 0 and j < c2 + c3:
					dp[i][j][k] += i / N * dp[i - 1][j + 1][k]
				if j > 0 and k < c1 + c2 + c3:
					dp[i][j][k] += j / N * dp[i][j - 1][k + 1]
				if k > 0:
					dp[i][j][k] += k / N * dp[i][j][k - 1]
				if i + j + k == 0:
					continue
				dp[i][j][k] += 1
				dp[i][j][k] *= N / (i + j + k)
	print(dp[c3][c2][c1])
main()


import sys
sys.setrecursionlimit(10 ** 8)
stdin = sys.stdin

def ni():
	return int(ns())

def na():
	return list(map(int, stdin.readline().split()))

def naa(N):
	return [na() for _ in range(N)]

def ns():
	return stdin.readline().rstrip()
N = ni()
a_array = na()
cnt = [0] * 3
for a in a_array:
	cnt[a - 1] += 1
dp = [[[0] * (N + 1) for _ in range(N + 1)] for _ in range(N + 1)]
for sushi in range(1, N + 1):
	for k in range(sushi + 1):
		for j in range(0, sushi - k + 1):
			i = sushi - k - j
			if i != 0:
				dp[i][j][k] += dp[i - 1][j][k] * i / sushi
			if j != 0:
				dp[i][j][k] += dp[i + 1][j - 1][k] * j / sushi
			if k != 0:
				dp[i][j][k] += dp[i][j + 1][k - 1] * k / sushi
			dp[i][j][k] += N / sushi
print(dp[cnt[0]][cnt[1]][cnt[2]])


import sys
sys.setrecursionlimit(10 ** 9)
N = int(input())
A = list(map(int, input().split()))
one = A.count(1)
two = A.count(2)
three = A.count(3)
dp = [[[-1] * (N + 1) for _ in range(N + 1)] for _ in range(N + 1)]

def calc(a, b, c):
	if dp[a][b][c] >= 0:
		return dp[a][b][c]
	if a + b + c == 0:
		return 0
	t = N
	if a > 0:
		t += calc(a - 1, b + 1, c) * a
	if b > 0:
		t += calc(a, b - 1, c + 1) * b
	if c > 0:
		t += calc(a, b, c - 1) * c
	t /= a + b + c
	dp[a][b][c] = t
	return t
ans = calc(three, two, one)
print(ans)


from collections import defaultdict
N = int(input())
A = list(map(int, input().split()))
dic = defaultdict(int)
for a in A:
	dic[a] += 1
a = dic[1]
b = dic[2]
c = dic[3]
dp = [[[0 for k in range(N + 1)] for j in range(N + 1)] for i in range(N + 1)]
dp[a + b][a][0] = 1
for i in range(a + b, N + 1):
	for j in range(a, i + 1):
		for k in range(j + 1):
			(p, q, r) = (j - k, i - j, N - i)
			if p:
				dp[i][j][k + 1] += dp[i][j][k] * p / (p + q + r)
			if q:
				dp[i][j + 1][k] += dp[i][j][k] * q / (p + q + r)
			if r:
				dp[i + 1][j][k] += dp[i][j][k] * r / (p + q + r)
ans = 0
for i in range(a + b, N + 1):
	for j in range(a, i + 1):
		for k in range(j + 1):
			(p, q, r) = (j - k, i - j, N - i)
			if p:
				ans += dp[i][j][k] * N / (p + q + r) * p / (p + q + r)
			if q:
				ans += dp[i][j][k] * N / (p + q + r) * q / (p + q + r)
			if r:
				ans += dp[i][j][k] * N / (p + q + r) * r / (p + q + r)
print(ans)


def main():
	N = int(input())
	c = [0] * 4
	for num in map(int, input().split()):
		c[num] += 1
	dp = [[[0] * (N + 2) for _ in range(N + 2)] for _ in range(N + 2)]
	for i3 in range(c[3] + 1):
		for i2 in range(c[2] + c[3] - i3 + 1):
			for i1 in range(c[1] + c[2] + c[3] - i2 - i3 + 1):
				try:
					dp[i1][i2][i3] = (i1 * dp[i1 - 1][i2][i3] + i2 * dp[i1 + 1][i2 - 1][i3] + i3 * dp[i1][i2 + 1][i3 - 1] + N) / (i1 + i2 + i3)
				except IndexError:
					continue
				except ZeroDivisionError:
					continue
	print(dp[c[1]][c[2]][c[3]])
main()


import sys
input = sys.stdin.readline

def main():
	N = int(input())
	A = list(map(int, input().split()))
	dp = [[[0.0 for k in range(N + 1)] for j in range(N + 1)] for i in range(N + 1)]
	one = A.count(1)
	two = A.count(2)
	three = A.count(3)
	for k in range(three + 1):
		for j in range(two + three + 1 - k):
			for i in range(one + two + three + 1 - k - j):
				if i == 0 and j == 0 and (k == 0):
					continue
				ret = N * 1.0
				if i > 0:
					ret += dp[i - 1][j][k] * i
				if j > 0:
					ret += dp[i + 1][j - 1][k] * j
				if k > 0:
					ret += dp[i][j + 1][k - 1] * k
				dp[i][j][k] = ret / (i + j + k)
	print(dp[one][two][three])
main()


import collections
n = int(input())
lst = list(map(int, input().split()))
c = collections.Counter(lst)
(p, q, r) = (c[1], c[2], c[3])
dp = [[[0] * (n + 1) for _ in range(n + 1)] for _ in range(n + 1)]
for k in range(0, r + 1):
	for j in range(0, q + r + 1 - k):
		for i in range(0, p + q + r + 1 - k - j):
			if i == 0 and j == 0 and (k == 0):
				continue
			E = n
			if i > 0:
				E += dp[i - 1][j][k] * i
			if j > 0:
				E += dp[i + 1][j - 1][k] * j
			if k > 0:
				E += dp[i][j + 1][k - 1] * k
			dp[i][j][k] = E / (i + j + k)
print(dp[p][q][r])


def main():
	import sys
	input = sys.stdin.readline
	n = int(input())
	l1 = l2 = l3 = 0
	for i in map(int, input().split()):
		if i == 1:
			l1 += 1
		elif i == 2:
			l2 += 1
		else:
			l3 += 1
	a = l2 + l3
	dp = [[[0.0] * (l3 + 1) for i in range(a + 1)] for j in range(n + 1)]
	for i in range(1, n + 1):
		for j in range(min(i, a) + 1):
			for k in range(min(j, l3) + 1):
				s = i - j
				t = j - k
				count = n / (s + t + k)
				if s > 0:
					count += dp[s - 1][t][k] * (s / (s + t + k))
				if t > 0:
					count += dp[s + 1][t - 1][k] * (t / (s + t + k))
				if k > 0:
					count += dp[s][t + 1][k - 1] * (k / (s + t + k))
				dp[s][t][k] = count
	print(dp[l1][l2][l3])
main()


from collections import defaultdict
N = int(input())
A = list(map(int, input().split()))
sushi = [0, 0, 0]
for a in A:
	sushi[a - 1] += 1
dp = [[[0.0 for _ in range(N + 1)] for _ in range(N + 1)] for _ in range(N + 1)]
for i in range(N + 1):
	for j in range(N + 1):
		for k in range(N + 1):
			if i + j + k > N or i + j + k == 0:
				continue
			if i > 0:
				dp[i][j][k] += i * dp[i - 1][j + 1][k]
			if j > 0:
				dp[i][j][k] += j * dp[i][j - 1][k + 1]
			if k > 0:
				dp[i][j][k] += k * dp[i][j][k - 1]
			dp[i][j][k] += N
			dp[i][j][k] /= i + j + k
print(dp[sushi[2]][sushi[1]][sushi[0]])


from collections import Counter
n = int(input())
a = list(map(int, input().split()))
c = Counter(a)
(a, b, c) = (c[1], c[2], c[3])
DP = [[[0] * (n + 2) for i in range(n + 2)] for j in range(n + 2)]
for i in range(c + 1):
	for j in range(n - a - i + 1):
		for k in range(n - i - j + 1):
			if i + j + k:
				DP[i][j][k] = (i * DP[i - 1][j + 1][k] + j * DP[i][j - 1][k + 1] + k * DP[i][j][k - 1] + n) / (i + j + k)
print(DP[c][b][a])