Buggy python submission (verdict: Time Limit Exceeded):
"""
dp[i][j][k] = 寿司が1個、2個、3個残っている皿の数がそれぞれi皿、j皿、k皿であるような状態に
なるまでに必要な操作回数の期待値
dp[c_1][c_2][c_3] = 0として、dp[0][0][0]が答え
"""

import sys
input = sys.stdin.readline
sys.setrecursionlimit(10**7)
n = int(input())
A = tuple(map(int, input().split()))
C = [0]*3
for a in A:
  C[a-1] += 1
dp = [[[-1]*(n+1) for i in range(n+1)] for j in range(n+1)]
dp[0][0][0] = 0
def f(i, j, k):
  if dp[i][j][k] != -1:
    return dp[i][j][k]
  res = 1
  if i:
    res += f(i-1, j, k)*(i/n)
  if j:
    res += f(i+1, j-1, k)*(j/n)
  if k:
    res += f(i, j+1, k-1)*(k/n)
  res /= (i+j+k)/n
  dp[i][j][k] = res
  return res
ans = f(C[0], C[1], C[2])
print(ans)

Fixed submission:
import sys
input = sys.stdin.readline
sys.setrecursionlimit(10**7)
n = int(input())
A = tuple(map(int, input().split()))
C = [0]*3
for a in A:
  C[a-1] += 1
dp = [[[-1]*(n+1) for i in range(n+1)] for j in range(n+1)]
dp[0][0][0] = 0
def f(i, j, k):
  if dp[i][j][k] != -1:
    return dp[i][j][k]
  res = 1
  if i:
    res += f(i-1, j, k)*(i/n)
  if j:
    res += f(i+1, j-1, k)*(j/n)
  if k:
    res += f(i, j+1, k-1)*(k/n)
  res /= (i+j+k)/n
  dp[i][j][k] = res
  return res
ans = f(C[0], C[1], C[2])
print(ans)

Buggy python submission (verdict: Time Limit Exceeded):
import sys
input = sys.stdin.readline

n = int(input())

dp = [[[-1]*(n+1) for _ in range(n+1)] for i in range(n+1)]
dp[0][0][0] = 0
for d in range(n+1):
  for c in range(n+1-d):
    for b in range(n+1-d-c):
      if b == c == d == 0:
        continue
      dp[b][c][d] = 1
      if b != 0:
        dp[b][c][d] += b/n*dp[b-1][c][d]
      if c != 0:
        dp[b][c][d] += c/n*dp[b+1][c-1][d]
      if d != 0:
        dp[b][c][d] += d/n*dp[b][c+1][d-1]
      dp[b][c][d] /= (b+c+d)
      dp[b][c][d] *= n

L = [0]*3
for a in map(int, input().split()):
  L[a-1] += 1
ans = dp[L[0]][L[1]][L[2]]
print(ans)

Fixed submission:
import sys
input = sys.stdin.readline
sys.setrecursionlimit(10**7)
n = int(input())
A = tuple(map(int, input().split()))
C = [0]*3
for a in A:
  C[a-1] += 1
dp = [[[-1]*(n+1) for i in range(n+1)] for j in range(n+1)]
dp[0][0][0] = 0
def f(i, j, k):
  if dp[i][j][k] != -1:
    return dp[i][j][k]
  res = 1
  if i:
    res += f(i-1, j, k)*(i/n)
  if j:
    res += f(i+1, j-1, k)*(j/n)
  if k:
    res += f(i, j+1, k-1)*(k/n)
  res /= (i+j+k)/n
  dp[i][j][k] = res
  return res
ans = f(C[0], C[1], C[2])
print(ans)

Buggy python submission (verdict: Time Limit Exceeded):
import sys
input = sys.stdin.readline

n = int(input())

dp = [[[-1]*(n+1) for _ in range(n+1)] for i in range(n+1)]
dp[0][0][0] = 0
for d in range(n+1):
  for c in range(n+1-d):
    for b in range(n+1-d-c):
      if b == c == d == 0:
        continue
      dp[b][c][d] = n
      if b != 0:
        dp[b][c][d] += b*dp[b-1][c][d]
      if c != 0:
        dp[b][c][d] += c*dp[b+1][c-1][d]
      if d != 0:
        dp[b][c][d] += d*dp[b][c+1][d-1]
      dp[b][c][d] /= (b+c+d)

L = [0]*3
for a in map(int, input().split()):
  L[a-1] += 1
ans = dp[L[0]][L[1]][L[2]]
print(ans)

Fixed submission:
import sys
input = sys.stdin.readline
sys.setrecursionlimit(10**7)
n = int(input())
A = tuple(map(int, input().split()))
C = [0]*3
for a in A:
  C[a-1] += 1
dp = [[[-1]*(n+1) for i in range(n+1)] for j in range(n+1)]
dp[0][0][0] = 0
def f(i, j, k):
  if dp[i][j][k] != -1:
    return dp[i][j][k]
  res = 1
  if i:
    res += f(i-1, j, k)*(i/n)
  if j:
    res += f(i+1, j-1, k)*(j/n)
  if k:
    res += f(i, j+1, k-1)*(k/n)
  res /= (i+j+k)/n
  dp[i][j][k] = res
  return res
ans = f(C[0], C[1], C[2])
print(ans)

Buggy python submission (verdict: Time Limit Exceeded):
import sys
input = sys.stdin.readline

n = int(input())

dp = [[[-1]*(n+1) for _ in range(n+1)] for i in range(n+1)]
dp[0][0][0] = 0
for d in range(n+1):
  for c in range(n+1-d):
    for b in range(n+1-d-c):
      if b == c == d == 0:
        continue
      dp[b][c][d] = n
      if b != 0:
        dp[b][c][d] += b*dp[b-1][c][d]
      if c != 0:
        dp[b][c][d] += c*dp[b+1][c-1][d]
      if d != 0:
        dp[b][c][d] += d*dp[b][c+1][d-1]
      dp[b][c][d] /= (b+c+d)

L = [0]*3
for a in map(int, input().split()):
  L[a-1] += 1
ans = dp[L[0]][L[1]][L[2]]
print(ans)

Fixed submission:
import sys
input = sys.stdin.readline
sys.setrecursionlimit(10**7)
n = int(input())
A = tuple(map(int, input().split()))
C = [0]*3
for a in A:
  C[a-1] += 1
dp = [[[-1]*(n+1) for i in range(n+1)] for j in range(n+1)]
dp[0][0][0] = 0
def f(i, j, k):
  if dp[i][j][k] != -1:
    return dp[i][j][k]
  res = 1
  if i:
    res += f(i-1, j, k)*(i/n)
  if j:
    res += f(i+1, j-1, k)*(j/n)
  if k:
    res += f(i, j+1, k-1)*(k/n)
  res /= (i+j+k)/n
  dp[i][j][k] = res
  return res
ans = f(C[0], C[1], C[2])
print(ans)

Buggy python submission (verdict: Time Limit Exceeded):
import sys
sys.setrecursionlimit(10**7)
input = sys.stdin.readline

def main():
  n = int(input())

  D = [[[-1]*(n+1) for _ in range(n+1)] for i in range(n+1)]
  def dfs(b, c, d):
    if b == c == d == 0:
      return 0
    if D[b][c][d] != -1:
      return D[b][c][d]
    rep = n
    if b != 0:
      rep += b * dfs(b-1, c, d)
    if c != 0:
      rep += c * dfs(b+1, c-1, d)
    if d != 0:
      rep += d * dfs(b, c+1, d-1)
    rep /= (b+c+d)
    D[b][c][d] = rep
    return rep

  L = [0]*3
  for a in map(int, input().split()):
    L[a-1] += 1
  ans = dfs(*L)
  print(ans)
  
if __name__ == "__main__":
  main()

Fixed submission:
import sys
input = sys.stdin.readline
sys.setrecursionlimit(10**7)
n = int(input())
A = tuple(map(int, input().split()))
C = [0]*3
for a in A:
  C[a-1] += 1
dp = [[[-1]*(n+1) for i in range(n+1)] for j in range(n+1)]
dp[0][0][0] = 0
def f(i, j, k):
  if dp[i][j][k] != -1:
    return dp[i][j][k]
  res = 1
  if i:
    res += f(i-1, j, k)*(i/n)
  if j:
    res += f(i+1, j-1, k)*(j/n)
  if k:
    res += f(i, j+1, k-1)*(k/n)
  res /= (i+j+k)/n
  dp[i][j][k] = res
  return res
ans = f(C[0], C[1], C[2])
print(ans)

Buggy python submission (verdict: Time Limit Exceeded):
import sys
sys.setrecursionlimit(10**7)
input = sys.stdin.readline

def main():
  n = int(input())

  D = [[[-1]*(n+1) for _ in range(n+1)] for i in range(n+1)]
  def dfs(b, c, d):
    if b == c == d == 0:
      return 0
    if D[b][c][d] != -1:
      return D[b][c][d]
    rep = n
    if b != 0:
      rep += b * dfs(b-1, c, d)
    if c != 0:
      rep += c * dfs(b+1, c-1, d)
    if d != 0:
      rep += d * dfs(b, c+1, d-1)
    rep /= (b+c+d)
    D[b][c][d] = rep
    return rep

  L = [0]*3
  for a in map(int, input().split()):
    L[a-1] += 1
  ans = dfs(*L)
  print(ans)
  
if __name__ == "__main__":
  main()

Fixed submission:
import sys
input = sys.stdin.readline
sys.setrecursionlimit(10**7)
n = int(input())
A = tuple(map(int, input().split()))
C = [0]*3
for a in A:
  C[a-1] += 1
dp = [[[-1]*(n+1) for i in range(n+1)] for j in range(n+1)]
dp[0][0][0] = 0
def f(i, j, k):
  if dp[i][j][k] != -1:
    return dp[i][j][k]
  res = 1
  if i:
    res += f(i-1, j, k)*(i/n)
  if j:
    res += f(i+1, j-1, k)*(j/n)
  if k:
    res += f(i, j+1, k-1)*(k/n)
  res /= (i+j+k)/n
  dp[i][j][k] = res
  return res
ans = f(C[0], C[1], C[2])
print(ans)

Buggy python submission (verdict: Time Limit Exceeded):
import sys
sys.setrecursionlimit(10**7)
input = sys.stdin.readline

n = int(input())

D = [[[-1]*(n+1) for _ in range(n+1)] for i in range(n+1)]
def dfs(b, c, d):
  if b == c == d == 0:
    return 0
  if D[b][c][d] != -1:
    return D[b][c][d]
  rep = n
  if b != 0:
    rep += b * dfs(b-1, c, d)
  if c != 0:
    rep += c * dfs(b+1, c-1, d)
  if d != 0:
    rep += d * dfs(b, c+1, d-1)
  rep /= (b+c+d)
  D[b][c][d] = rep
  return rep

L = [0]*3
for a in map(int, input().split()):
  L[a-1] += 1
ans = dfs(*L)
print(ans)

Fixed submission:
import sys
input = sys.stdin.readline
sys.setrecursionlimit(10**7)
n = int(input())
A = tuple(map(int, input().split()))
C = [0]*3
for a in A:
  C[a-1] += 1
dp = [[[-1]*(n+1) for i in range(n+1)] for j in range(n+1)]
dp[0][0][0] = 0
def f(i, j, k):
  if dp[i][j][k] != -1:
    return dp[i][j][k]
  res = 1
  if i:
    res += f(i-1, j, k)*(i/n)
  if j:
    res += f(i+1, j-1, k)*(j/n)
  if k:
    res += f(i, j+1, k-1)*(k/n)
  res /= (i+j+k)/n
  dp[i][j][k] = res
  return res
ans = f(C[0], C[1], C[2])
print(ans)

Buggy python submission (verdict: Time Limit Exceeded):
import numpy as np

import sys
sys.setrecursionlimit(10**7)
n = int(input())

D = np.full((n+1, n+1, n+1), -1)
def dfs(a, b, c, d):
  if a == n:
    return 0
  if D[a, b, c] != -1:
    return D[a, b, c]
  rep = n
  if b != 0:
    rep += b * dfs(a+1, b-1, c, d)
  if c != 0:
    rep += c * dfs(a, b+1, c-1, d)
  if d != 0:
    rep += d * dfs(a, b, c+1, d-1)
  rep /= (n-a)
  D[a, b, c] = rep
  return rep

L = [0]*4
for a in map(int, input().split()):
  L[a] += 1
ans = dfs(*L)
print(ans)

Fixed submission:
import sys
input = sys.stdin.readline
sys.setrecursionlimit(10**7)
n = int(input())
A = tuple(map(int, input().split()))
C = [0]*3
for a in A:
  C[a-1] += 1
dp = [[[-1]*(n+1) for i in range(n+1)] for j in range(n+1)]
dp[0][0][0] = 0
def f(i, j, k):
  if dp[i][j][k] != -1:
    return dp[i][j][k]
  res = 1
  if i:
    res += f(i-1, j, k)*(i/n)
  if j:
    res += f(i+1, j-1, k)*(j/n)
  if k:
    res += f(i, j+1, k-1)*(k/n)
  res /= (i+j+k)/n
  dp[i][j][k] = res
  return res
ans = f(C[0], C[1], C[2])
print(ans)

Buggy python submission (verdict: Runtime Error):
import numpy as np

import sys
sys.setrecursionlimit(10**7)
n = int(input())

D = np.full((n+1, n+1, n+1, n+1), -1)
def dfs(a, b, c, d):
  if a == n:
    return 0
  if D[a, b, c, d] != -1:
    return D[a, b, c, d]
  rep = n
  if b != 0:
    rep += b * dfs(a+1, b-1, c, d)
  if c != 0:
    rep += c * dfs(a, b+1, c-1, d)
  if d != 0:
    rep += d * dfs(a, b, c+1, d-1)
  rep /= (n-a)
  D[a, b, c, d] = rep
  return rep

L = [0]*4
for a in map(int, input().split()):
  L[a] += 1
ans = dfs(*L)
print(ans)

Fixed submission:
import sys
input = sys.stdin.readline
sys.setrecursionlimit(10**7)
n = int(input())
A = tuple(map(int, input().split()))
C = [0]*3
for a in A:
  C[a-1] += 1
dp = [[[-1]*(n+1) for i in range(n+1)] for j in range(n+1)]
dp[0][0][0] = 0
def f(i, j, k):
  if dp[i][j][k] != -1:
    return dp[i][j][k]
  res = 1
  if i:
    res += f(i-1, j, k)*(i/n)
  if j:
    res += f(i+1, j-1, k)*(j/n)
  if k:
    res += f(i, j+1, k-1)*(k/n)
  res /= (i+j+k)/n
  dp[i][j][k] = res
  return res
ans = f(C[0], C[1], C[2])
print(ans)

Buggy python submission (verdict: Time Limit Exceeded):
import sys
sys.setrecursionlimit(10**7)
n = int(input())

D = dict()
def dfs(a, b, c, d):
  if a == n:
    return 0
  if (a, b, c, d) in D:
    return D[(a, b, c, d)]
  rep = n
  if b != 0:
    rep += b * dfs(a+1, b-1, c, d)
  if c != 0:
    rep += c * dfs(a, b+1, c-1, d)
  if d != 0:
    rep += d * dfs(a, b, c+1, d-1)
  rep /= (n-a)
  D[(a, b, c, d)] = rep
  return rep

L = [0]*4
for a in map(int, input().split()):
  L[a] += 1
ans = dfs(*L)
print(ans)

Fixed submission:
import sys
input = sys.stdin.readline
sys.setrecursionlimit(10**7)
n = int(input())
A = tuple(map(int, input().split()))
C = [0]*3
for a in A:
  C[a-1] += 1
dp = [[[-1]*(n+1) for i in range(n+1)] for j in range(n+1)]
dp[0][0][0] = 0
def f(i, j, k):
  if dp[i][j][k] != -1:
    return dp[i][j][k]
  res = 1
  if i:
    res += f(i-1, j, k)*(i/n)
  if j:
    res += f(i+1, j-1, k)*(j/n)
  if k:
    res += f(i, j+1, k-1)*(k/n)
  res /= (i+j+k)/n
  dp[i][j][k] = res
  return res
ans = f(C[0], C[1], C[2])
print(ans)