Buggy python submission (verdict: Time Limit Exceeded):
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(n + 1):
        for j in range(n + 1):
            for i in range(n + 1):
                ijk = i + j + k
                if ijk == 0:
                    continue
                dp[i][j][k] = n / ijk
                if i != 0:
                    dp[i][j][k] += dp[i - 1][j][k] * i / ijk
                if j != 0 and i != n:
                    dp[i][j][k] += dp[i + 1][j - 1][k] * j / ijk
                if k != 0 and j != n:
                    dp[i][j][k] += dp[i][j + 1][k - 1] * k / ijk
    
    print(dp[one][two][three])


main()

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

Buggy python submission (verdict: Time Limit Exceeded):
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(n + 1):
        for j in range(n + 1):
            for i in range(n + 1):
                ijk = i + j + k
                if ijk == 0:
                    continue
                dp[i][j][k] = n / ijk
                if i != 0:
                    dp[i][j][k] += dp[i - 1][j][k] * i / ijk
                if j != 0 and i != n:
                    dp[i][j][k] += dp[i + 1][j - 1][k] * j / ijk
                if k != 0 and j != n:
                    dp[i][j][k] += dp[i][j + 1][k - 1] * k / ijk
    
    print(dp[one][two][three])


main()

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