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

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

costs = [float('inf') for _ in range(n)]
costs[0] = 0

for x in range(n):
    for y in range(x + 1, min(x + k + 1, n)):
        costs[y] = min(costs[y], costs[x] + abs(h[x] - h[y]))

print(costs[n - 1])

### FIXED CODE ###

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

costs = [float('inf') for _ in range(n)]
costs[0] = 0

for x in range(n):
    for y in range(x + 1, min(x + k + 1, n)):
        costs[y] = min(costs[y], costs[x] + abs(h[x] - h[y]))

print(costs[n - 1])
### BUGGY CODE ###

import sys
from collections import deque
input = sys.stdin.readline
n,m = map(int,input().split())
ab = [list(map(int,input().split())) for i in range(m)]
graph = [[] for i in range(n+1)]
for a,b in ab:
  graph[a].append(b)
s,t = map(int,input().split())
visited = [[-1,-1,-1] for i in range(n+1)]
que = deque([(s,0,0)])
while que:
  x,mod,cnt = que.popleft()
  visited[x][mod] = cnt
  if x == t and mod == 0:
    break
  for y in graph[x]:
    if visited[y][(mod+1)%3] == -1:
      que.append((y,(mod+1)%3,cnt+1))
print(visited[t][0]//3)

### FIXED CODE ###

import sys
from collections import deque
input = sys.stdin.readline
n,m = map(int,input().split())
ab = [list(map(int,input().split())) for i in range(m)]
graph = [[] for i in range(n+1)]
for a,b in ab:
  graph[a].append(b)
s,t = map(int,input().split())
visited = [[-1,-1,-1] for i in range(n+1)]
que = deque([(s,0,0)])
while que:
  x,mod,cnt = que.popleft()
  visited[x][mod] = cnt
  if x == t and mod == 0:
    break
  for y in graph[x]:
    if visited[y][(mod+1)%3] == -1:
      que.append((y,(mod+1)%3,cnt+1))
      visited[y][(mod+1)%3] = cnt+1
print(visited[t][0]//3)
### BUGGY CODE ###

N, K = map(int, input().split())
S = [list(map(int, input().split())) for _ in range(K)]

dp = [0] * (N + 1)
dp_sums = [0] * (N + 1)
dp[1] = dp_sums[1] = 1

for i in range(2,N+1):
    for l, r in S: 
        if i >= r + 1:
            dp[i] += dp_sums[i - l] - dp_sums[i - r - 1] 
            dp_sums[i] = dp_sums[i-1] + dp[i]
        elif i > l and i < r + 1:
            dp[i] += dp_sums[i - l] 
            dp_sums[i] = dp_sums[i-1] + dp[i]
        elif i <= l:
            dp_sums[i] = dp_sums[i-1] + dp[i]
        dp[i] %= 998244353
print(dp[N])

### FIXED CODE ###

N, K = map(int, input().split())
S = [list(map(int, input().split())) for _ in range(K)]

dp = [0] * (N + 1)
dp_sums = [0] * (N + 1)
dp[1] = dp_sums[1] = 1

for i in range(2,N+1):
    for l, r in S: 
        if i >= r + 1:
            dp[i] += dp_sums[i - l] - dp_sums[i - r - 1] 
            dp_sums[i] = dp_sums[i-1] + dp[i]
        elif i > l and i < r + 1:
            dp[i] += dp_sums[i - l] 
            dp_sums[i] = dp_sums[i-1] + dp[i]
        elif i <= l:
            dp_sums[i] = dp_sums[i-1] + dp[i]
    dp[i] %= 998244353
    dp_sums[i] %= 998244353
print(dp[N])
### BUGGY CODE ###

MOD = 10 ** 9 + 7
n, m = map(int, input().split())
s = list(map(int, input().split()))
t = list(map(int, input().split()))

dp = [0] * n
ndp = [0] * n
for tj in t:
    for i in range(n):
        ndp[i] = 0
    acc = 0
    for i, si in enumerate(s):
        if si == tj:
            ndp[i] = (dp[i] + acc + 1) % MOD
        else:
            ndp[i] = dp[i]
        acc = (acc + dp[i]) % MOD
    dp, ndp = ndp, dp
print((sum(dp) + 1) % MOD)


### FIXED CODE ###

MOD = 10 ** 9 + 7
n, m = map(int, input().split())
s = list(map(int, input().split()))
t = list(map(int, input().split()))

dp = [0] * n
ndp = [0] * n
for tj in t:
    for i in range(n):
        ndp[i] = 0
    acc = 0
    for i, si in enumerate(s):
        if si == tj:
            ndp[i] = (dp[i] + acc + 1) % MOD
        else:
            ndp[i] = dp[i]
        acc = (acc + dp[i]) % MOD
    dp, ndp = ndp, dp
print((sum(dp) + 1) % MOD)
### BUGGY CODE ###

n = int(input())
a = list(map(int, input().split()))
p =[]
for i in range(n) :
    p.append([i+1,a[i]])

r = ''
for i in range(n) :
    for j in range(n) :
        if p[j][1] == (i + 1) :
            r = r + ' ' + str(p[j][0])

print (r)

### FIXED CODE ###

n = int(input())
a = list(map(int, input().split()))
p =[]
for i in range(n) :
    p.append([i+1,a[i]])

p.sort(key=lambda x: x[1])
q = list(map(str,[x[0] for x in p]))
r = ' '.join(q)


print (r)
### BUGGY CODE ###

mon = 100
nen = 0
moku = int(input())

while mon < moku:
    mon = mon // 100
    nen += 1

print(nen)


### FIXED CODE ###

x = int(input())
nen = 0
a = 100
while a < x:
    a = int(a*1.01)
    nen += 1
print(nen)
### BUGGY CODE ###

import math
from functools import reduce


def gcd(*numbers):
    return reduce(math.gcd, numbers)


K = int(input())

hoge = []
for i in range(1, K + 1):
    for j in range(1, K + 1):
        for k in range(1, K + 1):
            hoge.append(gcd(i, j, k))

print(sum(hoge))


### FIXED CODE ###

import math
from functools import reduce

K = int(input())

sum = 0
for i in range(1, K + 1):
    for j in range(1, K + 1):
        for k in range(1, K + 1):
            sum += reduce(math.gcd, (i, j, k))

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

import functools
import operator
n = int(input())
l = input().split()
m = []
for i in range(n):
    m.append(int(l[i]))
ans = functools.reduce(operator.mul, m)
if ans <= 10**18:
    print(ans)
else:
    print(-1)


### FIXED CODE ###

n = int(input())
l = input().split()
ans = 1
T = True
for i in range(n):
    if l[i] == '0':
        ans = 0
        break
if ans != 0:
    for i in range(n):
        if ans <= 10**18:
            ans = ans * int(l[i])
        else:
            T = False
            break
if False:
    print(-1)
elif ans > 10**18:
    print(-1)
else:
    print(ans)
### BUGGY CODE ###

value = int(input())
have_array = input().split()
have_array = [int(x) for x in have_array]

value2 = int(input())
problem_array = input().split()
problem_array = [int(x) for x in problem_array]


error = True
for i in range(0, value2):
    if have_array.count(problem_array[i]) < problem_array.count(problem_array[i]):
        error = False
        break
print("YES" if error == True else "NO")

### FIXED CODE ###

n = int(input())
d_array = [int(x) for x in input().split()]
d_dict = {}
for d in d_array:
    d_dict.setdefault(d, 0)
    d_dict[d] += 1
m = int(input())
t_array = sorted([int(x) for x in input().split()])

try:
    for t in t_array:
        if d_dict[t] > 0:
            d_dict[t] -= 1
        else:
            print("NO")
            break
    else:
        print("YES")
except KeyError:
    print("NO")
    exit()
### BUGGY CODE ###

#!/usr/bin/env python3
import sys
rl = sys.stdin.buffer.readline
INF = sys.maxsize

N = int(rl())
PS = [tuple(map(int, rl().split())) for i in range(N)]

def bitcount(n):
  n = n - ((n >> 1) & 0x5555555555555555)
  n = (n & 0x3333333333333333) + ((n >> 2) & 0x3333333333333333)
  n = (n + (n >> 4)) & 0x0f0f0f0f0f0f0f0f
  n = n + (n >> 8)
  n = n + (n >> 16)
  n = n + (n >> 32)
  return n & 0x0000007f

def subsets(s):
  t = s
  while t >= 0:
    t &= s
    yield t
    t -= 1

# (x|y)cost[i][j] := 頂点の集合 i に路線が引かれているとき、j 番目の集落から路線までの最小距離
xcost = [[INF] * N for _ in range(1 << N)]
ycost = [[INF] * N for _ in range(1 << N)]
for i in range(1 << N):
  for j in range(N):
    xcost[i][j] = abs(PS[j][0])
    ycost[i][j] = abs(PS[j][1])
    for k in range(N):
      if ((i >> k) & 1) == 1:
        xcost[i][j] = min(xcost[i][j], abs(PS[j][0] - PS[k][0]))
        ycost[i][j] = min(ycost[i][j], abs(PS[j][1] - PS[k][1]))

# 計算結果の距離を歩行距離(= 距離 * 人口)にする
for i in range(1 << N):
  for j in range(N):
    xcost[i][j] = xcost[i][j] * PS[j][2]
    ycost[i][j] = ycost[i][j] * PS[j][2]

# x, y 座標に引かれた線路の引き方の組み合わせの中から最もコストが小さくなるものを求める
ans = [INF] * (N + 1)
for i in range(1 << N):
  size = bitcount(i)
  for j in subsets(i):
    cost = 0
    for k in range(N):
      # i に含まれていない頂点を合計する(i に含まれている頂点の歩行距離は常に０なので)
      if ((i >> k) & 1) == 0:
        cost += min(xcost[j][k], ycost[i-j][k])

    ans[size] = min(ans[size], cost)

# 結果出力
for a in ans:
  print(a)

### FIXED CODE ###

#!/usr/bin/env python3
import sys
rl = sys.stdin.buffer.readline
INF = sys.maxsize

N = int(rl())
PS = [tuple(map(int, rl().split())) for i in range(N)]

def bitcount(n):
  n = n - ((n >> 1) & 0x5555555555555555)
  n = (n & 0x3333333333333333) + ((n >> 2) & 0x3333333333333333)
  n = (n + (n >> 4)) & 0x0f0f0f0f0f0f0f0f
  n = n + (n >> 8)
  n = n + (n >> 16)
  n = n + (n >> 32)
  return n & 0x0000007f

def subsets(s):
  t = s
  while t >= 0:
    t &= s
    yield t
    t -= 1

# (x|y)cost[i][j] := 頂点の集合 i に路線が引かれているとき、j 番目の集落から路線までの最小距離
xcost = [[INF] * N for _ in range(1 << N)]
ycost = [[INF] * N for _ in range(1 << N)]
for i in range(1 << N):
  for j in range(N):
    xcost[i][j] = abs(PS[j][0])
    ycost[i][j] = abs(PS[j][1])
    for k in range(N):
      if ((i >> k) & 1) == 1:
        xcost[i][j] = min(xcost[i][j], abs(PS[j][0] - PS[k][0]))
        ycost[i][j] = min(ycost[i][j], abs(PS[j][1] - PS[k][1]))

# 計算結果の距離を歩行距離(= 距離 * 人口)にする
for i in range(1 << N):
  for j in range(N):
    xcost[i][j] = xcost[i][j] * PS[j][2]
    ycost[i][j] = ycost[i][j] * PS[j][2]

# x, y 座標に引かれた線路の引き方の組み合わせの中から最もコストが小さくなるものを求める
ans = [INF] * (N + 1)
for i in range(1 << N):
  size = bitcount(i)
  for j in subsets(i):
    cost = 0
    for k in range(N):
      # i に含まれていない頂点を合計する(i に含まれている頂点の歩行距離は常に０なので)
      if ((i >> k) & 1) == 0:
        cost += min(xcost[j][k], ycost[i-j][k])

    ans[size] = min(ans[size], cost)

# 結果出力
for a in ans:
  print(a)
### BUGGY CODE ###

N, P = map(int, input().split())
i = 2
ans = 1
while P > 1:
  x = 0
  while P % i == 0:
    x += 1
    P //= i
  ans *= i ** (x // N)
  i += 1
print(ans)

### FIXED CODE ###

N, P = map(int, input().split())
i = 2
ans = 1
while P > 1:
  if i * i > P:
    if N == 1:
      ans *= P
    break
  x = 0
  while P % i == 0:
    x += 1
    P //= i
  ans *= i ** (x // N)
  i += 1
print(ans)
### BUGGY CODE ###

#!/usr/bin/env python3
# -*- coding: utf-8 -*-


def main():
    n = int(input())
    p = list(map(int, input().split()))

    count = 0
    for i in range(0, n):
        for j in range(0, i + 1):
            if p[i] > p[j]:
                break
            elif j == i:
                count += 1
    print(count)


if __name__ == "__main__":
    main()


### FIXED CODE ###

#!/usr/bin/env python3
# -*- coding: utf-8 -*-


def main():
    n = int(input())
    p = list(map(int, input().split()))

    count = 0
    n_min = 0
    for i in range(0, n):
        if i == 0:
            count += 1
            n_min = p[i]
            continue
        if p[i] <= n_min:
            count += 1
            n_min = p[i]
    print(count)


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

m_d = list()    # 魔法移動距離
for i in range(-2, 3):
    for j in range(-2, 3):
        if (i,j) not in [(0,0),(-1,0),(0,-1),(1,0),(0,1)]:
            m_d += [(i,j)]

h, w = list(map(int, input().split()))
si, sj = list(map(int, input().split()))
ti, tj = list(map(int, input().split()))
s = [None] * h
for i in range(h):
    s[i] = input()

# 距離情報を一番遠い値で初期化
#import numpy as np
INF = int(1e9)
#dist = np.full((h+4, w+4), INF)
dist = [[INF for j in range(w+4)] for i in range(h+4)]

# マップ境界を壁で囲む
S = ['##{}##'.format(s_row) for s_row in s]
S = ['##{}##'.format('#' * (w+4))]*2 + S
S = S + ['##{}##'.format('#' * (w+4))]*2

# 01-BFS探索用キュー
from collections import deque
q = deque()

# 開始位置、終了位置を調整
si, sj = si+1, sj+1
ti, tj = ti+1, tj+1
dist[si][sj] = 0
q.append([si,sj])

while (len(q)>0):
    i, j = q.popleft()
    d = dist[i][j]
    for di, dj in [(-1,0),(0,-1),(1,0),(0,1)]:
        ni, nj = di+i, dj+j
        if (S[ni][nj]=='#'):
            continue # 壁
        if (dist[ni][nj]<=d):
            continue # 探索済みコスト以上
        dist[ni][nj] = d
        q.appendleft([ni,nj])

    for di, dj in m_d:
        ni, nj = di+i, dj+j
        if (S[ni][nj]=='#'):
            continue # 壁
        if (dist[ni][nj]<=d):
            continue # 探索済みコスト以上
        dist[ni][nj] = d+1
        q.append([ni,nj])

ans = dist[ti][tj]
if ans == INF:
    ans = -1
print(ans)


### FIXED CODE ###

h, w = list(map(int, input().split()))
si, sj = list(map(int, input().split()))
ti, tj = list(map(int, input().split()))
s = [None] * h
for i in range(h):
    s[i] = input()

# 移動Aで探索する方向
d_a = [(-1,0), (0,-1),(1,0),(0,1)]
# 移動Bで探索する方向
d_b = [ (i, j) for j in range(-2, 3) for i in range(-2, 3)]

# 距離情報を一番遠い値で初期化
#import numpy as np
INF = int(1e9)
#dist = np.full((h+2, w+2), INF)
dist = [[INF for j in range(w+2)] for i in range(h+2)]

# マップ境界と壁を距離0にして探索させない
for i in range(h+2):
    dist[i][0] = 0
    dist[i][-1] = 0
for j in range(w+2):
    dist[0][j] = 0
    dist[-1][j] = 0
for i in range(h):
    for j in range(w):
        if s[i][j]=='#': dist[i+1][j+1] = 0
#dist = [[INF for j in range(w)] for i in range(h)]

# 01-BFS探索用キュー
from collections import deque
q = deque()

# 開始位置
dist[si][sj] = 0
q.append((si,sj))

while (len(q)>0):
    i, j = q[0]
    d = dist[i][j]
    q.popleft()
    # 移動Aによるコスト
    for v in range(len(d_a)):
        di, dj = d_a[v][0]+i, d_a[v][1]+j
        if (di, dj) == (ti, tj):
            print(d)
            exit(0)
        if (dist[di][dj]<=d):
            continue # 探索済みコスト以上
        dist[di][dj] = d
        q.appendleft((di, dj))
    # 移動Bによるコスト
    for v in range(len(d_b)):
        # マップ境界で2以上移動したときに、反対の境界に向かうように剰余を取る
        di, dj = (d_b[v][0]+i)%(h+2), (d_b[v][1]+j)%(w+2)
        if (dist[di][dj]<=d):
            continue # 探索済みコスト以上
        dist[di][dj] = d+1
        q.append((di, dj))

ans = dist[ti][tj]
if ans == INF:
    ans = -1
print(ans)
### BUGGY CODE ###

l, r = map(int, input().split())
a = 2019
for i in range(l, r + 1):
  for j in range(i + 1, r + 1):
    if a > (i * j) % 2019:
      a = (i* j) % 2019
print(a)


### FIXED CODE ###

l, r = map(int, input().split())
if l % 2019 == 0:
  print(0)
else:
  if l // 2019 + 1 <= r // 2019:
    print(0)
  else:
    a = 2019
    for i in range(l, r + 1):
      for j in range(i + 1, r + 1):
        if a > (i * j) % 2019:
          a = (i* j) % 2019
    print(a)
### BUGGY CODE ###

N=int(input())
l=[]
l.append(input())
for i in range(1,N):
  s=input()
  if s not in l:
    l.append(s)
  
print(len(l))

### FIXED CODE ###

N=int(input())
l=[]
for i in range(N):
  l.append(input())

print(len(set(l)))
### BUGGY CODE ###

B,C = list(map(int,input().split()))
n_l = list(map(int,input().split()))
A = []
total = 0
for i in range(B-C+1):
    A.append(sum(n_l[i:i+C]))
place = A.index(max(A))
for i in range(C):
    total += n_l[place+i]+1
print(total*0.5)

### FIXED CODE ###

N,M=list(map(int,input().split()))
l_n=list(map(int,input().split()))
k=[]
j=0
for i in range(1,1001):
   j+=i
   k.append(j/i)
l_n=[k[l_n[i]-1] for i in range(N)]
ans=sum(l_n[0:M])
sum_n=ans
for i in range(N-M):
   sum_n+=l_n[i+M]
   sum_n-=l_n[i]
   ans=max(ans,sum_n)
print(ans)
### BUGGY CODE ###

N=int(input())
list1=list(map(int,input().split()))
list2=[0]*N

for i in range(N):
    list2[i]=list1.count(i+1)

def choose2(n):
    return n*(n-1)/2

total=0
for i in list2:
    total+=choose2(i)


for i in list1:
    ans=total-(list2[i-1]-1)
    print(int(ans))

### FIXED CODE ###

from collections import Counter

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

dic1=Counter(list1)

def choose2(n):
    return n*(n-1)/2

sum=0
for key in dic1:
    sum+=choose2(dic1[key])

for i in list1:
    print(int(sum-dic1[i]+1))
### BUGGY CODE ###

import bisect
N, M = map(int, input().split())
a = []
number = []
flag = 0
for i in range(M):
    A, B = map(int, input().split())
    a.append([A, B])
    a.append([B, A])
    number.append(A)
    number.append(B)
a.sort()
b = a[:]
b.reverse()
one = []
two = []
for i in range(M):
    if a[i][0] == 1:
        one.append(a[i][1])
    else:
        break

for i in range(M):
    if b[i][0] == N:
        two.append(b[i][1])
    else:
        break
def intersect_list(lst1, lst2):
    arr = []
    lst = lst1.copy()
    for element in lst2:
        try:
            lst.remove(element)
        except ValueError:
            pass
        else:
            arr.append(element)
    return arr
if len(intersect_list(one, two)) != 0:
    print("POSSIBLE")

else:
    print("IMPOSSIBLE")


### FIXED CODE ###

import sys

N, M = map(int, input().split())
ship = [[] for i in range(N+1)]

for i in range(M):
    a, b = map(int, input().split())
    ship[a].append(b)
    ship[b].append(a)

flag = 0
for i in ship[1]:
    if N in ship[i]:
        flag = 1
if flag == 1:
    print("POSSIBLE")
else:
    print("IMPOSSIBLE")
### BUGGY CODE ###

k = int(input())
base = 1
i = 1
ans = -1
while i <= 10**6:
    if (7*base) % k == 0:
        ans = i
        break
    base += 10**i
    i += 1
print(ans)



### FIXED CODE ###

import sys
k = int(input())
mod_k = [0] * (k+2)
mod_k[1] = 7 % k
if mod_k[1] == 0:
    print(1)
    sys.exit()
for i in range(2,k+2):
    nex = (mod_k[i-1]*10+7) % k
    if nex == 0:
        print(i)
        sys.exit()
    mod_k[i] = nex
print(-1)
### BUGGY CODE ###

import numpy as np

N = int(input())

A = np.zeros([N, 3], dtype='int32')

for i in range(N):
    a, b, c = map(int, input().split())
    A[i] = [a, b, c]

dp = np.zeros([N+1, 3], dtype='int32')

for i in range(N):
    for j in range(3):     # i   日目の選択
        for k in range(3): # i+1 日目の選択
            if j == k:
                continue
            if dp[i+1][k] < dp[i][j] + A[i][k]:
                dp[i+1][k] = dp[i][j] + A[i][k]

print(dp[-1].max())


### FIXED CODE ###

import numpy as np

N = int(input())

A = np.zeros([N, 3], dtype='int32')

for i in range(N):
    a, b, c = map(int, input().split())
    A[i] = [a, b, c]

dp = np.zeros([N+1, 3], dtype='int32')

for i in range(N):
    dp[i+1][0] = A[i][0] + max(dp[i][1], dp[i][2])
    dp[i+1][1] = A[i][1] + max(dp[i][0], dp[i][2])
    dp[i+1][2] = A[i][2] + max(dp[i][0], dp[i][1])

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

n = int(input())

from collections import defaultdict

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

d = defaultdict(int)

for el in a:
    d[el] += 1

count = 0

d = sorted(d.items(), reverse=True)
wm = d[0][0]

while len(d):
    a, c = d.pop()
    if c == 1:
#         print(f'count {a=}, {c=}, {count=}, {d=}')
        count += 1
    if a == 1:
        break
    if len(d):
        m = d[0][0]
    else:
        m = a - 1
    if a * 2 <= m:
        d = [elm for elm in d if elm[0] % a]

print(count)

### FIXED CODE ###

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

c = [0]*(10**6+1)

for a in aa:
    c[a] += 1

d = [False]*(10**6+1)

count = 0

for i in range(1, 10**6+1):
    if not c[i]:
        continue
    if d[i]:
        continue
    if c[i] == 1:
        count += 1
    for j in range(i, 10**6+1, i):
        d[j] = True

print(count)
### BUGGY CODE ###

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

def dfs(v):
    seen[v] = 1
    ans[v] += counter[v]

    for next_v in graph[v]:
        if seen[next_v]: continue
        ans[next_v] += ans[v]
        dfs(next_v)

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

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

counter = [0] * n
for _ in range(q):
    p, x = map(int, input().split())
    counter[p-1] += x

seen = [0] * n
ans = [0] * n
dfs(0)

print(*ans)

### FIXED CODE ###

import sys
input = sys.stdin.readline
from queue import Queue

n, q = map(int, input().split())
nodes = [[] for _ in range(n)]  # 隣接ノード
for i in range(n-1):
    a, b = map(int, input().split())
    a, b = a-1, b-1
    nodes[a].append(b)
    nodes[b].append(a)

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

ans = [0] * n
ans[0] = counts[0]
done = [0] * n
queue = Queue()
queue.put(0)
while True:
    node = queue.get()
    done[node] = 1
    next_nodes = nodes[node]
    for next_node in next_nodes:
        if not done[next_node]:
            queue.put(next_node)
            ans[next_node] = ans[node] + counts[next_node]
    if queue.empty():
        break

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

#事象が確率pで起きるとき, 事象が起きるまでの回数の期待値は1/p
#https://qiita.com/drken/items/03c7db44ccd27820ea0d

def main():
    import sys
    input = sys.stdin.readline
    sys.setrecursionlimit(10000000)
    from collections import Counter, deque
    #from collections import defaultdict
    from itertools import combinations, permutations, accumulate
    #from itertools import product
    from bisect import bisect_left,bisect_right
    import heapq
    from math import floor, ceil
    #from operator import itemgetter

    #inf = 10**17
    #mod = 10**9 + 7

    N = int(input())
    a = tuple(map(int, input().split()))
    c1 = a.count(1) #i
    c2 = a.count(2) #j
    c3 = a.count(3) #k

    dp = [[[0]*(N+1) for _ in range(N+1)] for __ in range(N+1)]
    for i in range(c3+1):
        for j in range(c2+c3-i+1):
            for k in range(N-i-j+1):
                if i == j == k == 0:
                    continue
                tmp = N
                if k != 0:
                    tmp += k*dp[k-1][j][i]
                if j != 0:
                    tmp += j*dp[k+1][j-1][i]
                if i != 0:
                    tmp += i*dp[k][j+1][i-1]
                dp[k][j][i] = tmp/(i+j+k)

    print(dp[c1][c2][c3])

if __name__ == '__main__':
    main()

### FIXED CODE ###

def main():
    import sys
    input = sys.stdin.readline
    sys.setrecursionlimit(10000000)
    from collections import Counter, deque
    #from collections import defaultdict
    from itertools import combinations, permutations, accumulate
    #from itertools import product
    from bisect import bisect_left,bisect_right
    import heapq
    from math import floor, ceil
    #from operator import itemgetter

    #inf = 10**17
    #mod = 10**9 + 7

    N = int(input())
    a = tuple(map(int, input().split()))
    c1 = a.count(1) #i
    c2 = a.count(2) #j
    c3 = a.count(3) #k

    dp = [[[0.0]*(N+1) for _ in range(N+1)] for __ in range(N+1)]
    for i in range(c3+1):
        for j in range(c2+c3-i+1):
            for k in range(N-i-j+1):
                if i == j == k == 0:
                    continue
                tmp = N
                if k != 0:
                    tmp += k*dp[k-1][j][i]
                if j != 0:
                    tmp += j*dp[k+1][j-1][i]
                if i != 0:
                    tmp += i*dp[k][j+1][i-1]
                dp[k][j][i] = tmp/(i+j+k)

    print(dp[c1][c2][c3])

if __name__ == '__main__':
    main()