Buggy python submission (verdict: Time Limit Exceeded):
#!/mnt/c/Users/moiki/bash/env/bin/python
# FROM : https://atcoder.jp/contests/dp/submissions/4017206
# N,M = map(int, input().split())
N = int(input())
from collections import Counter
a = Counter( map(int, input().split()))


#1,2,3
A,B,C = (a[i] for i in range(1,4))

# dpA,B,C

dp = [ [ [0] * (C+1) 
           for _ in range(B+C+1)
       ]
           for _ in range(A+B+C+1) 
     ]


for c in range(C+1):
    for b in range(B+C+1-c):
        for a in range(A+B+C+1-b-c):
            # if a == b == c == 0:
            #     continue

            try: 
                dp[a][b][c] = (
                        ( a * ( dp[a-1][b][c]   if a else 0)  ) + 
                        ( b * ( dp[a+1][b-1][c] if b else 0)  ) +
                        ( c * ( dp[a][b+1][c-1] if c else 0)  ) + N 
                       ) / ( a+b+c ) 
            except:
                continue

print(dp[A][B][C])


Fixed submission:
#!/mnt/c/Users/moiki/bash/env/bin/python
# FROM : https://atcoder.jp/contests/dp/submissions/4017206
# N,M = map(int, input().split())
N = int(input())
from collections import Counter
a = Counter( map(int, input().split()))


#1,2,3
A,B,C = (a[i] for i in range(1,4))

# dpA,B,C

# dp = [ [ [0] * (C+1) 
#            for _ in range(B+C+1)
#        ]
#            for _ in range(A+B+C+1) 
#      ]

dp = [ [ [0]*(A+B+C+1) for _ in range(B+C+1)]
        for _ in range(C+1) ] 

for c in range(C+1):
    for b in range(B+C+1-c):
        for a in range(A+B+C+1-b-c):
            # if a == b == c == 0:
            #     continue

            try: 
                dp[c][b][a] = (
                        ( a * ( dp[c][b][a-1]   if a else 0)  ) + 
                        ( b * ( dp[c][b-1][a+1] if b else 0)  ) +
                        ( c * ( dp[c-1][b+1][a] if c else 0)  ) + N 
                       ) / ( a+b+c ) 
                # dp[a][b][c] = (
                #         ( a * ( dp[a-1][b][c]   if a else 0)  ) + 
                #         ( b * ( dp[a+1][b-1][c] if b else 0)  ) +
                #         ( c * ( dp[a][b+1][c-1] if c else 0)  ) + N 
                #        ) / ( a+b+c ) 
            except:
                continue

print(dp[C][B][A])
# print(dp[A][B][C])

Buggy python submission (verdict: Time Limit Exceeded):
#!/mnt/c/Users/moiki/bash/env/bin/python
# FROM : https://atcoder.jp/contests/dp/submissions/4017206
# N,M = map(int, input().split())
N = int(input())
from collections import Counter
a = Counter( map(int, input().split()))


#1,2,3
A,B,C = (a[i] for i in range(1,4))

# dpA,B,C

dp = [ [ [0] * (C+1) 
           for _ in range(B+C+1)
       ]
           for _ in range(A+B+C+1) 
     ]


for c in range(C+1):
    for b in range(B+C+1-c):
        for a in range(A+B+C+1-b-c):
            # print("a: {}, b: {}, c:{} ".format(a,b,c), end = " ")
            if a == b == c == 0:
                # print("")
                continue

            dp[a][b][c] = (
                    ( a * ( dp[a-1][b][c]   if a else 0)  ) + 
                    ( b * ( dp[a+1][b-1][c] if b else 0)  ) +
                    ( c * ( dp[a][b+1][c-1] if c else 0)  ) + N 
                   ) / ( a+b+c ) 
            # print(dp[a][b][c])

print(dp[A][B][C])


Fixed submission:
#!/mnt/c/Users/moiki/bash/env/bin/python
# FROM : https://atcoder.jp/contests/dp/submissions/4017206
# N,M = map(int, input().split())
N = int(input())
from collections import Counter
a = Counter( map(int, input().split()))


#1,2,3
A,B,C = (a[i] for i in range(1,4))

# dpA,B,C

# dp = [ [ [0] * (C+1) 
#            for _ in range(B+C+1)
#        ]
#            for _ in range(A+B+C+1) 
#      ]

dp = [ [ [0]*(A+B+C+1) for _ in range(B+C+1)]
        for _ in range(C+1) ] 

for c in range(C+1):
    for b in range(B+C+1-c):
        for a in range(A+B+C+1-b-c):
            # if a == b == c == 0:
            #     continue

            try: 
                dp[c][b][a] = (
                        ( a * ( dp[c][b][a-1]   if a else 0)  ) + 
                        ( b * ( dp[c][b-1][a+1] if b else 0)  ) +
                        ( c * ( dp[c-1][b+1][a] if c else 0)  ) + N 
                       ) / ( a+b+c ) 
                # dp[a][b][c] = (
                #         ( a * ( dp[a-1][b][c]   if a else 0)  ) + 
                #         ( b * ( dp[a+1][b-1][c] if b else 0)  ) +
                #         ( c * ( dp[a][b+1][c-1] if c else 0)  ) + N 
                #        ) / ( a+b+c ) 
            except:
                continue

print(dp[C][B][A])
# print(dp[A][B][C])

Buggy python submission (verdict: Time Limit Exceeded):
#!/mnt/c/Users/moiki/bash/env/bin/python
# FROM : https://atcoder.jp/contests/dp/submissions/4017206
# N,M = map(int, input().split())
N = int(input())
from collections import Counter
a = Counter( map(int, input().split()))


#1,2,3
A,B,C = (a[i] for i in range(1,4))

# dpA,B,C

dp = [ [ [0] * (C+1) 
           for _ in range(B+C+1)
       ]
           for _ in range(A+B+C+1) 
     ]


for c in range(C+1):
    for b in range(B+C+1-c):
        for a in range(A+B+C+1-b-c):
            # print("a: {}, b: {}, c:{} ".format(a,b,c), end = " ")
            if a == b == c == 0:
                # print("")
                continue

            dp[a][b][c] = (
                    ( a * ( dp[a-1][b][c]   if a else 0)  ) + 
                    ( b * ( dp[a+1][b-1][c] if b else 0)  ) +
                    ( c * ( dp[a][b+1][c-1] if c else 0)  ) + N 
                   ) / ( a+b+c ) 
            # print(dp[a][b][c])

print(dp[A][B][C])


Fixed submission:
#!/mnt/c/Users/moiki/bash/env/bin/python
# FROM : https://atcoder.jp/contests/dp/submissions/4017206
# N,M = map(int, input().split())
N = int(input())
from collections import Counter
a = Counter( map(int, input().split()))


#1,2,3
A,B,C = (a[i] for i in range(1,4))

# dpA,B,C

# dp = [ [ [0] * (C+1) 
#            for _ in range(B+C+1)
#        ]
#            for _ in range(A+B+C+1) 
#      ]

dp = [ [ [0]*(A+B+C+1) for _ in range(B+C+1)]
        for _ in range(C+1) ] 

for c in range(C+1):
    for b in range(B+C+1-c):
        for a in range(A+B+C+1-b-c):
            # if a == b == c == 0:
            #     continue

            try: 
                dp[c][b][a] = (
                        ( a * ( dp[c][b][a-1]   if a else 0)  ) + 
                        ( b * ( dp[c][b-1][a+1] if b else 0)  ) +
                        ( c * ( dp[c-1][b+1][a] if c else 0)  ) + N 
                       ) / ( a+b+c ) 
                # dp[a][b][c] = (
                #         ( a * ( dp[a-1][b][c]   if a else 0)  ) + 
                #         ( b * ( dp[a+1][b-1][c] if b else 0)  ) +
                #         ( c * ( dp[a][b+1][c-1] if c else 0)  ) + N 
                #        ) / ( a+b+c ) 
            except:
                continue

print(dp[C][B][A])
# print(dp[A][B][C])