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

n = int(input())
x = list(map(int,input().split()))
y = sorted(x)
lx = len(x)
lxi = (lx-1)//2
for v in x:
    z = y.copy()
    z.remove(v)
    print (z[lxi])


### FIXED CODE ###

n = int(input())
x = list(map(int,input().split()))
y = sorted(x)
lidx = n//2
sidx = lidx-1
for v in x:
    if v <= y[sidx]:
        print (y[lidx])
    else:
        print (y[sidx])
### BUGGY CODE ###

#A問題
N,M = map(int,input().split())
A = []
mod = 1000000007
for i in range(M):
    A.append(int(input()))

sta = []
for i in range(N+1):
    if i == 0:
        sta.append(1)
    elif i == 1:
        sta.append(1)
    elif i == 2:
        sta.append(2)
    else:
        sta.append(sta[i-1]+sta[i-2])

row = []
now = 1
flag = 0
for i in range(N):
    I = i+1
    if i == 0:
        if I in A:
            now = 0
            flag = 1
        else:
            now+=1
    else:
        if I in A:
            if flag == 1:
                flag = 2
                break
            else:
                row.append(now)
                now = 0
                flag = 1
        else:
            flag = 0
            now+=1

if flag == 2:
    print(0)
else:
    row.append(now)
    ans = 1
    for r in row:
        ans = (ans*sta[r-1])%mod
    print(ans)

### FIXED CODE ###

#C問題
mod = 10**9+7
N,M = map(int,input().split())

step = []
for i in range(N+2):
    if i <= 1:
        step.append(1)
    elif i == 2:
        step.append(1)
    else:
        step.append(step[i-1]+step[i-2])
    
A = []
for j in range(M):
    A.append(int(input()))

stairs = []
flag = 0
old = -1
for a in A:
    if a-old == 1:
        flag = 1
        break
    else:
        stairs.append(a-old-1)
        old = a
stairs.append(N-old)

if flag == 1:
    print(0)
else:
    #print(stairs)
    ans = 1
    for s in stairs:
        ans*=step[s]
        
    print(ans%mod)
### BUGGY CODE ###

import math
from functools import reduce
k = int(input())
def gcd(*numbers):
    return reduce(math.gcd, numbers)
cnt = 0
for a in range(k):
    for b in range(k):
        for c in range(k):
            cnt = cnt + gcd(a+1,b+1,c+1)
print(cnt)


### FIXED CODE ###

import math

k = int(input())
cnt = 0
for a in range(k):
    for b in range(k):
        for c in range(k):
            cnt = cnt + math.gcd(math.gcd(a+1,b+1),c+1)
print(cnt)
### BUGGY CODE ###

import sys
import itertools

def can_be_composed(n, m, A):
	for i in range(1, n + 1):
		combination_list = list(itertools.combinations(A, i))
		for l in combination_list:
			if m == sum(l):
				return True

	return False

#fin = open("test.txt", "r")
fin = sys.stdin

n = int(fin.readline())
A = list(map(int, fin.readline().split()))
q = int(fin.readline())
m_list = list(map(int, fin.readline().split()))
for m in m_list:
	if can_be_composed(n, m, A):
		print("yes")
	else:
		print("no")

### FIXED CODE ###

import sys
#fin = open("test.txt", "r")
fin = sys.stdin

n = int(fin.readline())
A = list(map(int, fin.readline().split()))
q = int(fin.readline())
m_list = list(map(int, fin.readline().split()))

for m in m_list:
	can_compose = False
	s = [[] for i in range(n)] #s[i][m]??§???A[i]?????§???????´???§m????????????????????????????????????
	for i in range(n):
		s[i] = [False for i in range(m + 1)]

	for j in range(m + 1):
		if j == A[0]:
			s[0][j] = True
		else:
			s[0][j] = False
		
	if s[0][m]:
		can_compose = True
		
	if not can_compose:
		for i in range(1, n):
			for j in range(m + 1):
				if j == A[i]:
					s[i][j] = True
				elif s[i - 1][j]:
					s[i][j] = True
				else:
					if j - A[i] >= 0:
						s[i][j] = s[i - 1][j - A[i]]
			
			if s[i][m]:
				can_compose = True
				break

	if can_compose:
		print("yes")
	else:
		print("no")
### BUGGY CODE ###

n = int(input())
a = list(map(int, input().split()))
b = list(map(int, input().split()))
ans = 0
while True:
    cnt = 0
    for i in range(n):
        m = b[(i - 1) % n] + b[(i + 1) % n]
        if 0 < m < b[i] and a[i] < b[i]:
            cnt += (b[i] - a[i]) // m
            b[i] -= (b[i] - a[i]) // m * m
    ans += cnt
    if cnt == 0:
        break
print(ans if a == b else -1)

### FIXED CODE ###

n = int(input())
a = list(map(int, input().split()))
b = list(map(int, input().split()))
ans = 0
while True:
    cnt = 0
    for i in range(n):
        m = b[(i - 1) % n] + b[(i + 1) % n]
        if 0 < m < b[i] and a[i] < b[i]:
            cnt += (b[i] - a[i]) // m
            b[i] -= (b[i] - a[i]) // m * m
    ans += cnt
    if cnt == 0:
        break
print(ans if a == b else -1)
### BUGGY CODE ###

S=input()
n=len(S)
ans=[]
for i in range(n):
  cnt=0
  j=i
  while(S[j]=='A' or S[j]=='C' or S[j]=='G' or S[j]=='T'):
      cnt+=1
  ans.append(cnt)
print(max(ans))

### FIXED CODE ###

s=list(input())
cnt=0
ans=0
l=list("ATCG")
 
for i in s:
    if i in l:
        cnt+=1
        ans=max(ans,cnt)
    else:
        cnt=0
print(ans)
### BUGGY CODE ###

def a():
    N,M = map(int,input().split())
    B = list(map(lambda x: int(x)//2,input().split()))

    def gcd(n,m):
        while n:
            m,n = [n,m%n]
        return m

    su = 1
    for b in B:
        su *= b // gcd(su,b)

    for _ in filter(lambda x:(su//x)%2==0,B):
        return 0

    return M//su - M//(su*2)

print(a())

### FIXED CODE ###

def a():
    N,M = map(int,input().split())
    B = list(map(lambda x: int(x)//2,input().split()))

    def gcd(n,m):
        while n:
            m,n = [n,m%n]
        return m

    su = 1
    for b in B:
        su *= b // gcd(su,b)
        if su > M:
            return 0

    for _ in filter(lambda x:(su//x)%2==0,B):
        return 0

    return M//su - M//(su*2)

print(a())
### BUGGY CODE ###

import numpy as np


def main():
    N = int(input())
    A = np.array([])
    B = np.array([])
    for i in range(0, N):
        a, b = map(int, input().split())
        A = np.append(A, [a])
        B = np.append(B, [b])
    
    takahashi = 0
    aoki = 0
    # 足し算して一番大きいところからとる
    sum_AB = A + B
    l = sum_AB.argsort()[::-1]
    takahashi = sum([A[i] for i in [j for idx, j in enumerate(l) if idx % 2 == 0]])
    aoki = sum([B[i] for i in [j for idx, j in enumerate(l) if idx % 2 != 0]])

    print(int(takahashi - aoki))


main()


### FIXED CODE ###

import numpy as np


def main():
    N = int(input())
    A = []
    B = []
    for i in range(0, N):
        a, b = map(int, input().split())
        A.append(a)
        B.append(b)
    
    takahashi = 0
    aoki = 0
    # 足し算して一番大きいところからとる
    A = np.array(A)
    B = np.array(B)
    sum_AB = A + B
    l = sum_AB.argsort()[::-1]
    takahashi = sum([A[i] for i in [j for idx, j in enumerate(l) if idx % 2 == 0]])
    aoki = sum([B[i] for i in [j for idx, j in enumerate(l) if idx % 2 != 0]])

    print(int(takahashi - aoki))


main()
### BUGGY CODE ###

N = int(input())
S = input()
sum = 0
r = 0
g = 0
b = 0

for i in range(N):
    if S[i] == "R":
        r+=1
    elif S[i] == "G":
        g+=1
    else:
        b+=1

sum = r*g*b

for i in range(N):
    for j in range(N):
        try:
            a = S[i]
            b = S[i+j]
            c = S[i+2*j]
            if a!=b and b!=c and c!=a:
                sum -= 1
        except:
            continue

print(sum)

### FIXED CODE ###

N = int(input())
S = input()
sum = 0
r = 0
g = 0
b = 0

for i in range(N):
    if S[i] == "R":
        r+=1
    elif S[i] == "G":
        g+=1
    else:
        b+=1

sum = r*g*b

for i in range(N):
    for j in range((N-i)//2 +1):
        try:
            a = S[i]
            b = S[i+j]
            c = S[i+2*j]
            if a!=b and b!=c and c!=a:
                sum -= 1
        except:
            continue

print(sum)
### BUGGY CODE ###

N = int(input())
A = [int(x) for x in input().split(" ")]

from itertools import combinations

mod = 1000000007  # 丁度いい大きさの素数だけで意味は特にない。
s = 0
for c in combinations(A, 2):
    s += c[0] * c[1]

print(s % mod)

### FIXED CODE ###

N = int(input())
A = [int(x) for x in input().split(" ")]

from itertools import combinations

mod = 1000000007  # 丁度いい大きさの素数だけで意味は特にない。

s = 0
ans = 0
for n in A:
    s += n
    s %= mod

for i in range(N):
    s -= A[i]
    ans += A[i] * s
    ans %= mod

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

n = int(input())
a = list(map(int, input().split()))
b = []
c = []

for i in range(n):
    if i%2 == 0:
        b.insert(0, str(a[i]))
    else:
        b.append(str(a[i]))

if n%2 == 0:
    ans = b[::-1]
else:
    ans = b

ans = ' '.join(ans)
print(ans)

### FIXED CODE ###

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


if n%2 == 0:
    for i in range(n-1,-1,-2):
        print(a[i], end=' ')
    for i in range(0, n, 2):
        print(a[i], end=' ')
    
elif n%2 == 1:
    for i in range(n-1,-1,-2):
        print(a[i], end=' ')
    for i in range(1, n, 2):
        print(a[i], end=' ')
### BUGGY CODE ###

import collections
N = int(input())
S = [input() for _ in range(N)]

if len(S) == len(set(S)):
  [print(a) for a in sorted(S)]
else:
  c = collections.Counter(S)
  ans = sorted([i[0] for i in c.items() if i[1] == c.most_common()[0][1]])
  [print(a) for a in ans]


### FIXED CODE ###

import collections
N = int(input())
S = [input() for _ in range(N)]

if len(S) == len(set(S)):
  ans = S
else:
  ans = []
  c = collections.Counter(S)
  c_common = c.most_common()
  max_vote = c_common[0][1]
  for k in range(len(set(S))):
    if c_common[k][1]== max_vote:
      ans.append(c_common[k][0])
    else:
      break
[print(a) for a in sorted(ans)]
### BUGGY CODE ###

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

lis = [i for i in range(a,b+1)]

if a>0 and b>0:
  print("Positive")
  exit()
elif a<=0 and b>=0:
  print("Zero")
  exit()
elif a<0 and b<0:
  if (abs(a-b)+1)%2==0:
    print("Positive")
  else:
    print("Negative")

### FIXED CODE ###

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

if a>0 and b>0:
  print("Positive")
  exit()
elif a<=0 and b>=0:
  print("Zero")
  exit()
elif a==0 or b==0:
  print("Zero")
elif a<0 and b<0:
  if (abs(a-b)+1)%2==0:
    print("Positive")
    exit()
  else:
    print("Negative")
    exit()
### BUGGY CODE ###

N = int(input())
S = input()
ans = N
for i in range(N + 1):
	ans = min(ans, S[: i].count("#") + S[i:].count("."))
print(ans)


### FIXED CODE ###

N = int(input())
S = input()
A = [S.count(".")]
for i in range(N):
	if S[i] == "#":
		A.append(A[i] + 1)
	else:
		A.append(A[i] - 1)
print(min(A))
### BUGGY CODE ###

from collections import deque
n = int(input())
a = list(map(int, input().split()))
a.reverse()
mod = 7 + 10**9
leng = 61
data = [[0 for i in range(leng+1)]for j in range(n)]
#pre
for i in range(n):
    k = deque(bin(a[i]))
    k.reverse()
    k = list(k)
    for j in range(1, leng+1):
        if j - 1 >= len(k):
            data[i][j] = data[i - 1][j]
            continue
        if k[j - 1] == "1":
            data[i][j] = data[i - 1][j] + 1
        else:
            data[i][j] = data[i-1][j]
ans = 0
a.reverse()
data.reverse()
for i in range(n-1):
    k = deque(bin(a[i]))
    k.reverse()
    k.pop()
    k.pop()
    k = list(map(int, k))
    k = k + [0 for i in range(leng - len(k))]
    for j in range(leng):
        if k[j] == 1:
            ans += ((n - i - 1) - data[i+1][j+1]) * (2**j)
            ans %= mod
        else:
            ans += data[i+1][j+1] * (2**j)
            ans %= mod
print(ans)

### FIXED CODE ###

def main():
    import sys
    input = sys.stdin.readline
    n = int(input())
    a = list(map(int, input().split()))
    a.reverse()
    mod = 7 + 10**9
    leng = len(format(max(a), 'b'))
    bit_acc = [0 for i in range(leng)]
    for i in range(n):
        #先頭から二進数を0埋めした
        bit_data = format(a[i], 'b').zfill(leng)
        for j in range(leng):
            if bit_data[j] == '1':
                bit_acc[j] += 1
    ans = 0
    p = [pow(2,leng - 1 - j, mod) for j in range(leng)]
    for i in range(n):
        bit_data = format(a[i], 'b').zfill(leng)
        for j in range(leng):
            if bit_data[j] == '1':
                ans += (n - bit_acc[j]) * p[j]
            else:
                ans += bit_acc[j] * p[j]
            ans %= mod
    print((ans * 500000004) % mod)
if __name__ == "__main__":
    main()
### BUGGY CODE ###

ny = input().split()
n = int(ny[0])
y = int(ny[1])

ichiman = 0
gosen = 0
sen = 0
flg = False

for i in range(n+1):
	y1 = y
	if flg:
		break
	if y1 >= 10000 * i:
		y1 -= 10000 * i
	if y1 == 0 and i == n:
		ichiman = i
		flg = True
		break
	if y1 <= 0:
		break

	for j in range(n+1-i):
		y2 = y1
		if flg:
			break
		if y2 >= 5000*j:
			y2 -= 5000*j
		if y2 == 0 and i + j == n:
			ichiman = i
			gosen = j
			flg = True
			break
		if y2 <= 0:
			break

		for k in range(1, n+1-i-j):
			y3 = y2
			if y3 >= 1000*k:
				y3 -= 1000*k
			if y3 == 0 and i+j+k == n:
				ichiman = i
				gosen = j
				sen = k
				flg = True
				break
			if y3 <= 0:
				break


if not flg:
	ichiman = -1
	gosen = -1
	sen = -1

print(ichiman,gosen,sen)



### FIXED CODE ###

ny = input().split()
n = int(ny[0])
yen = int(ny[1])

ichiman = -1
gosen = -1
sen = -1
flg = False

for x in range(n + 1):
	if flg : break
	for y in range(n-x+1):
		if 10000*x + 5000*y + 1000*(n-x-y) == yen:
			flg = True
			ichiman = x
			gosen = y
			sen = n-x-y
			break

print(ichiman,gosen,sen)
### BUGGY CODE ###

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

c = [A.count(i) for i in uni]
coun = c[:]
c = [int((i*(i-1))/2) for i in c]
# print(c)
l = []
# print("+++++++++++++++")
for i in range(len(uni)):
    c_ = c[:]
    x = ((coun[i]-1)*(coun[i]-2))/2
    c_[i] = x
    # print(c_)
    l.append(int(sum(c_)))
# print(l)
ans = dict([[uni[i],l[i]] for i in range(len(l))])

# print(ans)
for i in range(N):
    print(ans[A[i]])


### FIXED CODE ###

import collections
N = int(input())
ai = list(map(int, input().split()))
c = collections.Counter(ai)
# print(c)
val=0
for i in c.values():
    val+=i*(i-1)//2

for i in range(len(ai)):
    b=c[ai[i]]
    print(val-b+1)
### BUGGY CODE ###

# input
N = int(input())
A = [int(input()) for _ in range(N)]

Paper = []

for i in range(N):
    if A[i] in Paper:
        Paper.remove(A[i]) 
    else:
        Paper.append(A[i])

print(len(Paper))


### FIXED CODE ###

# input
N = int(input())
A = [int(input()) for _ in range(N)]

A = sorted(A)
i = 0
ans = 0

while i < N:
    k = 1
    while (i + k) < N and A[i] == A[i + k]:
        k += 1
    if (k - 1) % 2 == 0:
        ans += 1
    i = i + k

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

n = int(input())
a = [int(input()) for i in range(n)]

record = []
index = 0
count = 0
tf = True
while True:
    index=a[index]-1
    record.append(index)
    if record.count(index) == 2:
        print(-1)
        tf = False
        break
    else:
        count += 1
        if index == 1:
            break
if tf:
    print(count)


### FIXED CODE ###

n = int(input())
a = [int(input()) for i in range(n)]

index = 0
count = 1
tf = False

while True:
  if a[index]==2:
    tf = True
    break
  else:
    index=a[index]-1
    if count == n:
      break
    else:
      count += 1
if tf:
    print(count)
else:
  print(-1)
### BUGGY CODE ###

a,b,c,k = map(int,input().split())
for i in range(1,k+1):
    temp1 = b+c
    temp2 = a+c
    temp3 = a+b
    a = temp1
    b = temp2
    c = temp3
ans = a - b
if (ans > 10^18):
    print('Unfair')
else:
    print(ans)


### FIXED CODE ###

a,b,c,k = map(int,input().split())
if (k % 2 == 0):
    ans = a-b
else:
    ans = b-a
if (ans > 10**18):
    print('Unfair')
else:
    print(ans)
### BUGGY CODE ###

#!/usr/bin/env python3
n = int(input())
s = input()

ans = n

for i in range(n):
    #Lより西にいて西を向いている人の数
    w = s[: i].count("W")

    #Lより東にいて東を向いている人の数
    e = s[i + 1 :].count("E")

    ans = min(ans, w + e)
print(ans)

### FIXED CODE ###

#!/usr/bin/env python3
n = int(input())
s = input()

lww = 0
lee = s[1:].count("E")
ans = lww + lee

for i in range(1, n):
    if s[i] == "E":
        lee -= 1
    if s[i - 1] == "W":
        lww += 1

    ans = min(ans, lee + lww)
    
print(ans)
### BUGGY CODE ###

n = int(input())
seq = [x for x in input().split(' ')]

b = []

for i in range(n):
    b.append(seq[i])
    c = []
    for j in range(i, -1, -1):
        c.append(b[j])
    
    b = c

print(' '.join(b))

### FIXED CODE ###

n = int(input())
seq = [x for x in input().split(' ')]

b = []

if n % 2 == 0:
    for j in range(n-1, -1, -2):
        b.append(seq[j])
    for i in range(0, n, 2):
        b.append(seq[i])

else:
    for j in range(n-1, -1, -2):
        b.append(seq[j])
    
    for i in range(1, n, 2):
        b.append(seq[i])

print(' '.join(b))
### BUGGY CODE ###

N = int(input())
s = list()
count = 0
for i in range(N):
  s.append(input())
  s[i] = sorted(s[i])
s.sort()
for i in range(N):
  for j in range(N):
    if s[i] == s[j] and i != j:
      count += 1
print(int(count/2))

### FIXED CODE ###

def conbi(n):
  return n*(n-1)/2
N = int(input())
s = list()
count = 0
ans = 0
for i in range(N):
  s.append(input())
  s[i] = sorted(s[i])
s.sort()
for i in range(N-1):
  if s[i] == s[i+1]:
    count += 1
  else:
    ans += conbi(count+1)
    count = 0
ans += conbi(count+1)
print(int(ans))
### BUGGY CODE ###

from  heapq import heappush, heappop, heapify

n,m,s,t=map(int,raw_input().split())

nl=[ [ ] for j in range(n+1) ] 

for i in range(m):
	u,v,a,b=map(int,raw_input().split())
	nl[u].append( (v,a,b) )
	nl[v].append( (u,a,b) )


def dij(v,type):
	d=[ float("inf") for i  in range(n+1)]
	d[v]=0

	Q=[]
	heappush(Q,v)

	while len(Q)>0:
		u=heappop(Q)
	#	print u, nl[u]
		for i in nl[u]:
			#print "i::",i
			v=i[0]
			yen=i[1]
			sunuku=i[2]
		#	print v,yen,sunuku,d
			if type=="y":alt=d[u]+yen
			elif type=="s":alt=d[u]+sunuku

			if d[v]> alt:
				d[v]=alt
				heappush(Q,v)
	return d

d_y=dij(s,"y")
d_s=dij(t,"s")

val=float("inf")

A=[]
for i in range(n,0,-1):
	tmp=d_y[i]+d_s[i]
	val=min(val, tmp)
	A.append(val)

for i in reversed(A):
	print 10**15-i


### FIXED CODE ###

import heapq
 
N,M,S,T = map(int,input().split())
S,T = S-1,T-1
src = [tuple(map(int,input().split())) for i in range(M)]
 
es = [[] for i in range(N)]
for u,v,a,b in src:
    u,v = u-1,v-1
    es[u].append((v,a,b))
    es[v].append((u,a,b))
 
INF = float('inf')
cy = [INF] * N
cy[S] = 0
hq = [(0,S)]
heapq.heapify(hq)
while hq:
    cost,v = heapq.heappop(hq)
    for to,a,b in es[v]:
        if cost + a >= cy[to]: continue
        cy[to] = cost + a
        heapq.heappush(hq, (cy[to],to))
 
cs = [INF] * N
cs[T] = 0
hq = [(0,T)]
heapq.heapify(hq)
while hq:
    cost,v = heapq.heappop(hq)
    for to,a,b in es[v]:
        if cost + b >= cs[to]: continue
        cs[to] = cost + b
        heapq.heappush(hq, (cs[to],to))
 
ans = [INF]
for i in reversed(range(N)):
    tmp = cs[i] + cy[i]
    ans.append(min(ans[-1],tmp))
 
for a in reversed(ans[1:]):
    print(10**15 - a)
### BUGGY CODE ###

N = int(input())

vs = []
adj = [[] for _ in range(N)]
v_index = dict()
for i in range(N-1):
    a, b = map(int, input().split())
    a -= 1
    b -= 1
    vs.append((a, b))
    vs.append((b, a))
    adj[a].append(b)
    adj[b].append(a)
    v_index[(a, b)] = i
    v_index[(b, a)] = i

M = int(input())
uvs = [tuple(map(int, input().split())) for _ in range(M)]

masks = []
for u, v in uvs:
    u -= 1
    v -= 1
    parent = [-1] * N
    stack = [u]
    while stack:
        node = stack.pop()
        if node == v:
            break

        for next_node in adj[node]:
            if parent[node] != next_node:
                parent[next_node] = node
                stack.append(next_node)
                
    mask = 0
    node = v
    while node != u:
        next_node = parent[node]
        i = v_index[(node, next_node)]
        mask |= 1 << i
        node = next_node
    masks.append(mask)

# print(masks)

ans = 0
for bits in range(1 << (N-1)):
    for mask in masks:
        if not bits & mask:
            break
    else:
        ans += 1

print(ans)

### FIXED CODE ###

N = int(input())

es = []
adj = [[] for _ in range(N)]
e_index = dict()
for i in range(N-1):
    a, b = map(int, input().split())
    a -= 1
    b -= 1
    es.append((a, b))
    es.append((b, a))
    adj[a].append(b)
    adj[b].append(a)
    e_index[(a, b)] = i
    e_index[(b, a)] = i

M = int(input())
uvs = [tuple(map(int, input().split())) for _ in range(M)]

edges = [0] * (N - 1)
for i, (u, v) in enumerate(uvs):
    u -= 1
    v -= 1
    parent = [-1] * N
    stack = [u]
    while stack:
        node = stack.pop()
        if node == v:
            break

        for next_node in adj[node]:
            if parent[node] != next_node:
                parent[next_node] = node
                stack.append(next_node)
             
    node = v
    while node != u:
        next_node = parent[node]
        index = e_index[(node, next_node)]
        edges[index] |= 1 << i
        node = next_node

dp = [0] * (1 << M)
dp[0] = 1
for e in edges:
    for i in range((1 << M) - 1, -1, -1):
        dp[i | e] += dp[i]

print(dp[-1])
### BUGGY CODE ###

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

    I = 0
    J = 0
    K = 0
    for a in A:
        if a == 1:
            I += 1
        elif a == 2:
            J += 1
        else:
            K += 1

    dp = [[[0] * (N + 1) for _ in range(N + 1)] for _ in range(N + 1)] 

    # def output(lst):
    #     for tmp in lst:
    #         print (tmp)

    for k in range(K + 1):
        for j in range(K + J + 1):
            for i in range(N + 1):
                if i == j == k == 0:
                    continue
                tmp = N / (i + j + k)
                if i > 0:
                    tmp += i / (i + j + k) * dp[k][j][i - 1]
                if j > 0 and i < N:
                    tmp += j / (i + j + k) * dp[k][j - 1][i + 1]
                if k > 0 and j < K + J:
                    tmp += k / (i + j + k) * dp[k - 1][j + 1][i]
                dp[k][j][i] = tmp

    print (dp[K][J][I])

    # output(dp)

if __name__ == '__main__':
    main()

### FIXED CODE ###

def main():
    import sys
    input = sys.stdin.readline
    N = int(input())
    A = tuple(map(int, input().split()))

    I = A.count(1)
    J = A.count(2)
    K = A.count(3)
    # for a in A:
    #     if a == 1:
    #         I += 1
    #     elif a == 2:
    #         J += 1
    #     else:
    #         K += 1

    dp = [[[0] * (N + 1) for _ in range(N + 1)] for _ in range(N + 1)] 

    # def output(lst):
    #     for tmp in lst:
    #         print (tmp)

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

    print (dp[K][J][I])

    # output(dp)

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

n = int(input())
s = list(input())[::-1]
result = 0
for i in range(1000):
    x = format(i, "03")
    j = 0
    p = 0
    while j < 3 and p < n:
        if s[p]==x[j]:
            j += 1
        p += 1
    if j==3:
        result += 1
print(result)

### FIXED CODE ###

n = int(input())
s = list(input())[::-1]
result = 0
for i in range(1000):
    x = format(i, "03")
    j = 0
    p = 0
    while p < n:
        if s[p]==x[j]:
            j += 1
            if j == 3:
                result += 1
                break
        p += 1

print(result)