import numpy as np

from numba import njit





@njit('f8(i8,i8,i8,i8,f8[:,:,:])')

def get_expv(N, i, j, k, expv):

    result = 0.0

    if expv[i][j][k] != -1:

        return expv[i][j][k]

    nonlp = 1.0 - (N-i-j-k) / N

    result += 1

    if i != 0:

        result += get_expv(N, i-1, j, k, expv) * (i / N)

    if j != 0:

        result += get_expv(N, i+1, j-1, k, expv) * (j / N)

    if k != 0:

        result += get_expv(N, i, j+1, k-1, expv) * (k / N)

    result /= nonlp

    expv[i][j][k] = result

    return result



def main():

    N = int(eval(input()))



    sushi_count = {1:0, 2:0, 3:0}

    for a in map(int, input().split()):

        sushi_count[a] += 1

    sh = (N+1, N-sushi_count[1]+1, sushi_count[3]+1)

    expv = np.full(sh, -1.0)



    expv[0][0][0] = 0.0



    print((get_expv(N, sushi_count[1], sushi_count[2], sushi_count[3], expv)))



if __name__ == '__main__':

    main()
import numpy as np

from numba import njit

 

 

@njit('f8(i8,i8,i8,i8,f8[:,:,:])', cache=True)

def get_expv(N, i, j, k, expv):

    result = 0.0

    if expv[i][j][k] != -1:

        return expv[i][j][k]

    nonlp = 1.0 - (N-i-j-k) / N

    result += 1

    if i != 0:

        result += get_expv(N, i-1, j, k, expv) * (i / N)

    if j != 0:

        result += get_expv(N, i+1, j-1, k, expv) * (j / N)

    if k != 0:

        result += get_expv(N, i, j+1, k-1, expv) * (k / N)

    result /= nonlp

    expv[i][j][k] = result

    return result

 

def main():

    N = int(eval(input()))

 

    sushi_count = {1:0, 2:0, 3:0}

    for a in map(int, input().split()):

        sushi_count[a] += 1

    sh = (N+1, N-sushi_count[1]+1, sushi_count[3]+1)

    expv = np.full(sh, -1.0)

 

    expv[0][0][0] = 0.0

 

    print((get_expv(N, sushi_count[1], sushi_count[2], sushi_count[3], expv)))

 

if __name__ == '__main__':

    main()
import numpy as np
from numba import njit


@njit("f8(i8,i8,i8,i8,f8[:,:,:])")
def get_expv(N, i, j, k, expv):
    result = 0.0
    if expv[i][j][k] != -1:
        return expv[i][j][k]
    nonlp = 1.0 - (N - i - j - k) / N
    result += 1
    if i != 0:
        result += get_expv(N, i - 1, j, k, expv) * (i / N)
    if j != 0:
        result += get_expv(N, i + 1, j - 1, k, expv) * (j / N)
    if k != 0:
        result += get_expv(N, i, j + 1, k - 1, expv) * (k / N)
    result /= nonlp
    expv[i][j][k] = result
    return result


def main():
    N = int(eval(input()))
    sushi_count = {1: 0, 2: 0, 3: 0}
    for a in map(int, input().split()):
        sushi_count[a] += 1
    sh = (N + 1, N - sushi_count[1] + 1, sushi_count[3] + 1)
    expv = np.full(sh, -1.0)
    expv[0][0][0] = 0.0
    print((get_expv(N, sushi_count[1], sushi_count[2], sushi_count[3], expv)))


if __name__ == "__main__":
    main()

import numpy as np
from numba import njit


@njit("f8(i8,i8,i8,i8,f8[:,:,:])", cache=True)
def get_expv(N, i, j, k, expv):
    result = 0.0
    if expv[i][j][k] != -1:
        return expv[i][j][k]
    nonlp = 1.0 - (N - i - j - k) / N
    result += 1
    if i != 0:
        result += get_expv(N, i - 1, j, k, expv) * (i / N)
    if j != 0:
        result += get_expv(N, i + 1, j - 1, k, expv) * (j / N)
    if k != 0:
        result += get_expv(N, i, j + 1, k - 1, expv) * (k / N)
    result /= nonlp
    expv[i][j][k] = result
    return result


def main():
    N = int(eval(input()))
    sushi_count = {1: 0, 2: 0, 3: 0}
    for a in map(int, input().split()):
        sushi_count[a] += 1
    sh = (N + 1, N - sushi_count[1] + 1, sushi_count[3] + 1)
    expv = np.full(sh, -1.0)
    expv[0][0][0] = 0.0
    print((get_expv(N, sushi_count[1], sushi_count[2], sushi_count[3], expv)))


if __name__ == "__main__":
    main()

-@njit("f8(i8,i8,i8,i8,f8[:,:,:])") +@njit("f8(i8,i8,i8,i8,f8[:,:,:])", cache=True)