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

#coding: utf-8
from functools import reduce
def gcd(a, b):
    if b == 0:
        return a

    else:
        return gcd(b, a%b)
N, X = map(int, input().split())
x = list(map(int, input().split()))
x = [abs(X - x[i]) for i in range(N)]
l = [x[0]]
for i in range(len(x)):
    for j in range(1, len(x)):
        l.append(gcd(max(x[i], x[j]), min(x[i], x[j])))
print(min(l))

### FIXED CODE ###

#coding: utf-8
from functools import reduce
def gcd(a, b):
    if b == 0:
        return a
    else:
        return gcd(b, a%b)
N, X = map(int, input().split())
x = list(map(int, input().split()))
x = [abs(X - x[i]) for i in range(N)]
l = reduce(gcd, x)
print(l)
### BUGGY CODE ###

#n=int(input())
n,a,b=map(int,input().split())
#l=list(map(int,input().split()))
#l=[list(map(int,input().split())) for i in range(n)]

v=n//(a+b)
ans=v*a
mod=n%(a+b)

for i in range(min(mod,a)):
    ans+=1
print(ans)  

### FIXED CODE ###

#n=int(input())
n,a,b=map(int,input().split())
#l=list(map(int,input().split()))
#l=[list(map(int,input().split())) for i in range(n)]

v=n//(a+b)
ans=v*a
mod=n%(a+b)

temp=min(mod,a)
ans+=temp
print(ans)
### BUGGY CODE ###

from collections import deque
n=int(input())
commands=[input().split() for i in range(n)]
    
List=deque()
def command(list_command):
    global List
    if 'insert' in list_command:
        List.appendleft(list_command[1])
    elif 'delete' in list_command:
        try:
            List.remove(list_command[1])
        except:
            pass
    elif 'deleteFirst' in list_command:
        List.popleft()
    elif 'deleteLast' in list_command:
        List.pop()
    return True
    
for i in commands:
    command(i)
print(*List)

### FIXED CODE ###

from collections import deque
n=int(input())
commands=[input().split() for i in range(n)]
    
List=deque()
for list_command in commands:
    if 'insert' in list_command:
        List.appendleft(list_command[1])
    elif 'delete' in list_command:
        try:
            List.remove(list_command[1])
        except:
            pass
    elif 'deleteFirst' in list_command:
        List.popleft()
    elif 'deleteLast' in list_command:
        List.pop()
  
print(*List)
### BUGGY CODE ###

import sys

sys.setrecursionlimit(100000)

N = int(raw_input())
H = map(int, raw_input().split())

def sumOfCost(i):
  if i == 0:
    return 0
  elif i == 1:
    return sumOfCost(0)+abs(H[i]-H[0])
  else:
    c1 = sumOfCost(i-1)+abs(H[i]-H[i-1])
    c2 = sumOfCost(i-2)+abs(H[i]-H[i-2])
    return min(c1,c2)
print sumOfCost(N-1)




### FIXED CODE ###

import sys

sys.setrecursionlimit(100000)

N = int(raw_input())
H = map(int, raw_input().split())
cost = [-1]*N

def sumOfCost(i):
  if cost[i] >= 0:
    return cost[i]
  if i == 0:
    soc=0
  elif i == 1:
    soc= sumOfCost(0)+abs(H[i]-H[0])
  else:
    c1 = sumOfCost(i-1)+abs(H[i]-H[i-1])
    c2 = sumOfCost(i-2)+abs(H[i]-H[i-2])
    soc=min(c1,c2)
  cost[i] = soc
  return soc

print sumOfCost(N-1)
### BUGGY CODE ###

from functools import reduce
import operator
import heapq
def SME(start,end):
    A = []
    if end > N : end = N
    count = 0
    for i,x in enumerate(Whole[start:end]):
        heapq.heappush(A,[x,i])
    for j in range(start,end):
        a = heapq.heappop(A)
        for i in range(L):
            idx = a[1] + i
            try :
                if not ANS[idx]:
                    ANS[idx] = a[0]
                    count += 1
            except IndexError : continue
        if count > N * parameter : break
    for i in range(L):
        if not ANS[i] : ANS[i] = min(Whole[:i+1])
    for i in range(L,N):
        if not ANS[i] : ANS[i] = min(Whole[i+1-L:i+1])
    return ANS
 
[N,L] = [int(x) for x in input().split()]
Whole = [int(x) for x in input().split()]
parameter = 0.9905
INIT = None
ANS = [INIT]*N
ANS = SME(0, N)
for i in ANS[L-1:-1]:print(i, end=" ")
print(ANS[-1])

### FIXED CODE ###

def ascend(a,b):
    mini = min(A[a:a+L])
    ans[a] = mini
    for i in range(a+1,b):
        if A[i+L-1] <= mini : mini = A[i+L-1]
        elif A[i-1] == mini : mini = min(A[i:i+L])
        ans[i] = mini

def descend(a,b):
    mini = min(A[b-1:b+L-1])
    ans[b-1] = mini
    for i in range(b-2,a-1,-1):
        if A[i] <= mini : mini = A[i]
        elif A[i+L] == mini: mini = min(A[i:i+L])
        ans[i] = mini
    
[N,L] = [int(x) for x in input().split()]
A = [int(x) for x in input().split()]
ans = [None]*(N-L+1)
count = 0;
if N > 10 ** 4:
    for i in range(100):
        if A[i+1] > A[i] : count += 1
    if count > 80 : descend(0, N-L+1)
    else : ascend(0,N-L+1)
else :
    ascend(0, N-L+1)
for i in ans[:-1] : print(i, end=" ")
print(ans[-1])
### BUGGY CODE ###

# coding: utf-8
import numpy as np


def solve(*args: str) -> str:
    n = int(args[0])
    A = np.array([int(a) for a in args[1]])

    for i in range(n-1):
        A = np.abs(A[:-1]-A[1:])

    return str(A[0])


if __name__ == "__main__":
    print(solve(*(open(0).read().splitlines())))


### FIXED CODE ###

# coding: utf-8


def solve(*args: str) -> str:
    n = int(args[0])
    A = [ord(a)-48 for a in args[1]]

    A = [abs(A[i]-A[i+1]) for i in range(n-1)]
    r = 2 if A.count(1) == 0 else 1

    ret = 0
    for i in range(n-1):
        ret += (A[i]//r)*(n-2 == (i | (n-2-i)))

    return str((ret % 2)*r)


if __name__ == "__main__":
    print(solve(*(open(0).read().splitlines())))
### BUGGY CODE ###

N, K = map(int, input().split())
R, S, P = map(int, input().split())
T = input()

ans = 0
M = ''
for i in range(N):
	if i < K:
		if T[i] == 'r':
			ans += P
			M += 'r'
		if T[i] == 's':
			ans += R
			M += 's'
		if T[i] == 'p':
			ans += S
			M += 'p'
	elif M[i-K] != T[i]:
		if T[i] == 'r':
			ans += P
			M += 'r'
		if T[i] == 's':
			ans += R
			M += 's'
		if T[i] == 'p':
			ans += S
			M += 'p'
	else:
		M += 'x'
print(ans)

### FIXED CODE ###

N, K = map(int, input().split())
R, S, P = map(int, input().split())
T = input()

ans = 0
M = []
for i in range(N):
	if i >= K and M[i-K] == T[i]:
		M.append('x')
		continue
	else:
		if T[i] == 'r':
			ans += P
			M.append('r')
		if T[i] == 's':
			ans += R
			M.append('s')
		if T[i] == 'p':
			ans += S
			M.append('p')
print(ans)
### BUGGY CODE ###

n,w=map(int,input().split())
l=[list(map(int,input().split())) for _ in [0]*n]
dp=[0 for _ in range(w+1)]
for i in range(n):
    for j in range(w,l[i][0]-1,-1):
        dp[j]=max(dp[j],dp[j-l[i][0]]+l[i][1])
print(max(dp))

### FIXED CODE ###

n,w=map(int,input().split())
l=[list(map(int,input().split())) for _ in [0]*n]
dp=[0 for _ in range(w+1)]
for i in range(n):
    for j in range(w,l[i][0]-1,-1):
        dp[j]=max(dp[j],dp[j-l[i][0]]+l[i][1])
print(max(dp))
### BUGGY CODE ###

def main():
    n = int(input())
    A = list(map(int, input().split()))
    A.sort()
    D = [True] * n
    ans = 0

    for i, a in enumerate(A):
        if not D[i]:
            continue
        if i == n-1:
            ans += 1
            break
        if a != A[i+1]:
            ans += 1

        for j, aj in enumerate(A[i+1:]):
            if aj % a == 0:
                D[i+j+1] = False

    print(ans)


if __name__ == '__main__':
    main()


### FIXED CODE ###

def main():
    n = int(input())
    A = list(map(int, input().split()))
    A.sort()
    D = [True] * (10**6 + 1)
    ans = 0

    for i, a in enumerate(A):
        if not D[a]:
            continue
        if (i < n-1 and a != A[i+1]) or i == n-1:
            ans += 1

        j = a
        while (j < 10**6 + 1):
            D[j] = False
            j += a

    print(ans)


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

#coding: utf-8
import numpy as np
N, M = map(int, input().split())
AB = np.array([list(map(int, input().split())) for _ in range(N)])
money = 0
for i in range(M):
    money += AB[np.argmin(AB[:, 0]), 0]
    AB[np.argmin(AB[:, 0]), 1] -= 1
    if AB[np.argmin(AB[:, 0]), 1] == 0:
        AB[np.argmin(AB[:, 0]), 0] = 10e6
print(money)

### FIXED CODE ###

#coding: utf-8
import numpy as np
N, M = map(int, input().split())
AB = np.array([list(map(int, input().split())) for _ in range(N)])
money = 0
col_num = 0
AB = AB[np.argsort(AB[:, col_num])]
if M <= AB[np.argmin(AB[:, 0]), 1]:
    money += AB[0, 0] * M
else:
    i = 0
    while M > 0:
        money += AB[i, 0] * AB[i, 1]
        M -= AB[i, 1]
        if M <= 0:
          money += AB[i, 0] * M
        i += 1
print(money)
### BUGGY CODE ###

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

if b-a+1 >= 2*k:
    l = [i for i in range(a, b + 1)]
    ans = (sorted(l[:k] + l[-k:]))
else:
    ans = [i for i in range(a, b + 1)]

for i in ans:
    print(i)

### FIXED CODE ###

A, B, K = map(int, input().split())

l = [i for i in range(A, A + K) if i <= B]
li = l + [i for i in range(B - K + 1, B + 1) if i >= A]

for i in sorted(set(li)):
    print(i)
### BUGGY CODE ###

import math 
N, K=map(int,input().split())
#A = np.zeros(N)
A = list(map(int,input().split()))
A = list(map(lambda x: x -1 , A))
current_town = 0

K2 = K % math.factorial(N)

for i in range(K2):
    current_town = A[current_town]

print(current_town+1)


### FIXED CODE ###

import numpy as np
n, k=map(int,input().split())

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

 
s = list()
ord = np.full(n+1, -1)
c=1
l=0

v=1
while ord[v]==-1:
    ord[v]=len(s)
    s.append(v)
    v=a[v-1]
c=len(s)-ord[v]
l=ord[v]

if k<l:
    print(s[k])  
else:
    k-=l
    k%=c
    print(s[l+k])
### BUGGY CODE ###

N,W=map(int,input().split())
w=[0]*(N+1)
v=[0]*(N+1)
for i in range(1,N+1):
  w[i],v[i]=map(int,input().split())

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

for i in range(1,N+1):
  for j in range(1,W+1):
    #print("i=",i,"j=",j)
    #dp[i][j]=max(dp[i][j],dp[i-1][j])
    #if j-w[i]<0: continue
    #dp[i][j]=max(dp[i][j],dp[i-1][j-w[i]]+v[i])
    if j-w[i]<0:
      dp[i][j]=max(dp[i][j],dp[i-1][j])
    else:
      dp[i][j]=max(dp[i][j],dp[i-1][j],dp[i-1][j-w[i]]+v[i])

#print(dp)
print(dp[N][W])


### FIXED CODE ###

N,W=map(int,input().split())
w=[0]*(N+1)
v=[0]*(N+1)
for i in range(1,N+1):
  w[i],v[i]=map(int,input().split())

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

for i in range(1,N+1):
  for j in range(1,W+1):
    #print("i=",i,"j=",j)
    dp[i][j]=max(dp[i][j],dp[i-1][j])
    if j-w[i]<0: continue
    dp[i][j]=max(dp[i][j],dp[i-1][j-w[i]]+v[i])

#print(dp)
print(dp[N][W])
### BUGGY CODE ###

S = input()
ans = 0
A = [0] * 2020
A[0] = 1
for i in range(len(S)):
     x = int(S[-i-1:]) % 2019
     A[x] += 1

for i in A:
    ans += int(i * (i-1) / 2)

print(ans)

### FIXED CODE ###

p=d=2019
z=[0]*p
for i,j in enumerate(input()[::-1]):
	d=d+int(j)*pow(10,i,p)
	z[d%p]+=1
r=z[0]
for i in z:
	r+=i*(i-1)//2
print(r)
### BUGGY CODE ###

X, Y, Z, K = map(int, input().split())
A = list(map(int, input().split()))
B = list(map(int, input().split()))
C = list(map(int, input().split()))

A.sort(reverse=True)
B.sort(reverse=True)
C.sort(reverse=True)

max_b = max(B)
max_c = max(C)


summs_ab = []
summs = []
"""
for a in A:
    for b in B:
        summs_ab.append(a+b)
summs_ab.sort(reverse=True)
summs_ab = summs_ab[:min(3001, X*Y*Z+1)]

for c in C:
    for sab in summs_ab:
        summs.append(sab+c)
summs.sort(reverse=True)
"""
for a in A[:K]:
    if len(summs) >= K and a + max_b + max_c < summs[K-1]:
        break

    for b in B[:K]:
        if len(summs) >= K and a + b + max_c < summs[K-1]:
            break

        for c in C[:K]:
            summ = a + b + c
            if len(summs) >= K:
                min_sum = summs[K-1]    
                if summ < min_sum:
                    break
            summs.append(summ)
        summs.sort()
        summs.reverse()

for i in range(K):
    print(summs[i])

### FIXED CODE ###

x,y,z,k = map(int,input().split())
lisa = list(map(int,input().split()))
lisb = list(map(int,input().split()))
lisc = list(map(int,input().split()))
lisa.sort(reverse=True)
lisb.sort(reverse=True)
lisc.sort(reverse=True)
an = []
ans = []
for num in lisb:
    for nu in lisa:
        an.append(num+nu)
an.sort(reverse=True)
an = an[:min(3001,x*y*z+1)]
for num in lisc:
    for nu in an:
        ans.append(num+nu)
ans.sort(reverse=True)
for i in range(k):
    print(ans[i])
### BUGGY CODE ###

def main():
    import sys
    input = sys.stdin.readline
    sys.setrecursionlimit(10**6)
    n = int(input())
    a = list(map(int, input().split()))
    if(n % 2 == 0):
        for i in range(1, n, 2):
            if(a.count(i) != 2):
                print(0)
                exit(0)
        print(2**(n//2))
        exit(0)
    for i in range(0, n, 2):
        if(i == 0 and a.count(i) != 1):
            print(0)
            exit(0)
        elif(i != 0 and a.count(i) != 2):
            print(0)
            exit(0)
    print(2**(n//2))


if __name__ == '__main__':
    main()

### FIXED CODE ###

def main():
    import sys
    input = sys.stdin.readline
    sys.setrecursionlimit(10**6)
    n = int(input())
    a = list(map(int, input().split()))
    a.sort()
    # print(a)
    if(n % 2 == 0):
        for i in range(n-1):
            if i % 2 == 0 and a[i] != a[i+1] or i % 2 == 1 and a[i]+2 != a[i+1]:
                print(0)
                exit(0)
        print(2**(n//2) % (10**9+7))
        exit(0)
    if a[0] != 0:
        print(0)
        exit(0)
    for i in range(1, n-1):
        if i % 2 == 0 and a[i]+2 != a[i+1] or i % 2 == 1 and a[i] != a[i+1]:
            print(0)
            exit(0)
    print(2**((n-1)//2) % (10**9+7))
    exit(0)


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

import itertools

def primes(n):
    l = []
    i = 2
    while i <= n**(1/2):
        while n % i == 0:
            n //= i
            l.append(i)
        i += 1
    if n > 1:
        l.append(n)
    return l

def mul(l):
    result = 1
    for i in l:
        result *= i
    return result

n = int(input())

prime_list = primes(n)

i,j = 1,n
for m in range(len(prime_list)):
    cmb = set(itertools.combinations(prime_list, m))
    for c in cmb:
        s = mul(c)
        t = n//s
        if abs(s-t) < abs(i-j):
            i,j = s,t

print(i+j-2)


### FIXED CODE ###

import math

N = int(input())

ans = 10**15
for k in range(1, int(math.sqrt(N))+1):
    if N % k > 0:
        continue
    ans = min(ans, k + N//k - 2)
print(ans)
### BUGGY CODE ###

from collections import deque
n,m = map(int, input().split())
t = [[] for i in range(n)]
dis = [n for i in range(n)]
dis[0] = 0
near = [0 for i in range(n)]
q = deque()
for i in range(m):
    a,b = map(int, input().split())
    t[a-1].append(b-1)
    t[b-1].append(a-1)
for i in range(len(t[0])):
    dis[t[0][i]] = 1
    near[t[0][i]] = 0
    q.append(t[0][i])
while len(q) > 0:
    e = q.popleft()
    for j in range(len(t[e])):
        if dis[t[e][j]] >= dis[e] +1:
            dis[t[e][j]] = dis[e] +1
            near[t[e][j]] = e
            q.append(t[e][j])
print('Yes')
for i in range(1,len(near)):
    print(near[i]+1)


### FIXED CODE ###

from collections import deque
n,m = map(int, input().split())
t = [[] for i in range(n)]
near = [-1 for i in range(n)]
near[0] = 0
q = deque()
for i in range(m):
    a,b = map(int, input().split())
    t[a-1].append(b-1)
    t[b-1].append(a-1)
for i in range(len(t[0])):
    c = t[0][i]
    near[c] = 0
    q.append(c)
while len(q) > 0:
    e = q.popleft()
    for j in range(len(t[e])):
        c = t[e][j]
        if near[c] == -1:
            near[c] = e
            q.append(c)
print('Yes')
for i in range(1,len(near)):
    print(near[i]+1)
### BUGGY CODE ###

import numpy as np
n, m = map(int, input().split())
c = np.array([True for _ in range(n)])
for _ in range(m):
    l, r = map(int, input().split())
    l = np.array([i for i in range(l-1)])
    r = np.array([i for i in range(r, n)])
    if len(l) != 0:
        c[l] = False
    if len(r) != 0:
        c[r] = False
print(sum(c))

### FIXED CODE ###


n, m = map(int, input().split())
l = 1
r = n
for _ in range(m):
    a, b = map(int, input().split())
    l = max(a, l)
    r = min(b, r)
print(max(0, r - l + 1))
### BUGGY CODE ###

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

bit = [0] * 60
mod = 10 ** 9 + 7
ans = 0
for i in range(60):
    c = 0
    for j in range(n):
        c += int(a[j] & 1)
        a[j] //= 2
    ans = (ans + c * (n - c) * (2 ** i)) % mod

print(ans)

### FIXED CODE ###

import numpy as np
n = int(input())
a = np.array(list(map(int, input().split())))

bit = [0] * 60
mod = 10 ** 9 + 7
ans = 0
for i in range(60):
    n1 = np.count_nonzero((a >> i) & 1)
    n0 = n - n1
    ans += (2 ** i) * n1 * n0 % mod
print(ans % mod)
### BUGGY CODE ###

string=input()
length=len(string)
mod=[0]*2019
while length > 0:
  mod[int(string[length-1:])%2019]+=1
  length-=1
print(int(sum([(i*(i-1))/2 for i in mod]))+mod[0])


### FIXED CODE ###

string=input()
length=len(string)
mod=[1]+[0]*2018
s=0
for i in range(length):
  s=(s+int(string[-1-i])*pow(10,i,2019))%2019
  mod[s]+=1
print(sum([i*(i-1)//2 for i in mod]))
### BUGGY CODE ###

import bisect

n = int(input())
ans_head=[-1]
for i in range(n):
  a=int(input())
  if min(ans_head)>=a:
    ans_head.append(a)
  else:
    insert_index = bisect.bisect_left(ans_head,a)
    ans_head[insert_index-1]=a

  ans_head.sort()
  #print(ans_head)
print(len(ans_head))

### FIXED CODE ###

import bisect
n=int(input())
A=[]
for i in range(n):
  A.append(int(input()))
Ans=[A[-1]]
for i in reversed(range(n-1)):
  a=A[i]
  if a>=Ans[-1]:
    Ans.append(a)
  else:

    Ans[bisect.bisect_right(Ans,a)]=a

print(len(Ans))
### BUGGY CODE ###

N, M = map(int, input().split())
a = list(map(int, input().split()))
s = list(set(a))
N = len(a)
for k in range(N):
  a[k] //= 2


count = 0
foo = 1

while a[0]%2 == 0:
  foo *= 2
  a[0] // 2
for k in range(1, N):
  if a[k] % foo == 0 and a[k]%(2*foo) !=0:
    a[k] //= foo
    continue
  else:
    print(0)
    exit()
ans = 0

def euclid(a, b):
  while b:
    a, b = b, a%b
  return a

lcm = a.pop()
for k in range(1, N):
  b = a.pop()
  lcm = lcm * b // euclid(lcm, b)
  if lcm* foo > M:
    print(0)
    exit()
lcm *= foo
ans = int((M / lcm -1)//2 + 1)
print(ans)


### FIXED CODE ###

N, M = map(int, input().split())
a = list(map(int, input().split()))
for k in range(N):
  a[k] //= 2

foo = 1
while a[0]%2 == 0:
  foo *= 2
  a[0] //= 2
for k in range(1, N):
  if a[k] % foo == 0 and a[k]%(2*foo) !=0:
    a[k] //= foo
    continue
  else:
    print(0)
    exit()
ans = 0

import math
lcm = a.pop()
for k in range(1, N):
  b = a.pop()
  lcm = lcm * b // math.gcd(lcm, b)
  if lcm* foo > M:
    print(0)
    exit()
lcm *= foo
ans = int((M / lcm -1)//2 + 1)
print(ans)
### BUGGY CODE ###


S = input()
N1 = S.replace('A','0').replace('BC','1')
S_li = N1.split('B')

count = 0
for bigstr in S_li:
    if len(bigstr):
        li = bigstr.split('C')
        for l in li:
            if len(l):
                while True:
                    a = l.find('0')
                    if a<0:
                        break
                    bc = l.rfind('1')
                    if a < bc:
                        l = l[a+1:bc]
                        count += (bc-a)
                    else:
                        break

print(str(count))

### FIXED CODE ###

import re
S = input()
N1 = S.replace('A','0').replace('BC','1')
S_li = re.split('B|C',N1)
 
count = 0
for l in S_li:
    a = sum([i for i,x in enumerate(l) if '1' in x])
    su=sum([x for x in range(l.count('1'))])
    count += (a-su)
print(str(count))
### BUGGY CODE ###

  
n, x, y = map(int, input().split())
x -= 1
y -= 1
d= [[float('inf')]*n for _ in range(n)]
for i in range(n-1):
  if i == 0:
    d[0][1] = 1
    d[n-1][n-2] = 1
  else:
    d[i][i+1] = 1
    d[i][i-1] = 1
for i in range(n):
  d[i][i] = 0

d[x][y] = 1
d[y][x] = 1
def warshall_floyd(d):
  #d[i][j]: iからjへの最短距離
  for k in range(n):
    for i in range(n):
      for j in range(n):
        d[i][j] = min(d[i][j],d[i][k] + d[k][j])
  return d

d = warshall_floyd(d)
  
from collections import defaultdict
di = defaultdict(int)
for i in range(n):
  for j in range(i+1, n):
    di[d[i][j]] += 1 

for i in range(1, n):
  if i in di.keys():
    print(di[i])
  else:
    print(0)

### FIXED CODE ###

from collections import deque 
from collections import defaultdict
n, x, y = map(int, input().split())
graph = [[] for _ in range(n)]     
for i in range(n-1):
  graph[i] += [i+1]
  graph[i+1] += [i]
graph[x-1] += [y-1]
graph[y-1] += [x-1]
moves = ((1, 0), (0, 1), (0, -1), (-1, 0)) 

def bfs(s):
  dist = [float('inf')]*n
  dist[s] = 0
  q = deque([s])

  while q:
    u = q.popleft() 
    for v in graph[u]:
      if dist[v] == float('inf'):
        q += [v]
        dist[v] = dist[u] + 1

  return dist

ans = defaultdict(int)
for i in range(n):
  d = bfs(i)
  for j in range(i+1, n):
    ans[d[j]] += 1 

for i in range(1, n):
  if i in ans.keys():
    print(ans[i])
  else:
    print(0)
### BUGGY CODE ###

n=int(input())
c=list(input())
m=float('inf')
for i in range(n+1):
  x=max(c[:i].count('W'),c[i:].count('R'))
  if m>x:
    m=x
print(m)

### FIXED CODE ###

n = int(input())
c = input()
w = 0
r = c.count('R')
ans = r

for k in range(n):
  if c[k] == 'W':
    w += 1
  elif c[k] == 'R':
    r -= 1
  cnt = max(w, r)
  if ans > cnt:
    ans = cnt
print(ans)
### BUGGY CODE ###

import sys


INF = sys.maxsize

N, K = (int(x) for x in input().split())
heights = [int(x) for x in input().split()]

memo = [INF] * N

for i in range(N - 1, -1, -1):
  if i == N - 1:
    # ゴールからゴールの距離を0で初期化
    memo[i] = 0
    continue
  cost = INF
  for j in range(1, K + 1):
    # 範囲外
    if i + j >= N:
      continue
    cost = min(cost, memo[i + j] + abs(heights[i] - heights[i + j]))
  memo[i] = cost             

print(memo[0])


### FIXED CODE ###

import sys


INF = sys.maxsize

N, K = (int(x) for x in input().split())
heights = [int(x) for x in input().split()]

memo = [INF] * N

for i in range(N - 1, -1, -1):
  if i == N - 1:
    # ゴールからゴールの距離を0で初期化
    memo[i] = 0
    continue
  cost = INF
  for j in range(1, K + 1):
    # 範囲外
    if i + j >= N:
      continue
    cost = min(cost, memo[i + j] + abs(heights[i] - heights[i + j]))
  memo[i] = cost             

print(memo[0])
### BUGGY CODE ###

import bisect
import copy
import heapq
import math
import sys
from collections import *
from itertools import accumulate, combinations, permutations, product
# from math import gcd
from functools import lru_cache
def input():
    return sys.stdin.readline()[:-1]
def ruiseki(lst):
    return [0]+list(accumulate(lst))
sys.setrecursionlimit(5000000)
mod=pow(10,9)+7
al=[chr(ord('a') + i) for i in range(26)]
direction=[[1,0],[0,1],[-1,0],[0,-1]]

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

lst=[0]*3
for i in range(n):
    lst[a[i]-1]+=1

dp=[[[-1]*310 for i in range(310)] for j in range(310)]

# @lru_cache(maxsize=None)
def bfs(one, two, thr):
    if dp[one][two][thr]!=-1:
        return dp[one][two][thr]
    if one==two==thr==0:
        return 0
    tmp=1
    if one>0:
        tmp+=bfs(one-1,two,thr)*one/n
    if two>0:
        tmp+=bfs(one+1,two-1,thr)*two/n
    if thr>0:
        tmp+=bfs(one,two+1,thr-1)*thr/n
    
    tmp*=n/(one+two+thr)
    dp[one][two][thr]=tmp
    return tmp

print(bfs(lst[0],lst[1],lst[2]))

### FIXED CODE ###

import bisect
import copy
import heapq
import math
import sys
from collections import *
from itertools import accumulate, combinations, permutations, product
# from math import gcd
from functools import lru_cache
def input():
    return sys.stdin.readline()[:-1]
def ruiseki(lst):
    return [0]+list(accumulate(lst))
sys.setrecursionlimit(5000000)
mod=pow(10,9)+7
al=[chr(ord('a') + i) for i in range(26)]
direction=[[1,0],[0,1],[-1,0],[0,-1]]

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

lst=[0]*3
for i in range(n):
    lst[a[i]-1]+=1

dp=[[[0.0]*310 for i in range(310)] for j in range(310)]

for k in range(lst[2]+1):
    for j in range(lst[1]+lst[2]+1-k):
        for i in range(lst[0]+lst[1]+lst[2]+1-k-j):
            if i==j==k==0:
                continue
            tmp=1.0
            if i>0:
                tmp+=dp[i-1][j][k]*i/n
            if j>0:
                tmp+=dp[i+1][j-1][k]*j/n
            if k>0:
                tmp+=dp[i][j+1][k-1]*k/n
            
            tmp*=n/(i+j+k)

            dp[i][j][k]=tmp

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