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

import collections

n = int(input())
dd = list(map(int, input().split()))
m = int(input())
tt = list(map(int, input().split()))
cd = collections.Counter(dd)
ct = collections.Counter(tt)

for t in tt:
 
  if t in dd and ct[t] <= cd[t]:
    continue
  else:
    print('NO')
    exit()
print('YES')

### FIXED CODE ###

import collections
n = int(input())
d_list = list(map(int, input().split()))
m = int(input())
t_list = list(map(int, input().split()))

if m > n:
    print("NO")
    exit()

d_c = collections.Counter(d_list)
t_c = collections.Counter(t_list)

for i in t_c:
    if t_c[i] <= d_c[i]:
        continue
    else:
        print("NO")
        exit()

print("YES")
### BUGGY CODE ###

N, K = map(int, input().split())
A = list(map(lambda x: int(x)-1, input().split()))

town = 0
visited = [town]
loop = None
while K > 0:
    K -= 1
    town = A[town]
    if town in visited:
        loop = visited[visited.index(town):]
        break
    visited.append(town)

if loop:
    K %= len(loop)
    print(loop[K]+1)
else:
    print(town+1)


### FIXED CODE ###

N, K = map(int, input().split())
A = list(map(lambda x: int(x)-1, input().split()))

town = 0
visited = [town]
index = 0
visited_index = {town: index}
loop = None
while K > 0:
    K -= 1
    town = A[town]
    if town in visited_index:
        loop = visited[visited_index[town]:]
        break
    visited.append(town)
    index += 1
    visited_index[town] = index

if loop:
    K %= len(loop)
    print(loop[K]+1)
else:
    print(town+1)
### BUGGY CODE ###

from math import gcd
n = int(input())
A = tuple(map(int, input().split()))

from collections import deque
q = deque([])
q.append([0, A[0], False])
q.append([1, A[1], True])
# 深さ優先探索
# idx, これまでのGCD, 抜いたか抜いてないか
ans = 0
while q:
    idx, g, jogai = q.pop()
    if g <= ans:
        continue
    if idx == n-1:
        ans = max(ans, g)
        continue

    q.append([idx+1, gcd(g, A[idx+1]), jogai])
    if not jogai:
        q.append([idx+1, g, True])
print(ans)

### FIXED CODE ###

from math import gcd
n = int(input())
A = list(map(int, input().split()))

# 以降のGCD
left_gcds = [A[0]]
for a in A[1:]:
    left_gcds.append(gcd(left_gcds[-1], a))

right_gcds = [A[-1]]
for a in A[:n-1][::-1]:
    right_gcds.append(gcd(right_gcds[-1], a))
right_gcds.reverse()

ans = 0
for i in range(n):
    if i == 0:
        tmp = right_gcds[i+1]
    elif i == n-1:
        tmp =left_gcds[i-1]
    else:
        tmp = gcd(left_gcds[i-1], right_gcds[i+1])
    ans = max(ans, tmp)
print(ans)
### BUGGY CODE ###

N, X = map(int, input().split())
*S, = map(int, input().split())

MOD = 10**9 + 7

fact = [1]*(X+1)
rfact = [1]*(X+1)
for i in range(X):
    fact[i+1] = r = fact[i] * (i+1) % MOD
    rfact[i+1] = pow(r, MOD-2, MOD)

S.sort()
memo = {}
def dfs(i, k):
    key = (i, k)
    if key in memo:
        return memo[key]
    if i == N:
        return k == X
    r = dfs(i+1, k) * i % MOD
    if k <= S[i]:
        for j in range(k, X+1, S[i]):
            r = (r + dfs(i+1, j)) % MOD
    memo[key] = r
    return r
print(sum(x*dfs(0, x)%MOD for x in range(S[0])) % MOD)

### FIXED CODE ###

N, X = map(int, input().split())
*V, = map(int, input().split())

MOD = 10**9 + 7

fact = [1]*(X+1)
rfact = [1]*(X+1)
for i in range(X):
    fact[i+1] = r = fact[i] * (i+1) % MOD
    rfact[i+1] = pow(r, MOD-2, MOD)

V.sort()

S = [0]*(X+1)
S[X] = 1
for i in range(N-1, -1, -1):
    T = [0]*(X+1)
    for k in range(X+1):
        S[k] %= MOD
        T[k] += S[k] * i % MOD
        T[k % V[i]] += S[k]
    S = T
print(sum(k*S[k] % MOD for k in range(V[0])) % MOD)
### BUGGY CODE ###

n = int(input())

list_d = sorted(list(map(int, input().split())))

d_max = max(list_d)
d_min = min(list_d)

score = 0
for i in range(d_min, d_max+2):

    #abcを数える
    score1 = 0
    score2 = 0
    for j in list_d:
        if j < i:
            score1 += 1

        if j >= i:
            score2 += 1


    if score1 == score2:
        score += 1

print(score)

### FIXED CODE ###

n = int(input())

list_d = sorted(list(map(int, input().split())))

list_b = list_d[:int(n/2)]
list_r = list_d[int(n/2):]
print(len(list(range(list_b[-1] + 1, list_r[0] + 1))))
### BUGGY CODE ###


def minCost(cost, m, n): 
	if (n < 0 or m < 0): 
		return 10**9+7
	elif (m == 0 and n == 0): 
		return cost[m][n] 
	else: 
		return cost[m][n] + min(minCost(cost,m-1,n),minCost(cost,m,n-1)) 


n,m=map(int,input().split())
a=[]
x=0
for i in range(n):
    s=input().replace('.','0').replace('#','1')
    ss=[int(i) for i in s]
    a.append(ss)
x=minCost(a,n-1,m-1)
print(x)



### FIXED CODE ###

n,m=map(int,input().split())
s=[list(input()) for i in range(n)]
ans=[[10**9+7]*m for i in range(n)]
ans[0][0]=int(s[0][0]=='#')
for i in range(n):
    for j in range(m):
        if i>0:
            #ans[i][j]=min(ans[i][j]+ans[i-1][j]+int(s[i-1][j]=='.' and s[i][j]=='#'))
            ans[i][j]=min(ans[i][j],ans[i-1][j]+int(s[i-1][j]=='.'and s[i][j]=='#'))
        if j>0:
            ans[i][j]=min(ans[i][j],ans[i][j-1]+int(s[i][j-1]=='.' and s[i][j]=='#'))
print(ans[n-1][m-1])
### BUGGY CODE ###

from itertools import accumulate
def solve(P, C, K, Checked, s):
    B = []
    B.append( C[s])
    now = P[s]
    Checked[s] = True
    while now != s:
        B.append(C[now])
        Checked[now] = True
        now = P[now]
    sumB = sum(B)
    L = len(B)
    accB = [0] + list( accumulate(B))
    ret = B[0]
    for i in range(L):
        for j in range(i+1,L+1):
            if j - i > K:
                continue
            if accB[j] - accB[i] > ret:
                ret = accB[j] - accB[i]
    accRB = [0] + list( accumulate(B[::-1]))
    # print(B, accB, accRB)
    # print(ret)
    for i in range(L+1):
        for j in range(L+1):
            if i==0 and j==0:
                continue
            if i + j > K:
                continue
            t = accB[i] + accRB[j]
            if sumB > 0:
                t += (K-(i+j))//L*sumB
            if t > ret:
                ret = t
                # print(i,j,ret)
    return ret
        
    
def main():
    N, K = map( int, input().split())
    P = list( map( lambda x: int(x)-1, input().split()))
    C = list( map( int, input().split()))
    Checked = [False]*N
    ans = C[0]
    for s in range(N):
        if Checked[s]:
            continue
        ans_s = solve(P, C, K, Checked, s)
        if ans_s > ans:
            ans = ans_s
    print(ans)
if __name__ == '__main__':
    main()


### FIXED CODE ###

from itertools import accumulate
def solve(P, C, K, Checked, s):
    B = []
    B.append( C[s])
    now = P[s]
    Checked[s] = True
    while now != s:
        B.append(C[now])
        Checked[now] = True
        now = P[now]
    sumB = sum(B)
    L = len(B)
    accB = [0] + list( accumulate(B))
    ret = B[0]
    for i in range(L):
        for j in range(i+1,L+1):
            if j - i > K:
                continue
            if accB[j] - accB[i] > ret:
                ret = accB[j] - accB[i]
    accRB = [0] + list( accumulate(B[::-1]))
    # print(B, accB, accRB)
    # print(ret)
    for i in range(L+1):
        for j in range(L+1):
            if i==0 and j==0:
                continue
            if i + j > K:
                continue
            t = accB[i] + accRB[j]
            if sumB > 0:
                t += (K-(i+j))//L*sumB
            if t > ret:
                ret = t
                # print(i,j,ret)
    return ret
        
    
def main():
    N, K = map( int, input().split())
    P = list( map( lambda x: int(x)-1, input().split()))
    C = list( map( int, input().split()))
    Checked = [False]*N
    ans = C[0]
    for s in range(N):
        if Checked[s]:
            continue
        ans_s = solve(P, C, K, Checked, s)
        if ans_s > ans:
            ans = ans_s
    print(ans)
if __name__ == '__main__':
    main()
### BUGGY CODE ###

import numpy as np
import sys

s=list(map(int,input().split()))
S=[]
for i in range(s[2]):
  S.append(int(input()))

P=np.array([s[1]]*s[0])
m=np.array([-1]*s[0])

for i in range(s[2]):
  P=P+m
  P[S[i]-1]+=1

for i in range(s[0]):
  if P[i]<=0:
    print('No')
  else:
    print('Yes')

### FIXED CODE ###

import numpy as np
import sys

s=list(map(int,input().split()))
S=[]
for i in range(s[2]):
  S.append(int(input()))

P=np.array([s[1]-s[2]]*s[0])
for i in range(s[2]):
  P[S[i]-1]+=1

for i in range(s[0]):
  if P[i]<=0:
    print('No')
  else:
    print('Yes')
### BUGGY CODE ###

import itertools
N = int(input())
l = [int(i) for i in input().split()]
count = 0
for v in itertools.permutations(l,3):
    if v[0] < v[1] + v[2]:
        if v[1] < v[0] + v[2]:
            if v[2] < v[1] + v[0]:
                count += 1
print(count//6)

### FIXED CODE ###

import bisect
N = int(input())
l = [int(i) for i in input().split()]
count = 0
l_new = sorted(l)
for i,a in enumerate(l_new):
    for j,b in enumerate(l_new[i+1:],start = i+1):
        left = bisect.bisect_right(l_new,abs(a-b))
        right = bisect.bisect_left(l_new,a + b)
        count += right - left
        
        if left <= i < right:
            count -= 1
        if left <= j < right:
            count -= 1
        
print(count//3)
### BUGGY CODE ###

def returnmax(numbers, i, N):
    nowmax = 0
    for j in range(N):
        if j != i:
            if nowmax < numbers[j]:
                nowmax = numbers[j]
    return nowmax
numbers = []
N = int(input())
for i in range(N):
    numbers.append(int(input()))
for i in range(N):
    print(returnmax(numbers, i, N))


### FIXED CODE ###

def returnsecond(numbers, N):
    first = 0
    firc = 0;
    second = 0
    for j in range(N):
        if first < numbers[j]:
            first = numbers[j]
            firc = j
    for j in range(N):
        if(j != firc and second <= numbers[j]):
            second = numbers[j]

    return first, second;


numbers = []
N = int(input())

for i in range(N):
    numbers.append(int(input()))
first, second = returnsecond(numbers, N)

for i in range(N):
    if numbers[i] != first:
        print(first)
    else:
        print(second)
### BUGGY CODE ###

mod = 998244353
N = int(input())
A = [int(input()) for i in range(N)]
A.sort()
S = sum(A)

PS = [0 for i in range(N+1)]
for i in range(N):
    PS[i+1] = PS[i] + A[i]

# D[i][r]: i個塗った時点でR=rとなる場合の数
D = [[0 for _ in range(PS[i]+1)] for i in range(N+1)]
D[0][0] = 1
# D2[i][r]: i個塗った時点でR=r, B=0となる場合の数
D2 = [[0 for _ in range(PS[i]+1)] for i in range(N+1)]
D2[0][0] = 1

for i in range(N):
    for j in range(PS[i]+1):
        if D[i][j] == 0:
            continue
        D[i+1][j] = (D[i+1][j] + D[i][j] * 2) % mod
        D[i+1][j+A[i]] = (D[i+1][j+A[i]] + D[i][j]) % mod

for i in range(N):
    for j in range(PS[i]+1):
        if D2[i][j] == 0:
            continue
        D2[i+1][j] = (D2[i+1][j] + D2[i][j]) % mod
        D2[i+1][j+A[i]] = (D2[i+1][j+A[i]] + D2[i][j]) % mod

border = (S + 1) // 2

result = 3 ** N
result -= 3 * sum(D[N][border:])
if border * 2 == S:
    result += 3 * D2[N][border]

print(result % mod)


### FIXED CODE ###

mod = 998244353
N = int(input())
A = [int(input()) for i in range(N)]
A.sort()
S = sum(A)

PS = [0 for i in range(N+1)]
for i in range(N):
    PS[i+1] = PS[i] + A[i]

# D[i][r]: i個塗った時点でR=rとなる場合の数
D = [[0 for _ in range(PS[i]+1)] for i in range(N+1)]
D[0][0] = 1
# D2[i][r]: i個塗った時点でR=r, B=0となる場合の数
D2 = [[0 for _ in range(PS[i]+1)] for i in range(N+1)]
D2[0][0] = 1

for i in range(N):
    for j in range(PS[i]+1):
        if D[i][j] == 0:
            continue
        D[i+1][j] = (D[i+1][j] + D[i][j] * 2) % mod
        D[i+1][j+A[i]] = (D[i+1][j+A[i]] + D[i][j]) % mod

for i in range(N):
    for j in range(PS[i]+1):
        if D2[i][j] == 0:
            continue
        D2[i+1][j] = (D2[i+1][j] + D2[i][j]) % mod
        D2[i+1][j+A[i]] = (D2[i+1][j+A[i]] + D2[i][j]) % mod

border = (S + 1) // 2

result = 3 ** N
result -= 3 * sum(D[N][border:])
if border * 2 == S:
    result += 3 * D2[N][border]

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

import sys
input = sys.stdin.readline
from collections import defaultdict
N = int(input())
A = list(map(int, input().split()))
dd = defaultdict(list)
count = 0
for i in range(N - 1):
    ai = A[i]
    iai = i + ai
    if dd[iai] == []:
        for j in range(i + 1, N):
            if j - A[j] == iai:
                dd[iai].append(j)
                count += 1
    else:
        for j in dd[iai]:
            if j > i:
                count += 1
print(count)

### FIXED CODE ###

import sys


def main():
    input = sys.stdin.buffer.readline
    n = int(input())
    a = list(map(int, input().split()))
    b = [0] * (10 ** 6)
    ans = 0
    for i in range(n):
        if i - a[i] > 0:
            ans += b[i - a[i]]
        if i + a[i] < 10 ** 6:
            b[i + a[i]] += 1
    print(ans)


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

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

for i in range(1, min(a, b) + 1):
    if a % i == 0 and b % i == 0:
        cd.add(i)

max_cd = max(cd)

for s in range(2, max_cd+1):
    remove = set()
    for t in cd:
        if s >= t:
            pass
        elif t % s == 0:
            remove.add(t)
    cd -= remove

print(len(cd))


### FIXED CODE ###

import math
from fractions import gcd

a, b = map(int, input().split())
cd = set()
ans = set()

'''
g = gcd(a, b)

for i in range(1, g+1):
    if a % i == 0 and b % i == 0:
        cd.add(i)
        '''

i =  1
a_set = set()

for i in range(1, int(math.sqrt(a)) + 1):
    if a % i == 0:
        a_set.add(i)
        a_set.add(a // i)
    i += 1

i = 1
b_set = set()

for i in range(1, int(math.sqrt(b)) + 1):
    if b % i == 0:
        b_set.add(i)
        b_set.add(b // i)
    i += 1

cd = set(a_set) & set(b_set)

for s in sorted(list(cd)):
    if s == 1:
        ans.add(s)
    else:
        for t in sorted(list(ans)):
            if t == 1:
                continue
            elif s % t == 0:
                break
        else:
            ans.add(s)

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

l,r = map(int, input().split())

t = []

for i in range(l,r):
    for j in range(l+1,r+1):
        t.append((i*j)%2019)

u = sorted(t)
print(u[0])

### FIXED CODE ###

l,r = map(int, input().split())

t = []

if r-l >= 2019:
    print(0)
else:
    for i in range(l,r):
        for j in range(l+1,r+1):
            t.append((i*j)%2019)
    print(min(t))
### BUGGY CODE ###

def solve():
    from sys import stdin
    f_i = stdin
    
    N = int(f_i.readline())
    
    adj = [[] for i in range(N)]
    for i in range(N - 1):
        A, B = map(int, f_i.readline().split())
        A -= 1
        B -= 1
        adj[A].append(B)
        adj[B].append(A)
    
    mod = 10 ** 9 + 7
    pow2 = [(2 ** i) % mod for i in range(N + 1)]
    
    from sys import setrecursionlimit
    setrecursionlimit(10 ** 6)
    
    ans = 0
    def dfs(node, parent):
        nonlocal ans
        cnt = 1
        for child in adj[node]:
            if child != parent:
                cnt += dfs(child, node)
        
        ans += (pow2[cnt] - 1) * (pow2[N-cnt] - 1)
        return cnt
    
    dfs(0, None)
    
    ans = ans - N * pow2[N-1] + pow2[N] - 1
    ans = ans * pow(pow2[N], mod - 2, mod) % mod
    
    print(ans)

solve()

### FIXED CODE ###

from sys import stdin
f_i = stdin

N = int(f_i.readline())

adj = [[] for i in range(N)]
for i in range(N - 1):
    A, B = map(int, f_i.readline().split())
    A -= 1
    B -= 1
    adj[A].append(B)
    adj[B].append(A)

mod = 10 ** 9 + 7

pow2 = [1] * (N + 1)
for i, j in zip(range(N), range(1, N + 1)):
    pow2[j] = pow2[i] * 2 % mod

from sys import setrecursionlimit
setrecursionlimit(10 ** 6)

ans = 0

def dfs(node, parent):
    global ans
    cnt = 1
    
    for child in adj[node]:
        if child != parent:
            cnt += dfs(child, node)
    
    ans += (pow2[cnt] - 1) * (pow2[N-cnt] - 1)
    ans %= mod
    
    return cnt

dfs(0, None)

ans = (ans - N * pow2[N-1] + pow2[N] - 1) % mod
ans = ans * pow(pow2[N], mod - 2, mod) % mod

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

def main():
  S = input()
  Q = int(input())
  import sys
  que = [list(sys.stdin.readline().split()) for _ in range(Q)]
  judge = False
  for l in que:
    if int(l[0])==1:
      if judge:
        judge = False
      else:
        judge = True

    elif int(l[0])==2:
      f,c = int(l[1]),l[2]
      if judge:
        if f==1:
          f=2
        elif f==2:
          f=1
      if f==1:
        S = ''.join([c,S])
      elif f==2:
        S = ''.join([S,c])

  if judge:
    S=S[::-1]
  print(S)
  
main()

### FIXED CODE ###

def main():
  S = input()
  Q = int(input())
  import sys
  que = [list(sys.stdin.readline().split()) for _ in range(Q)]
  pre=''
  post=''
  judge = False
  for l in que:
    if int(l[0])==1:
      if judge:
        judge = False
      else:
        judge = True

    elif int(l[0])==2:
      f,c = int(l[1]),l[2]
      if judge:
        if f==1:
          f=2
        elif f==2:
          f=1
      if f==1:
        pre = ''.join([pre,c])
      elif f==2:
        post = ''.join([post,c])

  pre = pre[::-1]
  S = pre+S+post
  if judge:
    S=S[::-1]
  print(S)
  
main()
### BUGGY CODE ###

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

B = [list(map(int, input().split())) for _ in range(M)][::-1]

S = []
pt = []
G = [-1] * (N+1)
C = [0] * (N+1)
idx = 0
cnt = 0
for pair in B:
    d = []
    for i, x in enumerate(pair):
        if G[x] >= 0:
            d.append(G[x])

    if len(d) <= 0:
        pt.append(1)
        for x in pair:
            G[x] = idx
            C[idx] += 1
        idx += 1
    elif len(d) == 1:
        pt.append(C[d[0]])
        for x in pair:
            if G[x] < 0:
                G[x] = d[0]
                C[d[0]] += 1
    else:
        if d[0] == d[1]:
            pt.append(0)
        else:
            pt.append(C[d[0]] * C[d[1]])
            for i, x in enumerate(G):
                if x == d[1]:
                    G[i] = d[0]
                    C[d[0]] += 1
                    C[d[1]] -= 1

cnt = 0
for x in pt[::-1]:
    cnt += x
    print(cnt)


### FIXED CODE ###

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

pt = []
G = [[None, 1] for x in range(N+1)]

def find(x):
    n = G[x]
    c = []
    while not n[0] is None:
        c.append(n)
        n = n[0]
    for ci in c:
        ci[0] = n
    return n

cnt = 0
while len(B):
    x, y = B.pop()
    wx = find(x)
    wy = find(y)
    if wx is wy:
        pt.append(0)
    else:
        pt.append(wx[1] * wy[1])
        wx[1] += wy[1]
        wy[0] = wx

    #print(G)

cnt = 0
for _ in range(M):
    cnt += pt.pop()
    print(cnt)
### BUGGY CODE ###

n = int(input())
d=0
while n>0:
    d+=n%10
    n//=10
if d%9 == 0:
    print('Yes')
else:
    print('No')

### FIXED CODE ###

n = input()
d=0
for i in range(len(n)):
    d+=int(n[i])
if d%9 == 0:
    print('Yes')
else:
    print('No')
### BUGGY CODE ###

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

n = int(input())
ab = []
edge = [[] for _ in range(n)]
for i in range(n):
    s = input().rstrip()
    for j, ch in enumerate(s):
        if ch == "1":
            if j > i:
                edge[i].append(j)
                edge[j].append(i)
                ab.append((i, j))

ans = 0
for i in range(n):
    dq = deque()
    dist = [-1] * n
    dq.append((i, 0))
    ok = True
    while dq:
        v, d = dq.popleft()
        if dist[v] == -1:
            dist[v] = d
        elif dist[v] != d:
            ok = False
            break
        for item in edge[v]:
            if dist[item] == -1:
                dq.append((item, d+1))
    if ok:
        ans = max(ans, max(dist))

if ans > 0:
    print(ans + 1)
else:
    print(-1)

### FIXED CODE ###

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

n = int(input())
edge = [[] for _ in range(n)]
mat = [[1000] * n for _ in range(n)]
for i in range(n):
    s = input().rstrip()
    for j, ch in enumerate(s):
        if ch == "1":
            mat[i][j] = 1
            if j > i:
                edge[i].append(j)
                edge[j].append(i)
for i in range(n):
    mat[i][i] = 0
for k in range(n):
    for i in range(n):
        for j in range(n):
            mat[i][j] = min(mat[i][j], mat[i][k] + mat[k][j])

ans = 0
dq = deque()
dist = [-1] * n
dq.append((0, 0))
ok = True
while dq:
    v, d = dq.popleft()
    if dist[v] == d:
        continue
    if dist[v] == -1:
        dist[v] = d
    else:
        ok = False
        break
    for item in edge[v]:
        if dist[item] == -1:
            dq.append((item, d+1))

if ok:
    ans = 0
    for line in mat:
        ans = max(ans, max(line))
    print(ans + 1)
else:
    print(-1)
### BUGGY CODE ###

from collections import deque
import math; floor,ceil = math.floor,math.ceil
import sys; input = lambda: sys.stdin.readline().rstrip()
aint = lambda: int(input()); ints = lambda: list(map(int, input().split()))
Yes = lambda boolean: print('Yes') if boolean else print('No')
YES = lambda boolean: print('YES') if boolean else print('NO')
is_even = lambda x: True if x%2==0 else False

def main():
    n = aint()
    a = ints()
    for i in range(n):
        print(a.count(i+1))

if __name__ == '__main__':
    main()

### FIXED CODE ###

from collections import deque
import math; floor,ceil = math.floor,math.ceil
import sys; input = lambda: sys.stdin.readline().rstrip()
aint = lambda: int(input()); ints = lambda: list(map(int, input().split()))
Yes = lambda boolean: print('Yes') if boolean else print('No')
YES = lambda boolean: print('YES') if boolean else print('NO')
is_even = lambda x: True if x%2==0 else False

def main():
    n = aint()
    a = ints();d = deque(a)
    buka = [0]*n
    for _ in range(n-1):
        buka[d.popleft()-1]+=1
    for num in buka:
        print(num)

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

import sys
input = sys.stdin.readline
def main():
    n,m = map(int,input().split())
    dp = [[10**10 for _ in range(2**n)] for _ in range(m+1)]
    dp[0][0] = 0
    for i in range(m):
        a,b = map(int,input().split())
        c = list(map(int,input().split()))
        S = 0
        for j in range(b):
            x = pow(2,c[j]-1)
            S |= x
        for j in range(2**n):
            dp[i+1][j] = min(dp[i+1][j],dp[i][j])
        for j in range(2**n):
            dp[i+1][j|S] = min(dp[i+1][j|S],dp[i][j]+a)
    if dp[m][2**n-1] == 10**10:
        print(-1)
    else:
        print(dp[m][2**n-1])

if __name__ == "__main__":
    main()

### FIXED CODE ###

import sys
input = sys.stdin.readline
def main():
    n,m = map(int,input().split())
    dp = [[10**10 for _ in range(2**n)] for _ in range(m+1)]
    dp[0][0] = 0
    for i in range(m):
        a,b = map(int,input().split())
        c = list(map(int,input().split()))
        S = 0
        for j in range(b):
            x = pow(2,c[j]-1)
            S |= x
        for j in range(2**n):
            dp[i+1][j] = min(dp[i+1][j],dp[i][j])
        for j in range(2**n):
            dp[i+1][j|S] = min(dp[i+1][j|S],dp[i][j]+a)
    if dp[m][2**n-1] == 10**10:
        print(-1)
    else:
        print(dp[m][2**n-1])

if __name__ == "__main__":
    main()