Buggy python submission (verdict: Time Limit Exceeded):
import sys
import math
from decimal import Decimal, ROUND_HALF_UP, ROUND_HALF_EVEN
from collections import deque
from bisect import bisect_left
from itertools import product
def I(): 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)]
#文字列を一文字ずつ数字に変換、'5678'を[5,6,7,8]とできる
def LSI(): return list(map(int, list(sys.stdin.readline().rstrip())))
def LSI2(N): return [list(map(int, list(sys.stdin.readline().rstrip()))) for i in range(N)]
#文字列として取得
def ST(): return sys.stdin.readline().rstrip()
def LST(): return sys.stdin.readline().rstrip().split()
def LST2(N): return [sys.stdin.readline().rstrip().split() for i in range(N)]
def FILL(i,h): return [i for j in range(h)]
def FILL2(i,h,w): return [FILL(i,w) for j in range(h)]
def FILL3(i,h,w,d): return [FILL2(i,w,d) for j in range(h)]
def FILL4(i,h,w,d,d2): return [FILL3(i,w,d,d2) for j in range(h)]
def sisha(num,digit): return Decimal(str(num)).quantize(Decimal(digit),rounding=ROUND_HALF_UP)
#'0.01'や'1E1'などで指定、整数に戻すならintをかます
MOD = 1000000007
INF = float("inf")
sys.setrecursionlimit(10**6+10)

N = I()
A = LI()
one = 0
two = 0
three = 0
for a in A:
    if a==1:
        one += 1
    elif a==2:
        two += 1
    elif a==3:
        three += 1

dp = FILL3(0,N+2,N+2,N+2)
dp[0][0][0] = 0
for  k in range(0,three+1):
    for j in range(0,two+three-k+1):
        for i in range(0,one+two+three-k-j+1):
            if i==j==k==0:
                continue
            zero = N-i-j-k
            p_0 = zero/N
            p_1 = i/N
            p_2 = j/N
            p_3 = k/N
            ret = 1
            if i>0:
                ret += p_1*dp[i-1][j][k]
            if j>0:
                ret += p_2*dp[i+1][j-1][k]
            if k>0:
                ret += p_3*dp[i][j+1][k-1]
            ret /= 1-p_0
            dp[i][j][k] = ret

print(dp[one][two][three])


Fixed submission:
import sys
import math
from decimal import Decimal, ROUND_HALF_UP, ROUND_HALF_EVEN
from collections import deque
from bisect import bisect_left
from itertools import product
def I(): 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)]
#文字列を一文字ずつ数字に変換、'5678'を[5,6,7,8]とできる
def LSI(): return list(map(int, list(sys.stdin.readline().rstrip())))
def LSI2(N): return [list(map(int, list(sys.stdin.readline().rstrip()))) for i in range(N)]
#文字列として取得
def ST(): return sys.stdin.readline().rstrip()
def LST(): return sys.stdin.readline().rstrip().split()
def LST2(N): return [sys.stdin.readline().rstrip().split() for i in range(N)]
def FILL(i,h): return [i for j in range(h)]
def FILL2(i,h,w): return [FILL(i,w) for j in range(h)]
def FILL3(i,h,w,d): return [FILL2(i,w,d) for j in range(h)]
def FILL4(i,h,w,d,d2): return [FILL3(i,w,d,d2) for j in range(h)]
def sisha(num,digit): return Decimal(str(num)).quantize(Decimal(digit),rounding=ROUND_HALF_UP)
#'0.01'や'1E1'などで指定、整数に戻すならintをかます
MOD = 1000000007
INF = float("inf")
sys.setrecursionlimit(10**6+10)

N = I()
A = LI()
one = 0
two = 0
three = 0
for a in A:
    if a==1:
        one += 1
    elif a==2:
        two += 1
    elif a==3:
        three += 1

dp = FILL3(0.0,N+2,N+2,N+2)
dp[0][0][0] = 0.0
for  k in range(0,three+1):
    for j in range(0,two+three-k+1):
        for i in range(0,one+two+three-k-j+1):
            if i==j==k==0:
                continue
            zero = N-i-j-k
            p_0 = zero/N
            p_1 = i/N
            p_2 = j/N
            p_3 = k/N
            ret = 1.0
            if i>0:
                ret += p_1*dp[i-1][j][k]
            if j>0:
                ret += p_2*dp[i+1][j-1][k]
            if k>0:
                ret += p_3*dp[i][j+1][k-1]
            ret /= 1-p_0
            dp[i][j][k] = ret

print(dp[one][two][three])

Buggy python submission (verdict: Time Limit Exceeded):
import sys
import math
from decimal import Decimal, ROUND_HALF_UP, ROUND_HALF_EVEN
from collections import deque
from bisect import bisect_left
from itertools import product
def I(): 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)]
#文字列を一文字ずつ数字に変換、'5678'を[5,6,7,8]とできる
def LSI(): return list(map(int, list(sys.stdin.readline().rstrip())))
def LSI2(N): return [list(map(int, list(sys.stdin.readline().rstrip()))) for i in range(N)]
#文字列として取得
def ST(): return sys.stdin.readline().rstrip()
def LST(): return sys.stdin.readline().rstrip().split()
def LST2(N): return [sys.stdin.readline().rstrip().split() for i in range(N)]
def FILL(i,h): return [i for j in range(h)]
def FILL2(i,h,w): return [FILL(i,w) for j in range(h)]
def FILL3(i,h,w,d): return [FILL2(i,w,d) for j in range(h)]
def FILL4(i,h,w,d,d2): return [FILL3(i,w,d,d2) for j in range(h)]
def sisha(num,digit): return Decimal(str(num)).quantize(Decimal(digit),rounding=ROUND_HALF_UP)
#'0.01'や'1E1'などで指定、整数に戻すならintをかます
MOD = 1000000007
INF = float("inf")
sys.setrecursionlimit(10**6+10)

N = I()
A = LI()
one = 0
two = 0
three = 0
for a in A:
    if a==1:
        one += 1
    elif a==2:
        two += 1
    elif a==3:
        three += 1

dp = FILL3(0.0,N+2,N+2,N+2)
dp[0][0][0] = 0
for  k in range(0,N+1):
    for j in range(0,N+1):
        for i in range(0,N+1):
            if i==j==k==0:
                continue
            zero = N-i-j-k
            p_0 = zero/N
            p_1 = i/N
            p_2 = j/N
            p_3 = k/N
            ret = 1.0
            if i>0:
                ret += p_1*dp[i-1][j][k]
            if j>0:
                ret += p_2*dp[i+1][j-1][k]
            if k>0:
                ret += p_3*dp[i][j+1][k-1]
            ret /= 1-p_0
            dp[i][j][k] = ret

print(dp[one][two][three])


Fixed submission:
import sys
import math
from decimal import Decimal, ROUND_HALF_UP, ROUND_HALF_EVEN
from collections import deque
from bisect import bisect_left
from itertools import product
def I(): 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)]
#文字列を一文字ずつ数字に変換、'5678'を[5,6,7,8]とできる
def LSI(): return list(map(int, list(sys.stdin.readline().rstrip())))
def LSI2(N): return [list(map(int, list(sys.stdin.readline().rstrip()))) for i in range(N)]
#文字列として取得
def ST(): return sys.stdin.readline().rstrip()
def LST(): return sys.stdin.readline().rstrip().split()
def LST2(N): return [sys.stdin.readline().rstrip().split() for i in range(N)]
def FILL(i,h): return [i for j in range(h)]
def FILL2(i,h,w): return [FILL(i,w) for j in range(h)]
def FILL3(i,h,w,d): return [FILL2(i,w,d) for j in range(h)]
def FILL4(i,h,w,d,d2): return [FILL3(i,w,d,d2) for j in range(h)]
def sisha(num,digit): return Decimal(str(num)).quantize(Decimal(digit),rounding=ROUND_HALF_UP)
#'0.01'や'1E1'などで指定、整数に戻すならintをかます
MOD = 1000000007
INF = float("inf")
sys.setrecursionlimit(10**6+10)

N = I()
A = LI()
one = 0
two = 0
three = 0
for a in A:
    if a==1:
        one += 1
    elif a==2:
        two += 1
    elif a==3:
        three += 1

dp = FILL3(0.0,N+2,N+2,N+2)
dp[0][0][0] = 0.0
for  k in range(0,three+1):
    for j in range(0,two+three-k+1):
        for i in range(0,one+two+three-k-j+1):
            if i==j==k==0:
                continue
            zero = N-i-j-k
            p_0 = zero/N
            p_1 = i/N
            p_2 = j/N
            p_3 = k/N
            ret = 1.0
            if i>0:
                ret += p_1*dp[i-1][j][k]
            if j>0:
                ret += p_2*dp[i+1][j-1][k]
            if k>0:
                ret += p_3*dp[i][j+1][k-1]
            ret /= 1-p_0
            dp[i][j][k] = ret

print(dp[one][two][three])

Buggy python submission (verdict: Time Limit Exceeded):
import sys
import math
from decimal import Decimal, ROUND_HALF_UP, ROUND_HALF_EVEN
from collections import deque
from bisect import bisect_left
from itertools import product
def I(): 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)]
#文字列を一文字ずつ数字に変換、'5678'を[5,6,7,8]とできる
def LSI(): return list(map(int, list(sys.stdin.readline().rstrip())))
def LSI2(N): return [list(map(int, list(sys.stdin.readline().rstrip()))) for i in range(N)]
#文字列として取得
def ST(): return sys.stdin.readline().rstrip()
def LST(): return sys.stdin.readline().rstrip().split()
def LST2(N): return [sys.stdin.readline().rstrip().split() for i in range(N)]
def FILL(i,h): return [i for j in range(h)]
def FILL2(i,h,w): return [FILL(i,w) for j in range(h)]
def FILL3(i,h,w,d): return [FILL2(i,w,d) for j in range(h)]
def FILL4(i,h,w,d,d2): return [FILL3(i,w,d,d2) for j in range(h)]
def sisha(num,digit): return Decimal(str(num)).quantize(Decimal(digit),rounding=ROUND_HALF_UP)
#'0.01'や'1E1'などで指定、整数に戻すならintをかます
MOD = 1000000007
INF = float("inf")
sys.setrecursionlimit(10**6+10)

N = I()
A = LI()
one = 0
two = 0
three = 0
for a in A:
    if a==1:
        one += 1
    elif a==2:
        two += 1
    elif a==3:
        three += 1

dp = FILL3(0,N+2,N+2,N+2)
dp[0][0][0] = 0
for  k in range(0,N+1):
    for j in range(0,N+1):
        for i in range(0,N+1):
            if i==j==k==0:
                continue
            zero = N-i-j-k
            p_0 = zero/N
            p_1 = i/N
            p_2 = j/N
            p_3 = k/N
            ret = 1
            if i>0:
                ret += p_1*dp[i-1][j][k]
            if j>0:
                ret += p_2*dp[i+1][j-1][k]
            if k>0:
                ret += p_3*dp[i][j+1][k-1]
            ret /= 1-p_0
            dp[i][j][k] = ret

print(dp[one][two][three])


Fixed submission:
import sys
import math
from decimal import Decimal, ROUND_HALF_UP, ROUND_HALF_EVEN
from collections import deque
from bisect import bisect_left
from itertools import product
def I(): 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)]
#文字列を一文字ずつ数字に変換、'5678'を[5,6,7,8]とできる
def LSI(): return list(map(int, list(sys.stdin.readline().rstrip())))
def LSI2(N): return [list(map(int, list(sys.stdin.readline().rstrip()))) for i in range(N)]
#文字列として取得
def ST(): return sys.stdin.readline().rstrip()
def LST(): return sys.stdin.readline().rstrip().split()
def LST2(N): return [sys.stdin.readline().rstrip().split() for i in range(N)]
def FILL(i,h): return [i for j in range(h)]
def FILL2(i,h,w): return [FILL(i,w) for j in range(h)]
def FILL3(i,h,w,d): return [FILL2(i,w,d) for j in range(h)]
def FILL4(i,h,w,d,d2): return [FILL3(i,w,d,d2) for j in range(h)]
def sisha(num,digit): return Decimal(str(num)).quantize(Decimal(digit),rounding=ROUND_HALF_UP)
#'0.01'や'1E1'などで指定、整数に戻すならintをかます
MOD = 1000000007
INF = float("inf")
sys.setrecursionlimit(10**6+10)

N = I()
A = LI()
one = 0
two = 0
three = 0
for a in A:
    if a==1:
        one += 1
    elif a==2:
        two += 1
    elif a==3:
        three += 1

dp = FILL3(0.0,N+2,N+2,N+2)
dp[0][0][0] = 0.0
for  k in range(0,three+1):
    for j in range(0,two+three-k+1):
        for i in range(0,one+two+three-k-j+1):
            if i==j==k==0:
                continue
            zero = N-i-j-k
            p_0 = zero/N
            p_1 = i/N
            p_2 = j/N
            p_3 = k/N
            ret = 1.0
            if i>0:
                ret += p_1*dp[i-1][j][k]
            if j>0:
                ret += p_2*dp[i+1][j-1][k]
            if k>0:
                ret += p_3*dp[i][j+1][k-1]
            ret /= 1-p_0
            dp[i][j][k] = ret

print(dp[one][two][three])

Buggy python submission (verdict: Time Limit Exceeded):
import sys
import math
from decimal import Decimal, ROUND_HALF_UP, ROUND_HALF_EVEN
from collections import deque
from bisect import bisect_left
from itertools import product
def I(): 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)]
#文字列を一文字ずつ数字に変換、'5678'を[5,6,7,8]とできる
def LSI(): return list(map(int, list(sys.stdin.readline().rstrip())))
def LSI2(N): return [list(map(int, list(sys.stdin.readline().rstrip()))) for i in range(N)]
#文字列として取得
def ST(): return sys.stdin.readline().rstrip()
def LST(): return sys.stdin.readline().rstrip().split()
def LST2(N): return [sys.stdin.readline().rstrip().split() for i in range(N)]
def FILL(i,h): return [i for j in range(h)]
def FILL2(i,h,w): return [FILL(i,w) for j in range(h)]
def FILL3(i,h,w,d): return [FILL2(i,w,d) for j in range(h)]
def FILL4(i,h,w,d,d2): return [FILL3(i,w,d,d2) for j in range(h)]
def sisha(num,digit): return Decimal(str(num)).quantize(Decimal(digit),rounding=ROUND_HALF_UP)
#'0.01'や'1E1'などで指定、整数に戻すならintをかます
MOD = 1000000007
INF = float("inf")
sys.setrecursionlimit(10**6+10)

N = I()
A = LI()
one = 0
two = 0
three = 0
for a in A:
    if a==1:
        one += 1
    elif a==2:
        two += 1
    elif a==3:
        three += 1

dp = FILL3(-1.0,N+1,N+1,N+1)
dp[0][0][0] = 0
def rec(i,j,k):
    if i<0 or j<0 or k<0:
        return 0
    if dp[i][j][k] != -1.0:
        return dp[i][j][k]
    zero = N-i-j-k
    p_0 = zero/N
    p_1 = i/N
    p_2 = j/N
    p_3 = k/N
    ret = p_1*rec(i-1,j,k) + p_2*rec(i+1,j-1,k) + p_3*rec(i,j+1,k-1) + 1
    ret /= 1-p_0
    dp[i][j][k] = ret
    return ret

print(rec(one,two,three))


Fixed submission:
import sys
import math
from decimal import Decimal, ROUND_HALF_UP, ROUND_HALF_EVEN
from collections import deque
from bisect import bisect_left
from itertools import product
def I(): 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)]
#文字列を一文字ずつ数字に変換、'5678'を[5,6,7,8]とできる
def LSI(): return list(map(int, list(sys.stdin.readline().rstrip())))
def LSI2(N): return [list(map(int, list(sys.stdin.readline().rstrip()))) for i in range(N)]
#文字列として取得
def ST(): return sys.stdin.readline().rstrip()
def LST(): return sys.stdin.readline().rstrip().split()
def LST2(N): return [sys.stdin.readline().rstrip().split() for i in range(N)]
def FILL(i,h): return [i for j in range(h)]
def FILL2(i,h,w): return [FILL(i,w) for j in range(h)]
def FILL3(i,h,w,d): return [FILL2(i,w,d) for j in range(h)]
def FILL4(i,h,w,d,d2): return [FILL3(i,w,d,d2) for j in range(h)]
def sisha(num,digit): return Decimal(str(num)).quantize(Decimal(digit),rounding=ROUND_HALF_UP)
#'0.01'や'1E1'などで指定、整数に戻すならintをかます
MOD = 1000000007
INF = float("inf")
sys.setrecursionlimit(10**6+10)

N = I()
A = LI()
one = 0
two = 0
three = 0
for a in A:
    if a==1:
        one += 1
    elif a==2:
        two += 1
    elif a==3:
        three += 1

dp = FILL3(0.0,N+2,N+2,N+2)
dp[0][0][0] = 0.0
for  k in range(0,three+1):
    for j in range(0,two+three-k+1):
        for i in range(0,one+two+three-k-j+1):
            if i==j==k==0:
                continue
            zero = N-i-j-k
            p_0 = zero/N
            p_1 = i/N
            p_2 = j/N
            p_3 = k/N
            ret = 1.0
            if i>0:
                ret += p_1*dp[i-1][j][k]
            if j>0:
                ret += p_2*dp[i+1][j-1][k]
            if k>0:
                ret += p_3*dp[i][j+1][k-1]
            ret /= 1-p_0
            dp[i][j][k] = ret

print(dp[one][two][three])

Buggy python submission (verdict: Time Limit Exceeded):
import sys
import math
from decimal import Decimal, ROUND_HALF_UP, ROUND_HALF_EVEN
from collections import deque
from bisect import bisect_left
from itertools import product
def I(): 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)]
#文字列を一文字ずつ数字に変換、'5678'を[5,6,7,8]とできる
def LSI(): return list(map(int, list(sys.stdin.readline().rstrip())))
def LSI2(N): return [list(map(int, list(sys.stdin.readline().rstrip()))) for i in range(N)]
#文字列として取得
def ST(): return sys.stdin.readline().rstrip()
def LST(): return sys.stdin.readline().rstrip().split()
def LST2(N): return [sys.stdin.readline().rstrip().split() for i in range(N)]
def FILL(i,h): return [i for j in range(h)]
def FILL2(i,h,w): return [FILL(i,w) for j in range(h)]
def FILL3(i,h,w,d): return [FILL2(i,w,d) for j in range(h)]
def FILL4(i,h,w,d,d2): return [FILL3(i,w,d,d2) for j in range(h)]
def sisha(num,digit): return Decimal(str(num)).quantize(Decimal(digit),rounding=ROUND_HALF_UP)
#'0.01'や'1E1'などで指定、整数に戻すならintをかます
MOD = 1000000007
INF = float("inf")
sys.setrecursionlimit(10**6+10)

N = I()
A = LI()
one = 0
two = 0
three = 0
for a in A:
    if a==1:
        one += 1
    elif a==2:
        two += 1
    elif a==3:
        three += 1

dp = FILL3(-1,N+1,N+1,N+1)
dp[0][0][0] = 0
def rec(i,j,k):
    if i<0 or j<0 or k<0:
        return 0
    if dp[i][j][k] != -1:
        return dp[i][j][k]
    zero = N-i-j-k
    p_0 = zero/N
    p_1 = i/N
    p_2 = j/N
    p_3 = k/N
    ret = p_1*rec(i-1,j,k) + p_2*rec(i+1,j-1,k) + p_3*rec(i,j+1,k-1) + 1
    ret /= 1-p_0
    dp[i][j][k] = ret
    return ret

print(rec(one,two,three))


Fixed submission:
import sys
import math
from decimal import Decimal, ROUND_HALF_UP, ROUND_HALF_EVEN
from collections import deque
from bisect import bisect_left
from itertools import product
def I(): 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)]
#文字列を一文字ずつ数字に変換、'5678'を[5,6,7,8]とできる
def LSI(): return list(map(int, list(sys.stdin.readline().rstrip())))
def LSI2(N): return [list(map(int, list(sys.stdin.readline().rstrip()))) for i in range(N)]
#文字列として取得
def ST(): return sys.stdin.readline().rstrip()
def LST(): return sys.stdin.readline().rstrip().split()
def LST2(N): return [sys.stdin.readline().rstrip().split() for i in range(N)]
def FILL(i,h): return [i for j in range(h)]
def FILL2(i,h,w): return [FILL(i,w) for j in range(h)]
def FILL3(i,h,w,d): return [FILL2(i,w,d) for j in range(h)]
def FILL4(i,h,w,d,d2): return [FILL3(i,w,d,d2) for j in range(h)]
def sisha(num,digit): return Decimal(str(num)).quantize(Decimal(digit),rounding=ROUND_HALF_UP)
#'0.01'や'1E1'などで指定、整数に戻すならintをかます
MOD = 1000000007
INF = float("inf")
sys.setrecursionlimit(10**6+10)

N = I()
A = LI()
one = 0
two = 0
three = 0
for a in A:
    if a==1:
        one += 1
    elif a==2:
        two += 1
    elif a==3:
        three += 1

dp = FILL3(0.0,N+2,N+2,N+2)
dp[0][0][0] = 0.0
for  k in range(0,three+1):
    for j in range(0,two+three-k+1):
        for i in range(0,one+two+three-k-j+1):
            if i==j==k==0:
                continue
            zero = N-i-j-k
            p_0 = zero/N
            p_1 = i/N
            p_2 = j/N
            p_3 = k/N
            ret = 1.0
            if i>0:
                ret += p_1*dp[i-1][j][k]
            if j>0:
                ret += p_2*dp[i+1][j-1][k]
            if k>0:
                ret += p_3*dp[i][j+1][k-1]
            ret /= 1-p_0
            dp[i][j][k] = ret

print(dp[one][two][three])

Buggy python submission (verdict: Time Limit Exceeded):
import sys
import math
from decimal import Decimal, ROUND_HALF_UP, ROUND_HALF_EVEN
from collections import deque
from bisect import bisect_left
from itertools import product
def I(): 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)]
#文字列を一文字ずつ数字に変換、'5678'を[5,6,7,8]とできる
def LSI(): return list(map(int, list(sys.stdin.readline().rstrip())))
def LSI2(N): return [list(map(int, list(sys.stdin.readline().rstrip()))) for i in range(N)]
#文字列として取得
def ST(): return sys.stdin.readline().rstrip()
def LST(): return sys.stdin.readline().rstrip().split()
def LST2(N): return [sys.stdin.readline().rstrip().split() for i in range(N)]
def FILL(i,h): return [i for j in range(h)]
def FILL2(i,h,w): return [FILL(i,w) for j in range(h)]
def FILL3(i,h,w,d): return [FILL2(i,w,d) for j in range(h)]
def FILL4(i,h,w,d,d2): return [FILL3(i,w,d,d2) for j in range(h)]
def sisha(num,digit): return Decimal(str(num)).quantize(Decimal(digit),rounding=ROUND_HALF_UP)
#'0.01'や'1E1'などで指定、整数に戻すならintをかます
MOD = 1000000007
INF = float("inf")
sys.setrecursionlimit(10**6+10)

N = I()
A = LI()
one = 0
two = 0
three = 0
for a in A:
    if a==1:
        one += 1
    elif a==2:
        two += 1
    elif a==3:
        three += 1

dp = FILL3(-1,N+1,N+1,N+1)
dp[0][0][0] = 0
def rec(i,j,k):
    if i<0 or j<0 or k<0:
        return 0
    if dp[i][j][k] != -1:
        return dp[i][j][k]
    zero = N-i-j-k
    p_0 = zero/N
    p_1 = i/N
    p_2 = j/N
    p_3 = k/N
    ret = p_1*rec(i-1,j,k) + p_2*rec(i+1,j-1,k) + p_3*rec(i,j+1,k-1) + 1
    ret /= 1-p_0
    dp[i][j][k] = ret
    return ret

print(rec(one,two,three))


Fixed submission:
import sys
import math
from decimal import Decimal, ROUND_HALF_UP, ROUND_HALF_EVEN
from collections import deque
from bisect import bisect_left
from itertools import product
def I(): 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)]
#文字列を一文字ずつ数字に変換、'5678'を[5,6,7,8]とできる
def LSI(): return list(map(int, list(sys.stdin.readline().rstrip())))
def LSI2(N): return [list(map(int, list(sys.stdin.readline().rstrip()))) for i in range(N)]
#文字列として取得
def ST(): return sys.stdin.readline().rstrip()
def LST(): return sys.stdin.readline().rstrip().split()
def LST2(N): return [sys.stdin.readline().rstrip().split() for i in range(N)]
def FILL(i,h): return [i for j in range(h)]
def FILL2(i,h,w): return [FILL(i,w) for j in range(h)]
def FILL3(i,h,w,d): return [FILL2(i,w,d) for j in range(h)]
def FILL4(i,h,w,d,d2): return [FILL3(i,w,d,d2) for j in range(h)]
def sisha(num,digit): return Decimal(str(num)).quantize(Decimal(digit),rounding=ROUND_HALF_UP)
#'0.01'や'1E1'などで指定、整数に戻すならintをかます
MOD = 1000000007
INF = float("inf")
sys.setrecursionlimit(10**6+10)

N = I()
A = LI()
one = 0
two = 0
three = 0
for a in A:
    if a==1:
        one += 1
    elif a==2:
        two += 1
    elif a==3:
        three += 1

dp = FILL3(0.0,N+2,N+2,N+2)
dp[0][0][0] = 0.0
for  k in range(0,three+1):
    for j in range(0,two+three-k+1):
        for i in range(0,one+two+three-k-j+1):
            if i==j==k==0:
                continue
            zero = N-i-j-k
            p_0 = zero/N
            p_1 = i/N
            p_2 = j/N
            p_3 = k/N
            ret = 1.0
            if i>0:
                ret += p_1*dp[i-1][j][k]
            if j>0:
                ret += p_2*dp[i+1][j-1][k]
            if k>0:
                ret += p_3*dp[i][j+1][k-1]
            ret /= 1-p_0
            dp[i][j][k] = ret

print(dp[one][two][three])

Buggy python submission (verdict: Time Limit Exceeded):
import sys
import math
from decimal import Decimal, ROUND_HALF_UP, ROUND_HALF_EVEN
from collections import deque
from bisect import bisect_left
from itertools import product
def I(): 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)]
#文字列を一文字ずつ数字に変換、'5678'を[5,6,7,8]とできる
def LSI(): return list(map(int, list(sys.stdin.readline().rstrip())))
def LSI2(N): return [list(map(int, list(sys.stdin.readline().rstrip()))) for i in range(N)]
#文字列として取得
def ST(): return sys.stdin.readline().rstrip()
def LST(): return sys.stdin.readline().rstrip().split()
def LST2(N): return [sys.stdin.readline().rstrip().split() for i in range(N)]
def FILL(i,h): return [i for j in range(h)]
def FILL2(i,h,w): return [FILL(i,w) for j in range(h)]
def FILL3(i,h,w,d): return [FILL2(i,w,d) for j in range(h)]
def FILL4(i,h,w,d,d2): return [FILL3(i,w,d,d2) for j in range(h)]
def sisha(num,digit): return Decimal(str(num)).quantize(Decimal(digit),rounding=ROUND_HALF_UP)
#'0.01'や'1E1'などで指定、整数に戻すならintをかます
MOD = 1000000007
INF = float("inf")
sys.setrecursionlimit(10**6+10)

N = I()
A = LI()
one = 0
two = 0
three = 0
for a in A:
    if a==1:
        one += 1
    elif a==2:
        two += 1
    elif a==3:
        three += 1

dp = FILL3(-1,N+1,N+1,N+1)
def rec(i,j,k):
    if i<0 or j<0 or k<0 or i+j+k==0:
        return 0
    if dp[i][j][k] != -1:
        return dp[i][j][k]
    zero = N-i-j-k
    p_0 = zero/N
    p_1 = i/N
    p_2 = j/N
    p_3 = k/N
    ret = p_1*rec(i-1,j,k) + p_2*rec(i+1,j-1,k) + p_3*rec(i,j+1,k-1) + 1
    ret /= 1-p_0
    dp[i][j][k] = ret
    return ret

print(rec(one,two,three))


Fixed submission:
import sys
import math
from decimal import Decimal, ROUND_HALF_UP, ROUND_HALF_EVEN
from collections import deque
from bisect import bisect_left
from itertools import product
def I(): 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)]
#文字列を一文字ずつ数字に変換、'5678'を[5,6,7,8]とできる
def LSI(): return list(map(int, list(sys.stdin.readline().rstrip())))
def LSI2(N): return [list(map(int, list(sys.stdin.readline().rstrip()))) for i in range(N)]
#文字列として取得
def ST(): return sys.stdin.readline().rstrip()
def LST(): return sys.stdin.readline().rstrip().split()
def LST2(N): return [sys.stdin.readline().rstrip().split() for i in range(N)]
def FILL(i,h): return [i for j in range(h)]
def FILL2(i,h,w): return [FILL(i,w) for j in range(h)]
def FILL3(i,h,w,d): return [FILL2(i,w,d) for j in range(h)]
def FILL4(i,h,w,d,d2): return [FILL3(i,w,d,d2) for j in range(h)]
def sisha(num,digit): return Decimal(str(num)).quantize(Decimal(digit),rounding=ROUND_HALF_UP)
#'0.01'や'1E1'などで指定、整数に戻すならintをかます
MOD = 1000000007
INF = float("inf")
sys.setrecursionlimit(10**6+10)

N = I()
A = LI()
one = 0
two = 0
three = 0
for a in A:
    if a==1:
        one += 1
    elif a==2:
        two += 1
    elif a==3:
        three += 1

dp = FILL3(0.0,N+2,N+2,N+2)
dp[0][0][0] = 0.0
for  k in range(0,three+1):
    for j in range(0,two+three-k+1):
        for i in range(0,one+two+three-k-j+1):
            if i==j==k==0:
                continue
            zero = N-i-j-k
            p_0 = zero/N
            p_1 = i/N
            p_2 = j/N
            p_3 = k/N
            ret = 1.0
            if i>0:
                ret += p_1*dp[i-1][j][k]
            if j>0:
                ret += p_2*dp[i+1][j-1][k]
            if k>0:
                ret += p_3*dp[i][j+1][k-1]
            ret /= 1-p_0
            dp[i][j][k] = ret

print(dp[one][two][three])