Buggy python submission (verdict: Time Limit Exceeded):
n,a=int(input()),map(int,input().split());c=[0]*3
for i in a:c[i-1]+=1
x,y,z=c;dp=[[[0]*(z+2) for i in range(n-x+2)]for i in range(n+2)]
for k in range(z+1):
  for j in range(n-x-k+1):
    for i in range(n-k-j+1):
      if i+j+k:dp[i][j][k]=(n+dp[i-1][j][k]*i+dp[i+1][j-1][k]*j+dp[i][j+1][k-1]*k)/(i+j+k)
print(dp[x][y][z])

Fixed submission:
n,a=int(input()),map(int,input().split());c=[0]*3
for i in a:c[i-1]+=1
x,y,z=c;dp=[[[None]*(z+2) for i in range(n-x+2)]for i in range(n+2)];dp[0][0][0]=0
for k in range(z+1):
  for j in range(n-x-k+1):
    for i in range(n-k-j+1):
      if i+j+k:dp[i][j][k]=((dp[i-1][j][k]*i if i else 0)+(dp[i+1][j-1][k]*j if j else 0)+(dp[i][j+1][k-1]*k if k else 0)+n)/(i+j+k)
print(dp[x][y][z])

Buggy python submission (verdict: Time Limit Exceeded):
n,a=int(input()),map(int,input().split());c=[0]*3;l=[1.0/i for i in range(1,n+1)]
for i in a:c[i-1]+=1
x,y,z=c;dp=[[[0]*(z+2) for i in range(n-x+2)]for i in range(n+2)]
for k in range(z+1):
  for j in range(n-x-k+1):
    for i in range(n-k-j+1):
      if i+j+k:dp[i][j][k]=(n+dp[i-1][j][k]*i+dp[i+1][j-1][k]*j+dp[i][j+1][k-1]*k)*l[i+j+k-1]
print(dp[x][y][z])

Fixed submission:
n,a=int(input()),map(int,input().split());c=[0]*3
for i in a:c[i-1]+=1
x,y,z=c;dp=[[[None]*(z+2) for i in range(n-x+2)]for i in range(n+2)];dp[0][0][0]=0
for k in range(z+1):
  for j in range(n-x-k+1):
    for i in range(n-k-j+1):
      if i+j+k:dp[i][j][k]=((dp[i-1][j][k]*i if i else 0)+(dp[i+1][j-1][k]*j if j else 0)+(dp[i][j+1][k-1]*k if k else 0)+n)/(i+j+k)
print(dp[x][y][z])

Buggy python submission (verdict: Time Limit Exceeded):
n=int(input());c=[0]*3;l=[1.0/i for i in range(1,n+1)]
for i in map(int,input().split()):c[i-1]+=1
x,y,z=c;dp=[[[-1]*(z+2) for i in range(n-x+2)]for i in range(n+2)]
for k in range(z+1):
  for j in range(n-x-k+1):
    for i in range(n-k-j+1):
      if i+j+k:dp[i][j][k]=(n+dp[i-1][j][k]*i+dp[i+1][j-1][k]*j+dp[i][j+1][k-1]*k)*l[i+j+k-1]
print(dp[x][y][z]+1)

Fixed submission:
n,a=int(input()),map(int,input().split());c=[0]*3
for i in a:c[i-1]+=1
x,y,z=c;dp=[[[None]*(z+2) for i in range(n-x+2)]for i in range(n+2)];dp[0][0][0]=0
for k in range(z+1):
  for j in range(n-x-k+1):
    for i in range(n-k-j+1):
      if i+j+k:dp[i][j][k]=((dp[i-1][j][k]*i if i else 0)+(dp[i+1][j-1][k]*j if j else 0)+(dp[i][j+1][k-1]*k if k else 0)+n)/(i+j+k)
print(dp[x][y][z])

Buggy python submission (verdict: Time Limit Exceeded):
n=int(input());c=[0]*3;l=[1.0/i for i in range(1,n+1)]
for i in map(int,input().split()):c[i-1]+=1
x,y,z=c;dp=[[[-1]*(z+2) for i in range(n-x+2)]for i in range(n+2)]
for k in range(z+1):
  for j in range(n-x-k+1):
    for i in range(n-k-j+1):
      if i+j+k:dp[i][j][k]=(n+dp[i-1][j][k]*i+dp[i+1][j-1][k]*j+dp[i][j+1][k-1]*k)*l[i+j+k-1]
print(dp[x][y][z]+1)

Fixed submission:
n,a=int(input()),map(int,input().split());c=[0]*3
for i in a:c[i-1]+=1
x,y,z=c;dp=[[[None]*(z+2) for i in range(n-x+2)]for i in range(n+2)];dp[0][0][0]=0
for k in range(z+1):
  for j in range(n-x-k+1):
    for i in range(n-k-j+1):
      if i+j+k:dp[i][j][k]=((dp[i-1][j][k]*i if i else 0)+(dp[i+1][j-1][k]*j if j else 0)+(dp[i][j+1][k-1]*k if k else 0)+n)/(i+j+k)
print(dp[x][y][z])

Buggy python submission (verdict: Time Limit Exceeded):
n,a=int(input()),list(map(int,input().split()));c=[0,0,0];x=[1.0/i for i in range(1,n+1)]
for i in a:c[i-1]+=1
dp=[[[-1]*(c[2]+2) for i in range(c[1]+c[2]+2)]for i in range(n+2)]
for k in range(c[2]+1):
  for j in range(c[2]+c[1]-k+1):
    for i in range(n-k-j+1):
      if i+j+k:dp[i][j][k]=((dp[i-1][j][k]*i if i else 0)+(dp[i+1][j-1][k]*j if j else 0)+(dp[i][j+1][k-1]*k if k else 0)+n)*x[i+j+k-1]
print(dp[c[0]][c[1]][c[2]]+1)

Fixed submission:
n,a=int(input()),map(int,input().split());c=[0]*3
for i in a:c[i-1]+=1
x,y,z=c;dp=[[[None]*(z+2) for i in range(n-x+2)]for i in range(n+2)];dp[0][0][0]=0
for k in range(z+1):
  for j in range(n-x-k+1):
    for i in range(n-k-j+1):
      if i+j+k:dp[i][j][k]=((dp[i-1][j][k]*i if i else 0)+(dp[i+1][j-1][k]*j if j else 0)+(dp[i][j+1][k-1]*k if k else 0)+n)/(i+j+k)
print(dp[x][y][z])

Buggy python submission (verdict: Runtime Error):
n,a=int(input()),list(map(int,input().split()));c=[0,0,0];x=[1.0/i for i in range(1,n+1)];dp=[[[-1]*(c[2]+2) for i in range(c[1]+c[2]+2)]for i in range(n+2)]
for i in a:c[i-1]+=1
for k in range(c[2]+1):
  for j in range(c[2]+c[1]-k+1):
    for i in range(n-k-j+1):
      if i+j+k>0:dp[i][j][k]=((dp[i-1][j][k]*i if i else 0)+(dp[i+1][j-1][k]*j if j else 0)+(dp[i][j+1][k-1]*k if k else 0)+n)*x[i+j+k-1]
print(dp[c[0]][c[1]][c[2]]+1)

Fixed submission:
n,a=int(input()),map(int,input().split());c=[0]*3
for i in a:c[i-1]+=1
x,y,z=c;dp=[[[None]*(z+2) for i in range(n-x+2)]for i in range(n+2)];dp[0][0][0]=0
for k in range(z+1):
  for j in range(n-x-k+1):
    for i in range(n-k-j+1):
      if i+j+k:dp[i][j][k]=((dp[i-1][j][k]*i if i else 0)+(dp[i+1][j-1][k]*j if j else 0)+(dp[i][j+1][k-1]*k if k else 0)+n)/(i+j+k)
print(dp[x][y][z])

Buggy python submission (verdict: Time Limit Exceeded):
n=int(input());c=[0,0,0];x=[1.0/i for i in range(1,n+1)];dp=[[[-1]*(n+2) for i in range(n+2)]for i in range(n+2)]
for i in list(map(int,input().split())):c[i-1]+=1
for k in range(n+1):
  for j in range(n-k+1):
    for i in range(n-k-j+1):
      if i+j+k>0:dp[i][j][k]=(n+dp[i-1][j][k]*i+dp[i+1][j-1][k]*j+dp[i][j+1][k-1]*k)*x[i+j+k-1]
print(dp[c[0]][c[1]][c[2]]+1)

Fixed submission:
n,a=int(input()),map(int,input().split());c=[0]*3
for i in a:c[i-1]+=1
x,y,z=c;dp=[[[None]*(z+2) for i in range(n-x+2)]for i in range(n+2)];dp[0][0][0]=0
for k in range(z+1):
  for j in range(n-x-k+1):
    for i in range(n-k-j+1):
      if i+j+k:dp[i][j][k]=((dp[i-1][j][k]*i if i else 0)+(dp[i+1][j-1][k]*j if j else 0)+(dp[i][j+1][k-1]*k if k else 0)+n)/(i+j+k)
print(dp[x][y][z])

Buggy python submission (verdict: Time Limit Exceeded):
n,a=int(input()),list(map(int,input().split()));c=[0,0,0];x=[1.0/i for i in range(1,n+1)];dp=[[[-1]*(n+2) for i in range(n+2)]for i in range(n+2)]
for i in a:c[i-1]+=1
for k in range(n+1):
  for j in range(n-k+1):
    for i in range(n-k-j+1):
      if i+j+k>0:dp[i][j][k]=(n+dp[i-1][j][k]*i+dp[i+1][j-1][k]*j+dp[i][j+1][k-1]*k)*x[i+j+k-1]
print(dp[c[0]][c[1]][c[2]]+1)

Fixed submission:
n,a=int(input()),map(int,input().split());c=[0]*3
for i in a:c[i-1]+=1
x,y,z=c;dp=[[[None]*(z+2) for i in range(n-x+2)]for i in range(n+2)];dp[0][0][0]=0
for k in range(z+1):
  for j in range(n-x-k+1):
    for i in range(n-k-j+1):
      if i+j+k:dp[i][j][k]=((dp[i-1][j][k]*i if i else 0)+(dp[i+1][j-1][k]*j if j else 0)+(dp[i][j+1][k-1]*k if k else 0)+n)/(i+j+k)
print(dp[x][y][z])

Buggy python submission (verdict: Time Limit Exceeded):
n,a=int(input()),list(map(int,input().split()));c=[a.count(i+1)for i in range(3)];x=[1.0/i for i in range(1,n+1)];dp=[[[-1]*(n+2) for i in range(n+2)]for i in range(n+2)]
for k in range(n+1):
  for j in range(n-k+1):
    for i in range(n-k-j+1):
      if i+j+k>0:dp[i][j][k]=(n+dp[i-1][j][k]*i+dp[i+1][j-1][k]*j+dp[i][j+1][k-1]*k)*x[i+j+k-1]
print(dp[c[0]][c[1]][c[2]]+1)

Fixed submission:
n,a=int(input()),map(int,input().split());c=[0]*3
for i in a:c[i-1]+=1
x,y,z=c;dp=[[[None]*(z+2) for i in range(n-x+2)]for i in range(n+2)];dp[0][0][0]=0
for k in range(z+1):
  for j in range(n-x-k+1):
    for i in range(n-k-j+1):
      if i+j+k:dp[i][j][k]=((dp[i-1][j][k]*i if i else 0)+(dp[i+1][j-1][k]*j if j else 0)+(dp[i][j+1][k-1]*k if k else 0)+n)/(i+j+k)
print(dp[x][y][z])

Buggy python submission (verdict: Time Limit Exceeded):
n,a=int(input()),list(map(int,input().split()))
c=[0]*3
for i in a:c[i-1]+=1
x=[1/i for i in range(1,n+1)]
dp=[[[0]*(n+2) for i in range(n+2)]for i in range(n+2)]
for k in range(n+1):
  for j in range(n-k+1):
    for i in range(n-k-j+1):
      if n+1>i+j+k>0:
        dp[i][j][k]=(n+dp[i-1][j][k]*i+dp[i+1][j-1][k]*j+dp[i][j+1][k-1]*k)*x[i+j+k-1]
print(dp[c[0]][c[1]][c[2]])

Fixed submission:
n,a=int(input()),map(int,input().split());c=[0]*3
for i in a:c[i-1]+=1
x,y,z=c;dp=[[[None]*(z+2) for i in range(n-x+2)]for i in range(n+2)];dp[0][0][0]=0
for k in range(z+1):
  for j in range(n-x-k+1):
    for i in range(n-k-j+1):
      if i+j+k:dp[i][j][k]=((dp[i-1][j][k]*i if i else 0)+(dp[i+1][j-1][k]*j if j else 0)+(dp[i][j+1][k-1]*k if k else 0)+n)/(i+j+k)
print(dp[x][y][z])

Buggy python submission (verdict: Time Limit Exceeded):
n,a=int(input()),list(map(int,input().split()))
c=[a.count(i+1)for i in range(3)]
x=[1/i for i in range(1,n+1)]
dp=[[[0]*(n+2) for i in range(n+2)]for i in range(n+2)]
for k in range(n+1):
  for j in range(n-k+1):
    for i in range(n-k-j+1):
      if n+1>i+j+k>0:
        dp[i][j][k]=(n+dp[i-1][j][k]*i+dp[i+1][j-1][k]*j+dp[i][j+1][k-1]*k)*x[i+j+k-1]
print(dp[c[0]][c[1]][c[2]])

Fixed submission:
n,a=int(input()),map(int,input().split());c=[0]*3
for i in a:c[i-1]+=1
x,y,z=c;dp=[[[None]*(z+2) for i in range(n-x+2)]for i in range(n+2)];dp[0][0][0]=0
for k in range(z+1):
  for j in range(n-x-k+1):
    for i in range(n-k-j+1):
      if i+j+k:dp[i][j][k]=((dp[i-1][j][k]*i if i else 0)+(dp[i+1][j-1][k]*j if j else 0)+(dp[i][j+1][k-1]*k if k else 0)+n)/(i+j+k)
print(dp[x][y][z])

Buggy python submission (verdict: Time Limit Exceeded):
n,a=int(input()),list(map(int,input().split()));c=[a.count(i+1)for i in range(3)];x=[1/i for i in range(1,n+1)];dp=[[[0]*(n+2) for i in range(n+2)]for i in range(n+2)]
for k in range(n+1):
  for j in range(n-k+1):
    for i in range(n-k-j+1):
      if n+1>i+j+k>0:dp[i][j][k]=(n+dp[i-1][j][k]*i+dp[i+1][j-1][k]*j+dp[i][j+1][k-1]*k)*x[i+j+k-1]
print(dp[c[0]][c[1]][c[2]])

Fixed submission:
n,a=int(input()),map(int,input().split());c=[0]*3
for i in a:c[i-1]+=1
x,y,z=c;dp=[[[None]*(z+2) for i in range(n-x+2)]for i in range(n+2)];dp[0][0][0]=0
for k in range(z+1):
  for j in range(n-x-k+1):
    for i in range(n-k-j+1):
      if i+j+k:dp[i][j][k]=((dp[i-1][j][k]*i if i else 0)+(dp[i+1][j-1][k]*j if j else 0)+(dp[i][j+1][k-1]*k if k else 0)+n)/(i+j+k)
print(dp[x][y][z])

Buggy python submission (verdict: Time Limit Exceeded):
n,a=int(input()),list(map(int,input().split()))
c=[0]*3
for i in a:c[i-1]+=1
x=[1/i for i in range(1,n+1)]
dp=[[[0]*(n+2) for i in range(n+2)]for i in range(n+2)]
for k in range(n+1):
  for j in range(n-k+1):
    for i in range(n-k-j+1):
      if not n+1>i+j+k>0:continue
      dp[i][j][k]=(n+dp[i-1][j][k]*i+dp[i+1][j-1][k]*j+dp[i][j+1][k-1]*k)*x[i+j+k-1]
print(dp[c[0]][c[1]][c[2]])

Fixed submission:
n,a=int(input()),map(int,input().split());c=[0]*3
for i in a:c[i-1]+=1
x,y,z=c;dp=[[[None]*(z+2) for i in range(n-x+2)]for i in range(n+2)];dp[0][0][0]=0
for k in range(z+1):
  for j in range(n-x-k+1):
    for i in range(n-k-j+1):
      if i+j+k:dp[i][j][k]=((dp[i-1][j][k]*i if i else 0)+(dp[i+1][j-1][k]*j if j else 0)+(dp[i][j+1][k-1]*k if k else 0)+n)/(i+j+k)
print(dp[x][y][z])

Buggy python submission (verdict: Time Limit Exceeded):
n,a=int(input()),list(map(int,input().split()))
c=[0]*3
for i in a:c[i-1]+=1
x=[1/i for i in range(1,n+1)]
dp=[[[0]*(n+2) for i in range(n+2)]for i in range(n+2)]
for k in range(n+1):
  for j in range(n+1):
    for i in range(n+1):
      if not n+1>i+j+k>0:continue
      dp[i][j][k]=(n+dp[i-1][j][k]*i+dp[i+1][j-1][k]*j+dp[i][j+1][k-1]*k)*x[i+j+k-1]
print(dp[c[0]][c[1]][c[2]])

Fixed submission:
n,a=int(input()),map(int,input().split());c=[0]*3
for i in a:c[i-1]+=1
x,y,z=c;dp=[[[None]*(z+2) for i in range(n-x+2)]for i in range(n+2)];dp[0][0][0]=0
for k in range(z+1):
  for j in range(n-x-k+1):
    for i in range(n-k-j+1):
      if i+j+k:dp[i][j][k]=((dp[i-1][j][k]*i if i else 0)+(dp[i+1][j-1][k]*j if j else 0)+(dp[i][j+1][k-1]*k if k else 0)+n)/(i+j+k)
print(dp[x][y][z])

Buggy python submission (verdict: Time Limit Exceeded):
n,a=int(input()),list(map(int,input().split()))
c=[0]*3
for i in a:c[i-1]+=1
x=[1/i for i in range(1,n+1)]
dp=[[[0]*(n+2) for i in range(n+2)]for i in range(n+2)]
for k in range(n+1):
  for j in range(n+1):
    for i in range(n+1):
      if not n+1>i+j+k>0:continue
      p=n
      if i>0:p+=dp[i-1][j][k]*i
      if j>0:p+=dp[i+1][j-1][k]*j
      if k>0:p+=dp[i][j+1][k-1]*k
      dp[i][j][k]=p*x[i+j+k-1]
print(dp[c[0]][c[1]][c[2]])

Fixed submission:
n,a=int(input()),map(int,input().split());c=[0]*3
for i in a:c[i-1]+=1
x,y,z=c;dp=[[[None]*(z+2) for i in range(n-x+2)]for i in range(n+2)];dp[0][0][0]=0
for k in range(z+1):
  for j in range(n-x-k+1):
    for i in range(n-k-j+1):
      if i+j+k:dp[i][j][k]=((dp[i-1][j][k]*i if i else 0)+(dp[i+1][j-1][k]*j if j else 0)+(dp[i][j+1][k-1]*k if k else 0)+n)/(i+j+k)
print(dp[x][y][z])

Buggy python submission (verdict: Time Limit Exceeded):
n,a=int(input()),list(map(int,input().split()))
count=[0]*3
for i in a:count[i-1]+=1
#dp[i][j][k]...寿司が1個の皿がi枚、2個の皿がj枚、3個の皿がk枚の時の期待値
dp=[[[0]*(n+2) for i in range(n+2)]for i in range(n+2)]
for k in range(n+1):
  for j in range(n+1):
    for i in range(n+1):
      if i+j+k==0:continue
      #競プロフレンズ解説参照
      p=1
      if i>0:p+=dp[i-1][j][k]*(i/n)
      if j>0:p+=dp[i+1][j-1][k]*(j/n)
      if k>0:p+=dp[i][j+1][k-1]*(k/n)
      dp[i][j][k]=p/(1-((n-i-j-k)/n))
print(dp[count[0]][count[1]][count[2]])

Fixed submission:
n,a=int(input()),map(int,input().split());c=[0]*3
for i in a:c[i-1]+=1
x,y,z=c;dp=[[[None]*(z+2) for i in range(n-x+2)]for i in range(n+2)];dp[0][0][0]=0
for k in range(z+1):
  for j in range(n-x-k+1):
    for i in range(n-k-j+1):
      if i+j+k:dp[i][j][k]=((dp[i-1][j][k]*i if i else 0)+(dp[i+1][j-1][k]*j if j else 0)+(dp[i][j+1][k-1]*k if k else 0)+n)/(i+j+k)
print(dp[x][y][z])

Buggy python submission (verdict: Time Limit Exceeded):
import sys
input=sys.stdin.readline
sys.setrecursionlimit(10000000)
n,a=int(input()),list(map(int,input().split()))
b=[0]*3
for i in a:b[i-1]+=1
dp=[[[0]*(n+1) for i in range(n+1)]for i in range(n+1)]
flag=[[[False]*(n+1) for i in range(n+1)]for i in range(n+1)];flag[0][0][0]=True
def d(a,b,c):
  if flag[a][b][c]:return dp[a][b][c]
  p=1;flag[a][b][c]=True
  if a>0:p+=d(a-1,b,c)*(a/n)
  if b>0:p+=d(a+1,b-1,c)*(b/n)
  if c>0:p+=d(a,b+1,c-1)*(c/n)
  dp[a][b][c]=p/(1-((n-a-b-c)/n))
  return dp[a][b][c]
print(d(b[0],b[1],b[2]))

Fixed submission:
n,a=int(input()),map(int,input().split());c=[0]*3
for i in a:c[i-1]+=1
x,y,z=c;dp=[[[None]*(z+2) for i in range(n-x+2)]for i in range(n+2)];dp[0][0][0]=0
for k in range(z+1):
  for j in range(n-x-k+1):
    for i in range(n-k-j+1):
      if i+j+k:dp[i][j][k]=((dp[i-1][j][k]*i if i else 0)+(dp[i+1][j-1][k]*j if j else 0)+(dp[i][j+1][k-1]*k if k else 0)+n)/(i+j+k)
print(dp[x][y][z])

Buggy python submission (verdict: Time Limit Exceeded):
n,a=int(input()),list(map(int,input().split()));b=[0]*3;dp=[[[0]*(n+1) for i in range(n+1)]for i in range(n+1)];flag=[[[False]*(n+1) for i in range(n+1)]for i in range(n+1)];flag[0][0][0]=True
for i in a:b[i-1]+=1
def d(a,b,c):
  if flag[a][b][c]:return dp[a][b][c]
  p=1;flag[a][b][c]=True
  if a>0:p+=d(a-1,b,c)*(a/n)
  if b>0:p+=d(a+1,b-1,c)*(b/n)
  if c>0:p+=d(a,b+1,c-1)*(c/n)
  dp[a][b][c]=p/(1-((n-a-b-c)/n));return dp[a][b][c]
print(d(b[0],b[1],b[2]))

Fixed submission:
n,a=int(input()),map(int,input().split());c=[0]*3
for i in a:c[i-1]+=1
x,y,z=c;dp=[[[None]*(z+2) for i in range(n-x+2)]for i in range(n+2)];dp[0][0][0]=0
for k in range(z+1):
  for j in range(n-x-k+1):
    for i in range(n-k-j+1):
      if i+j+k:dp[i][j][k]=((dp[i-1][j][k]*i if i else 0)+(dp[i+1][j-1][k]*j if j else 0)+(dp[i][j+1][k-1]*k if k else 0)+n)/(i+j+k)
print(dp[x][y][z])