Harryxun/sft_time huggingface dataset:
### BUGGY CODE ###

N,M=map(int,input().split())
A=sorted(list(map(int,input().split())),reverse=True)
idx=1
for i in range(M):
    nidx=A[:idx].index(max(A[:idx]))
    if nidx+1==idx:
        idx+=1
    A[nidx]/=2

A=list(map(int,A))
print(sum(A))


### FIXED CODE ###

import heapq
N,M=map(int,input().split())
A=list(map(lambda x:x*-(1),list(map(int,input().split()))))
heapq.heapify(A)
for i in range(M):
    num=(heapq.heappop(A)*(-1)/2)
    heapq.heappush(A, num*-1)



A=list(map(int,A))
print(-sum(A))
### BUGGY CODE ###

a,b=map(int,input().split())
import numpy as np
def gcd(x,y):
  if x%y==0:
    return y
  else:
    return gcd(x,x%y)
  
  
  
z=int(np.ceil(np.sqrt(gcd(a,b))))
j=0
ans=[]
for i in range(1,z+1):
  while z%i==0:
    z/=i
    ans.append(i)
  

  
print(lenset((ans)))
    


### FIXED CODE ###

a,b=map(int,input().split())

def gcd(x,y):
  if x%y==0:
    return y
  else:
    return gcd(y,x%y)
  
  
n=gcd(a,b)  
i=2
ans=[1]

while i * i <= n:
  if n % i == 0:
    n /= i
    ans.append(i)
  else:
    i += 1

ans.append(n)    
  
print(len(set(ans)))
### BUGGY CODE ###

import sys
input=sys.stdin.readline
sys.setrecursionlimit(10**9)
mod=10**9+7
from collections import Counter
def comb(n,r):
    if n<r:
        return 0
    else:
        r=min(r,n-r)
        result=1
        for i in range(n-r+1,n+1):
            result*=i
        for i in range(1,r+1):
            result//=i
        return result
n=int(input())
A=list(map(int,input().split()))
C=Counter(A)
i=C.most_common()[0][0]
idx=[k for k, x in enumerate(A) if x==i]
for k in range(1,n+2):
    print((comb(n+1,k)%mod-comb(n+idx[0]-idx[1],k-1)%mod)%mod)

### FIXED CODE ###

#077-D
import sys
input=sys.stdin.readline
sys.setrecursionlimit(10**9)
from collections import Counter
mod=10**9+7
n=int(input())
A=list(map(int,input().split()))
factorial=[1]
for i in range(1,n+2):
    factorial.append(factorial[i-1]*i%mod)
inverse=[0]*(n+2)
inverse[n+1]=pow(factorial[n+1],mod-2,mod)
for i in range(n,-1,-1):
    inverse[i]=inverse[i+1]*(i+1)%mod
def comb(n,r):
    if n<r:
        return 0
    return factorial[n]*inverse[r]*inverse[n-r]%mod
C=Counter(A)
i=C.most_common()[0][0]
idx=[k for k, x in enumerate(A) if x==i]
for k in range(1,n+2):
    print((comb(n+1,k)-comb(n+idx[0]-idx[1],k-1))%mod)
### BUGGY CODE ###

a=[int(input()) for i in range(int(input()))]
count=0
for x in a:
    if a.count(x)%2==1:
        count+=1
print(count)

### FIXED CODE ###

import collections
n=int(input())
count=0
a=[int(input()) for _ in range(n)]
a=collections.Counter(a)

for key,value in a.items():
    if value%2==1:
        count+=1
print(count)
### BUGGY CODE ###

from time import time
start_time = time()
D = int(input())
C = list(map(int,input().split()))
S = [list(map(int,input().split())) for i in range(D)]

INF = float('inf')
DF = 7000
last = [0] * 26
cur_ans = []
nexts = []
for i,s in enumerate(S):
    best_k = -1
    best_score = -INF
    scores = []
    for k,s in enumerate(s):
        score = s
        for j,c in enumerate(C):
            if j==k: continue
            score -= c * (i+1 - last[j])
        if score > best_score:
            best_score = score
            best_k = k
        scores.append((score,k))
    last[best_k] = i+1
    cur_ans.append(best_k + 1)
    for sc,k in scores:
        if k==best_k: continue
        if sc < best_score - DF: continue
        nexts.append((best_score-sc, i,k))
nexts.sort(key=lambda x:x[0])

def evaluate(ans):
    last = [0] * 26
    score = 0
    for i,(s,a) in enumerate(zip(S,ans)):
        score += s[a-1]
        last[a-1] = i+1
        for j,c in enumerate(C):
            score -= c * (i+1 - last[j])
    return score + 10**6

cur_score = evaluate(cur_ans)
selects = [-1] * D
for _,ni,nk in nexts:
    if selects[ni] >= 0: continue
    last = [0] * 26
    ans = []
    for i,s in enumerate(S):
        if selects[i] >= 0:
            last[selects[i]] = i+1
            ans.append(selects[i] + 1)
            continue
        if i==ni:
            last[nk] = i+1
            ans.append(nk + 1)
            continue
        best_k = -1
        best_score = -INF
        for k,s in enumerate(s):
            score = s
            for j,c in enumerate(C):
                if j==k: continue
                score -= c * (i+1 - last[j])
            if score > best_score:
                best_score = score
                best_k = k
        last[best_k] = i+1
        ans.append(best_k + 1)
    sc = evaluate(ans)
    if sc > cur_score:
        cur_score = sc
        cur_ans = ans
        selects[ni] = nk
    if time() - start_time > 1.99:
        break

print(*cur_ans, sep='\n')

### FIXED CODE ###

for i in range(365):
    print(1)
### BUGGY CODE ###

R, G, B, N = map(int,input().split())

i = 0
j = 0
cnt = 0

while i*R <= N:
    while i*R + j*G <= N:
        if (N - i*R - j*G) % B == 0:
            cnt += 1
        j += 1
    j = 0
    i += 1

print(cnt)

### FIXED CODE ###

R, G, B, N = map(int,input().split())
 
i = 0
j = 0
cnt = 0
 
while i*R <= N:
    while i*R + j*G <= N:
        temp = N - i*R - j*G
        if temp % B == 0:
            cnt += 1
        j += 1
    j = 0
    i += 1
 
print(cnt)
### BUGGY CODE ###

N,K = map(int, input().split())
A = list(map(int, input().split()))

dp = [0] * (N+1)

for i in range(K,N+1):

    if i == K:
        temp = 1
        for j in range(K):
            temp *= A[i-1-j]
        dp[i] = temp
        continue

    dp[i] = int(dp[i-1] / A[i-1-K] * A[i-1])
    if i > K:
        if dp[i-1] < dp[i]:
            print('Yes')
        else:
            print('No')




### FIXED CODE ###

N,K = map(int, input().split())
A = list(map(int, input().split()))

for i in range(K, N):
    if A[i] > A[i-K]:
        print('Yes')
    else:
        print('No')
### BUGGY CODE ###

n,k=map(int,input().split())
a=list(map(int,input().split()))

now=1
visited=[1]

for i in range(k):
  now=a[now-1]
  if now in visited:
    for j in range(1,len(visited)+1):
      if visited[-j]==now:
        t=j
        for i in range(((k-(len(visited)-j))%t)):
          now=a[now-1]
        print(now)
        exit()
  
  visited.append(now)
        
print(now)

### FIXED CODE ###

n,k=map(int,input().split())
a=list(map(int,input().split()))

now=0
visited=set()
visited.add((0))
visited2=[0]


while True:
  k-=1
  now=a[now]-1

  if k==0:
    print(now+1)
    exit()

  
  if now in visited:
    visited.add((now))
    visited2.append(now)
    break

  visited.add((now))
  visited2.append(now)


xxx=visited2[-1]
cnt=[]
for i in range(len(visited2)):
  if visited2[i]==xxx:
    cnt.append(i)


k%=cnt[1]-cnt[0]


if k!=0:
  for i in range(k):
    now=a[now]-1
  

print(now+1)
### BUGGY CODE ###

def solve():
    #start here
    n, k = map(int, input().split())
    h = list(map(int, input().split()))
    dp = [0 for i in range(n)]
    for i in range(1, n):
        x = float('inf')
        for j in range(1, 1 + min(k, i)):
            x = min(x, dp[i-j] + abs(h[i]-h[i-j]))
        dp[i] = x
    print(dp[n-1])
 
solve()

### FIXED CODE ###

def solve():
    #start here
    n, k = map(int, input().split())
    h = list(map(int, input().split()))
    dp = [0 for i in range(n)]
    for i in range(1, n):
        x = float('inf')
        for j in range(1, 1 + min(k, i)):
            x = min(x, dp[i-j] + abs(h[i]-h[i-j]))
        dp[i] = x
    print(dp[n-1])

solve()
### BUGGY CODE ###

import sys
sys.setrecursionlimit(10**6)

n, q = map(int, input().split())

tree = [[] for _ in range(n)]

for i in range(n-1):
    a, b = map(int, input().split())
    tree[a-1].append(b-1)
    tree[b-1].append(a-1)

add = [0] * n

for i in range(q):
    p, x = map(int, input().split())
    add[p-1] += x

ans = [0] * n

def dfs(v, p, value):
    value += add[v]
    ans[v] = value
    for c in tree[v]:
        if c == p:
            continue
        dfs(c, v, value)

dfs(0, -1, 0)

print(*ans)

### FIXED CODE ###

import sys
sys.setrecursionlimit(10**6)
input = sys.stdin.readline

n, q = map(int, input().split())

tree = [[] for _ in range(n)]

for i in range(n-1):
    a, b = map(int, input().split())
    tree[a-1].append(b-1)
    tree[b-1].append(a-1)

add = [0] * n

for i in range(q):
    p, x = map(int, input().split())
    add[p-1] += x

ans = [0] * n

def dfs(v, p, value):
    value += add[v]
    ans[v] = value
    for c in tree[v]:
        if c == p:
            continue
        dfs(c, v, value)

dfs(0, -1, 0)

print(*ans)
### BUGGY CODE ###

from collections import defaultdict,deque
import sys,heapq,bisect,math,itertools,string,queue,copy,time
sys.setrecursionlimit(10**8)
INF = float('inf')
mod = 10**9+7
eps = 10**-7
def inp(): return int(sys.stdin.readline())
def inpl(): return list(map(int, sys.stdin.readline().split()))
def inpl_str(): return list(sys.stdin.readline().split())

# In[]:
N = inp()
xx = inpl()

# N = 3
# xx = 1,2,3

# In[]:
aa = [1]
fac = 1
for L in range(2,N):
    fac *= L-1
    naa = [fac]*L
    for i in range(L):
        if i < L-1:
            naa[i] += (L-i-1)*aa[i]
        if 1 <= i:
            naa[i] += (i+1)*aa[i-1]
        naa[i] %= mod

    aa = naa[:]
    # print(aa)

# print(aa)

# In[]:
dx = [xx[i]-xx[i-1] for i in range(1,N)]
# print(dx)

# In[]:
ans = 0
# print(aa)
# print(dx)
for a,d in zip(aa,dx):
    ans += a*d

print(ans%mod)


### FIXED CODE ###

mod = 10**9+7

# N = 15
N = int(input())
xx = list(map(int, input().split()))

a = 1
for i in range(2,N):
    a *= i
    a %= mod

aa = [a]
for i in range(N-2):
    aa.append((aa[-1]+a*pow(i+2,mod-2,mod))%mod)


dx = [xx[i]-xx[i-1] for i in range(1,N)]

ans = 0
for a,d in zip(aa,dx):
    ans += a*d
    ans %= mod

print(ans%mod)
### BUGGY CODE ###

N=int(input())
a=input().split(' ')
s=1
for i in range(N):
    s*=int(a[i])
if s<=10**18:
    print(s)
else:
    print("-1")

### FIXED CODE ###

import sys
N=int(input())
a=list(map(int, input().split()))
s=1
# aに0がある場合を省く
if 0 in a:
    print(0)
    sys.exit()
else:
# sが10^18になったら打ち切る
    for i in a:
        if s<10**18:
            s*=i
    if s>10**18:
        print(-1)
        sys.exit()
    print(s)
### BUGGY CODE ###

from numpy.linalg import solve
n = int(input())
a = list(map(int, input().split()))

left = [[0] * n for _ in range(n)]
right = list(map(lambda x: x * 2, a))
for i in range(0, n):
    left[i][i] = 1
    left[i][(i+1)%n] = 1
b = solve(left, right)
print(*list(map(int, b)))

### FIXED CODE ###

n = int(input())
a = list(map(int, input().split()))

b = [0] * n
b[0] = sum(a) - 2 * sum(a[1::2])

for i in range(1, n):
    b[i] = 2 * a[i-1] - b[i-1]

print(*b)
### BUGGY CODE ###


N = int(input())
L = list(map(int, input().split()))
L = sorted(L)

x = 0

for i in range(len(L)):
    for j in range(i+1, len(L)):
        for k in range(j+1, len(L)):
            if (L[k] < L[i] + L[j]):
                if (L[i] < L[j] + L[k]):
                    if  (L[j] < L[k] + L[i]):
                        x += 1
            else:
                break
        
print(x)

### FIXED CODE ###

import bisect

n = int(input())
l = list(map(int, input().split()))
l = sorted(l)

cnt = 0
for i in range(n-1):
    for j in range(i+1,n):
        up = l[j] + l[i]
        #l[k] = up となるようなkのうち最小のものを見つけろ
        k = bisect.bisect_left(l, up)
        cnt += k - j - 1
print(cnt)
### BUGGY CODE ###


def main():
    import sys
    import time
    input = sys.stdin.buffer.readline
    start = time.time()
    N = int(input())
    A = [tuple(map(int, input().split())) for i in range(N)]

    id = [0]*N
    Lock = [-1]*N
    ans = 0
    min_id = 0
    M = (N*(N-1)) // 2

    while(min_id < N-1):
        now = time.time()
        if now - start > 2000:
            ans = M+1
            break
        ans += 1
        if ans > M:
            break
        tmp = set()
        for i in range(N):
            if id[i] >= N-1:
                continue
            else:
                if Lock[i] >= 0:
                    continue
                else:
                    a = A[i][id[i]]
                    if Lock[a-1] == i and i not in tmp:
                        Lock[a-1] = -1
                        id[a-1] += 1
                        tmp.add(a-1)
                        id[i] += 1
                    else:
                        if i not in tmp:
                            Lock[i] = A[i][id[i]]-1
        min_id = min(id)
    if ans > M:
        print(-1)
    else:
        print(ans)


main()


### FIXED CODE ###

def main():
    import sys
    import time
    input = sys.stdin.buffer.readline
    start = time.time()
    N = int(input())
    A = [tuple(map(int, input().split())) for i in range(N)]

    id = [0]*N
    Lock = [-1]*N
    ans = 0
    min_id = 0
    M = (N*(N-1)) // 2

    while(min_id < N-1):
        now = time.time()
        if now - start > 1.9:
            ans = M
            break
        ans += 1
        if ans > M:
            break
        tmp = set()
        for i in range(N):
            if id[i] >= N-1:
                continue
            else:
                if Lock[i] >= 0:
                    continue
                else:
                    a = A[i][id[i]]
                    if Lock[a-1] == i and i not in tmp:
                        Lock[a-1] = -1
                        id[a-1] += 1
                        tmp.add(a-1)
                        id[i] += 1
                    else:
                        if i not in tmp:
                            Lock[i] = A[i][id[i]]-1
        min_id = min(id)
    if ans > M:
        print(-1)
    else:
        print(ans)


main()
### BUGGY CODE ###

N, Y = map(int, input().split())

coins = [10000, 5000, 1000]

ans = []
def dfs(sum_v, now, i):
    if len(ans) != 0:
        return

    used = sum(now)

    if len(now) == 3:
        if sum_v == Y:
            ans.append(now)
        return

    if sum_v + coins[i] * (N - used) < Y:
        return

    if i == 2:
        ne = now + [N - used]
        dfs(sum_v + coins[i] * (N - used), ne, i + 1)
    else:
        for j in range(N - used + 1):
            ne = now + [j]
            dfs(sum_v + coins[i] * j, ne, i + 1)

dfs(0, [], 0)
if len(ans) == 0:
    print("-1 -1 -1")
else:
    print(" ".join(map(str, ans[0])))


### FIXED CODE ###

N, Y = map(int, input().split())

coins = [10000, 5000, 1000]

ans = []
def dfs(sum_v, now, i):
    if len(ans) != 0:
        return

    used = sum(now)

    if len(now) == 3:
        if sum_v == Y:
            ans.append(now)
        return

    if sum_v + coins[i] * (N - used) < Y:
        return

    if sum_v > Y:
        return

    if i == 2:
        ne = now + [N - used]
        dfs(sum_v + coins[i] * (N - used), ne, i + 1)
    else:
        for j in range(N - used + 1):
            ne = now + [j]
            dfs(sum_v + coins[i] * j, ne, i + 1)

dfs(0, [], 0)
if len(ans) == 0:
    print("-1 -1 -1")
else:
    print(" ".join(map(str, ans[0])))
### BUGGY CODE ###

import sys
from collections import deque


def input():
    return sys.stdin.readline()[:-1]


def main():
    S = input()
    Q = int(input())
    que = deque(S)
    for i in range(Q):
        q = list(input().split())
        if len(q) == 1:
            que.reverse()
        else:
            _, f, c = q
            if f == '1':
                que.appendleft(c)
            else:
                que.append(c)
    print("".join(list(que)))


if __name__ == "__main__":
    main()


### FIXED CODE ###

import sys
from collections import deque


def input():
    return sys.stdin.readline()[:-1]


def main():
    S = input()
    Q = int(input())
    que = deque(S)
    rev = 0
    for i in range(Q):
        q = input()
        if q[0] == '1':
            # que.reverse()
            rev += 1
        else:
            _, f, c = q.split()
            if rev % 2 == 0:
                if f == '1':
                    que.appendleft(c)
                else:
                    que.append(c)
            else:
                if f == '1':
                    que.append(c)
                else:
                    que.appendleft(c)
    if rev % 2 == 1:
        que.reverse()
    print("".join(list(que)))


if __name__ == "__main__":
    main()
### BUGGY CODE ###

from heapq import heappush, heappop
from collections import deque

N,K = map(int,input().split())
V = list(map(int,input().split()))

ans = 0

for i in range(K+1):
    for l in range(i+1):
        for r in range(i+1-l):
            j = min(i-r-l,r+l)
            hq = []
            dq = deque(V)
            for _ in range(l):
                if dq:
                    item = dq.popleft()
                    heappush(hq, item)
            for _ in range(r):
                if dq:
                    item = dq.pop()
                    heappush(hq, item)
            for _ in range(j):
                if hq:
                    heappop(hq)
            res = sum(hq)
            ans = max(ans,res)
        
print(ans)

### FIXED CODE ###

from heapq import heappush, heappop
from collections import deque

N,K = map(int,input().split())
V = list(map(int,input().split()))

ans = 0

for i in range(K+1):
    sup = min(i,N)
    for l in range(sup+1):
        for r in range(sup+1-l):
            j = min(i-r-l,r+l)
            hq = []
            dq = deque(V)
            for _ in range(l):
                item = dq.popleft()
                heappush(hq, item)
            for _ in range(r):
                item = dq.pop()
                heappush(hq, item)
            for _ in range(j):
                heappop(hq)
            res = sum(hq)
            ans = max(ans,res)

print(ans)
### BUGGY CODE ###

#!/usr/bin/env python3
import sys

YES = "Yes"
NO = "No"

N,K = list(map(int, input().split()))
A = list(map(int, input().split()))

def prod(A):
    ans = A[0]
    for i in range(1,len(A)):
        ans = ans * A[i]
    return ans

scores = [0] * K
pre = 0
i = 0
while i < K:
    scores[i] = A[i]
    i += 1

pre = prod(scores)

while i < N:
    cur = pre
    cur = cur / scores[i % K]
    cur = cur * A[i]
    scores[i % K] = A[i]

    if cur > pre:
        print(YES)
    else:
        print(NO)
    pre = cur
    i += 1


### FIXED CODE ###

#!/usr/bin/env python3
import sys

YES = "Yes"
NO = "No"

N,K = list(map(int, input().split()))
A = list(map(int, input().split()))

scores = [0] * K
scores[0] = A[0]
i = 1
while i < K:
    scores[i] = A[i]
    i += 1

while i < N:
    if A[i] > scores[i % K]:
        print(YES)
    else:
        print(NO)
    scores[i % K] = A[i]
    i += 1
### BUGGY CODE ###

import math
n=int(input())
for i in range(1,n+1):
    nn=int(math.sqrt(i))
    min=int((nn+1)/3)
    min1=int((nn+1)/2)
    count=0
    for x in range(1,min+1):
        for y in range(x,min1+1):
            for z in range(y,nn+1):
                #print(x*x+y*y+z*z+x*y+y*z+z*x)
                if (x*x+y*y+z*z+x*y+y*z+z*x)==i:
                    if x==y and y==z and z==y:
                        count=count+1
                    elif x!=y and y!=z and z!=y:
                        count=count+6
                    else:
                        count=count+3
    print(count)


### FIXED CODE ###

import math
n=int(input())
for i in range(1,n+1):
    nn=int(math.sqrt(i))
    min=int((nn+1)/math.sqrt(3))
    min1=int((nn+1)/math.sqrt(2))
    count=0
    for x in range(1,min+1):
        for y in range(x,min1+1):
            for z in range(y,nn+1):
                #print(x*x+y*y+z*z+x*y+y*z+z*x)
                if (x*x+y*y+z*z+x*y+y*z+z*x)==i:
                    if x==y and y==z and z==x:
                        count=count+1
                    elif x!=y and y!=z and z!=x:
                        count=count+6
                    else:
                        count=count+3
    print(count)
### BUGGY CODE ###

import sys
input = sys.stdin.readline

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

    tmp=[0,0,0]
    cnt=0
    for i in range(0,1000):
        if i < 10:
            tmp[0]=0
            tmp[1]=0
            tmp[2]=i
        elif i < 100:
            tmp[0]=0
            tmp[1]=i//10
            tmp[2]=i-tmp[1]*10
        else:
            tmp[0]=i//100
            tmp[1]=(i-tmp[0]*100)//10
            tmp[2]=i-tmp[0]*100-tmp[1]*10
        ketaflg=0
        for j in range(0,n):
            if tmp[0]==int(s[j]) and ketaflg==0:
                ketaflg=1
            elif tmp[1]==int(s[j]) and ketaflg==1:
                ketaflg=2
            elif tmp[2]==int(s[j]) and ketaflg==2:
                ketaflg=3
                break
        if ketaflg==3:
            cnt+=1
    print(cnt)


if __name__=='__main__':
    main()


### FIXED CODE ###

import sys

def main():
    # input = sys.stdin.readline

    n=int(input())
    s=list(map(int,input()))
    # s.pop(-1)
    cnt=0
    for i in range(10):
        if i in s[:-2]:
            idx1=s[:-2].index(i)
            for j in range(10):
                if j in s[idx1+1:-1]:
                    idx2=s[idx1+1:-1].index(j)+idx1+1
                    for k in range(10):
                        if k in s[idx2+1:]:
                            cnt+=1
    print(cnt)

    #
    # tmp=[0,0,0]
    # cnt=0
    # for i in range(0,1000):
    #     if i < 10:
    #         tmp[0]=0
    #         tmp[1]=0
    #         tmp[2]=i
    #     elif i < 100:
    #         tmp[0]=0
    #         tmp[1]=i//10
    #         tmp[2]=i-tmp[1]*10
    #     else:
    #         tmp[0]=i//100
    #         tmp[1]=(i-tmp[0]*100)//10
    #         tmp[2]=i-tmp[0]*100-tmp[1]*10
    #     ketaflg=0
    #     for j in s :
    #         if j == '\n':
    #             break
    #         if tmp[0]==int(j) and ketaflg==0:
    #             ketaflg=1
    #         elif tmp[1]==int(j) and ketaflg==1:
    #             ketaflg=2
    #         elif tmp[2]==int(j) and ketaflg==2:
    #             ketaflg=3
    #             cnt+=1
    #             break
    # print(cnt)


if __name__=='__main__':
    main()
### BUGGY CODE ###

# Pypy3だとTLEになる。
from collections import defaultdict
import sys
sys.setrecursionlimit(10 ** 9)

N = int(input())
A = list(map(int,input().split()))

susicount = [0,0,0]
for a in A:
  susicount[a-1] += 1
#print(susicount)

# dp[i][j][k]:寿司3個のお皿がi枚、2個のがj枚、1個がk枚のときの期待値
# dp[i][j][k] = i/N * dp[i-1][j+1][k]
#             + j/N * dp[i][j-1][k+1]
#             + k/N * dp[i][j][k-1]
#             + (N-i-j-k)/N * dp[i][j][k]
#             + 1
# dp[i][j][k]を移項すると、
# dp[i][j][k] = 1/(i+j+k) * (i * dp[i-1][j+1][k]
#                          + j * dp[i][j-1][k+1]
#                          + k * dp[i][j][k-1]
#                          + N)
dp = [[[-1 for _ in range(N+1)] for _ in range(N+1)] for _ in range(N+1)]

def rec(i,j,k):
  if i == 0 and j == 0 and k == 0:
    return 0.0 # 型推論で時間がかからないように0ではなく0.0とする。
  if dp[i][j][k] != -1:
    return dp[i][j][k]
  res = 0.0 # 型推論で時間がかからないように0ではなく0.0とする。
  if i != 0:
    res += i * rec(i-1,j+1,k)
  if j != 0:
    res += j * rec(i,j-1,k+1)
  if k != 0:
    res += k * rec(i,j,k-1)
  res = (res+N)/(i+j+k)
  dp[i][j][k] = res
  return dp[i][j][k]

print(rec(susicount[2],susicount[1],susicount[0]))


### FIXED CODE ###

# 再帰関数を使うとTLEになるので、3重ループにしてみる。
from collections import defaultdict

N = int(input())
A = list(map(int,input().split()))

sushi = [0,0,0]
for a in A:
  sushi[a-1] += 1

# dp[i][j][k]:寿司3個のお皿がi枚、2個のがj枚、1個がk枚のときの期待値
# dp[i][j][k] = i/N * dp[i-1][j+1][k]
#             + j/N * dp[i][j-1][k+1]
#             + k/N * dp[i][j][k-1]
#             + (N-i-j-k)/N * dp[i][j][k]
#             + 1
# dp[i][j][k]を移項すると、
# dp[i][j][k] = 1/(i+j+k) * (i * dp[i-1][j+1][k]
#                          + j * dp[i][j-1][k+1]
#                          + k * dp[i][j][k-1]
#                          + N)
dp = [[[0.0 for _ in range(N+1)] for _ in range(N+1)] for _ in range(N+1)] # 型推論で時間がかからないように0ではなく0.0とする。

for i in range(N+1):
  for j in range(N+1):
    for k in range(N+1):
      if i+j+k > N or i+j+k == 0:
        continue
      if i>0:
        dp[i][j][k] += i * dp[i-1][j+1][k]
      if j>0:
        dp[i][j][k] += j * dp[i][j-1][k+1]
      if k>0:
        dp[i][j][k] += k * dp[i][j][k-1]
      dp[i][j][k] += N
      dp[i][j][k] /= (i+j+k)

print(dp[sushi[2]][sushi[1]][sushi[0]])