Buggy python submission (verdict: Time Limit Exceeded):
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]*(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()

Fixed submission:
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()

Buggy python submission (verdict: Time Limit Exceeded):
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]*(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=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()

Fixed submission:
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()

Buggy python submission (verdict: Time Limit Exceeded):
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]*(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(n+1-k-j):
            if i==0 and j==0 and 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[A][B][C])

Fixed submission:
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()

Buggy python submission (verdict: Time Limit Exceeded):
n=int(input())
a=list(map(int,input().split()))

A=a.count(1)
B=a.count(2)
C=a.count(3)

dp=[[[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(n+1-k-j):
            if i==0 and j==0 and 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[A][B][C])


Fixed submission:
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()

Buggy python submission (verdict: Time Limit Exceeded):
import sys
sys.setrecursionlimit(int(1e7))
n=int(input())
a=list(map(int,input().split()))

A=a.count(1)
B=a.count(2)
C=a.count(3)

d=A+B+C
memo=[[[-1]*(d+1) for _ in range(d+1)] for _ in range(d+1)]
memo[0][0][0]=0
def c(i,j,k):
        if memo[i][j][k]!=-1:
            return memo[i][j][k]
        else:
            memo[i][j][k]=n/(i+j+k)
            if 1<=i<=d:
                memo[i][j][k]+=c(i-1,j,k)*i/(i+j+k)
            if 0<=i<=d-1 and 1<=j<=d:
                memo[i][j][k]+=c(i+1,j-1,k)*j/(i+j+k)
            if 0<=j<=d-1 and 1<=k<=d:
                memo[i][j][k]+=c(i,j+1,k-1)*k/(i+j+k)
            return memo[i][j][k]

print(c(A,B,C))

Fixed submission:
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()

Buggy python submission (verdict: Time Limit Exceeded):
import sys
sys.setrecursionlimit(int(1e7))
n=int(input())
a=list(map(int,input().split()))

A=a.count(1)
B=a.count(2)
C=a.count(3)

memo=[[[-1]*(301) for _ in range(301)] for _ in range(301)]
memo[0][0][0]=0
def c(i,j,k):
        if memo[i][j][k]!=-1:
            return memo[i][j][k]
        else:
            memo[i][j][k]=n/(i+j+k)
            if 1<=i<=300:
                memo[i][j][k]+=c(i-1,j,k)*i/(i+j+k)
            if 0<=i<=299 and 1<=j<=300:
                memo[i][j][k]+=c(i+1,j-1,k)*j/(i+j+k)
            if 0<=j<=299 and 1<=k<=300:
                memo[i][j][k]+=c(i,j+1,k-1)*k/(i+j+k)
            return memo[i][j][k]

print(c(A,B,C))

Fixed submission:
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()

Buggy python submission (verdict: Time Limit Exceeded):
import sys
sys.setrecursionlimit(int(1e7))
n=int(input())
a=list(map(int,input().split()))

A=a.count(1)
B=a.count(2)
C=a.count(3)

memo=[[[-1]*(301) for _ in range(301)] for _ in range(301)]
memo[0][0][0]=0
def c(i,j,k):
        if memo[i][j][k]!=-1:
            return memo[i][j][k]
        else:
            memo[i][j][k]=n/(i+j+k)
            if 0<=i-1<=300:
                memo[i][j][k]+=c(i-1,j,k)*i/(i+j+k)
            if 0<=i+1<=300 and 0<=j-1<=300:
                memo[i][j][k]+=c(i+1,j-1,k)*j/(i+j+k)
            if 0<=j+1<=300 and 0<=k-1<=300:
                memo[i][j][k]+=c(i,j+1,k-1)*k/(i+j+k)
            return memo[i][j][k]

print(c(A,B,C))

Fixed submission:
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()