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

import heapq

INF = float('inf')
yen = 10**15

def pcc(src, adj):
	global n
	pq = [(0,src)]
	heapq.heapify(pq)
	dist = [INF]*(n+1)
	dist[src] = 0
	while pq:
		d,u = heapq.heappop(pq)
		for w, v in adj[u]:
			if dist[v] > dist[u] + w:
				dist[v] = dist[u] + w
				heapq.heappush(pq, (dist[v], v))
	return dist

n,m,s,t = (int(i) for i in input().split())
adjs = [[] for i in range(n+1)]
adjt = [[] for i in range(n+1)]
for i in range(m):
	u,v,a,b = (int(i) for i in input().split())
	adjs[u].append([a,v])
	adjs[v].append([a,u])
	adjt[u].append([b,v])
	adjt[v].append([b,u])

dist_s = pcc(s,adjs)
dist_t = pcc(t,adjt)

ans = [0]*(n+1)
ans[n] = yen -dist_s[n] - dist_t[n]
for i in range(n-1,0,-1):
	ans[i] = max(ans[i+1], yen - dist_s[i] - dist_t[i])
print(*ans[1:], sep = '\n')


### FIXED CODE ###

import heapq
def dijkstra(s, neighbor):
	dist = [float('inf')] * N
	dist[s] = 0
	que = [(0, s)]
	heapq.heapify(que)
	while que:
		d, v = heapq.heappop(que)
		if d > dist[v]:
			continue
		for u, l in neighbor[v]:
			tmp_d = d + l
			if tmp_d < dist[u]:
				dist[u] = tmp_d
				heapq.heappush(que, (tmp_d, u))
	return dist
 
N, M, s, t = map(int, input().split())
yen = [[] for _ in range(N)]
snuuk = [[] for _ in range(N)]
for _ in range(M):
	u, v, a, b = map(int, input().split())
	yen[u-1].append((v-1, a))
	yen[v-1].append((u-1, a))
	snuuk[u-1].append((v-1, b))
	snuuk[v-1].append((u-1, b))
 
dist_s = dijkstra(s-1, yen)
dist_t = dijkstra(t-1, snuuk)
ans = [-1] * N
tmp = float('inf')
for i in range(N-1, -1, -1):
	if dist_s[i] + dist_t[i] < tmp:
		tmp = dist_s[i] + dist_t[i]
	ans[i] = 10 ** 15 - tmp
print(*ans, sep='\n')
### BUGGY CODE ###

N = int(input())
A = list(map(int, input().split()))
ans = A[0]
for i in range(N-1):
  ans *= A[i+1]
if ans > 10**18:
  print('-1')
else:
  print(ans)


### FIXED CODE ###

N = int(input())
A = list(map(int, input().split()))
if A.count(0)>0:
  print(0)
else:
  ans = A[0]
  for i in range(N-1):
    ans *= A[i+1]
    if ans > 10**18:
      print('-1')
      exit()
  print(ans)
### BUGGY CODE ###

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

BC.sort(key=lambda x: x[1], reverse=True)
A.sort()
s = 0
for B, C in BC:
    mn = A[0]
    if mn >= C:
        s += sum(A)
        break
    n = len(A)
    if B > n:
        B = n
    if A[B - 1] <= C:
        s += B * C
        if B == n:
            break
        A = A[B:]
    else:
        for a in A[1:B]:
            if a >= C:
                i = A.index(a)
                s += i * C
                s += sum(A[i:])
                break
        break
else:
    s += sum(A)
print(s)

### FIXED CODE ###

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

BC.sort(key=lambda x: x[1], reverse=True)
A.sort()
l, r = 0, N
for B, C in BC:
    if A[l] >= C:
        break
    a, b = l, r
    if A[r - 1] >= C:
        while a + 1 < b:
            i = a + (b - a) // 2
            if A[i] >= C:
                b = i
            else:
                a = i
        r = b
    n = B + l
    if n > r:
        n = r
        B = n - l
    if n <= b:
        A[l:n] = [C] * B
        l = n
    else:
        A[l:b] = [C] * B
        l = b
    if l == r:
        break

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

n,m=[int(x) for x in input().split()]
h=[int(x) for x in input().split()]

route=[[0]*n for _ in range(n)]

for i in range(m):
    a,b=[int(x) for x in input().split()]
    a-=1
    b-=1

    if h[b]>=h[a]:
        route[a][b]=1
    if h[a]>=h[b]:
        route[b][a]=1


SUM=0
for i in range(n):

    if sum(route[i])==0:
        SUM+=1

print(SUM)

### FIXED CODE ###

n,m=[int(x) for x in input().split()]
h=[int(x) for x in input().split()]

route=[1]*n

for i in range(m):
    a,b=[int(x) for x in input().split()]
    a-=1
    b-=1

    if h[b]>=h[a]:
        route[a]=0
    if h[a]>=h[b]:
        route[b]=0



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

from decimal import *
getcontext().prec = 100
from bisect import bisect_left as bl
from bisect import bisect_right as br
from heapq import heappush,heappop
import math
from collections import *
from functools import reduce,cmp_to_key
import sys
input = sys.stdin.readline

M = mod = 998244353
def factors(n):return sorted(set(reduce(list.__add__, ([i, n//i] for i in range(1, int(n**0.5) + 1) if n % i == 0))))
def inv_mod(n):return pow(n, mod - 2, mod)

def li():return [int(i) for i in input().rstrip('\n').split()]
def st():return input().rstrip('\n')
def val():return int(input().rstrip('\n'))
def li2():return [i for i in input().rstrip('\n')]
def li3():return [int(i) for i in input().rstrip('\n')]
def li4():return [Decimal(i) for i in input().rstrip('\n').split(' ')]

n = val()
l = li4()
mihe = n//2 + 1


dp = [[Decimal(0) for i in range(n)] for j in range(n + 1)]
sumarray = [Decimal(1.0000000000000000000000000000000000000000000000000000000000000000000000000) for i in range(n + 1)]



for i in range(n-1,-1,-1):
    for j in range(n-1,i - 1,-1):
        dp[i][j] = ( l[i] / (1 - l[i]) ) * sumarray[j + 1]

    for j in range(n):
        if sumarray[j] != 1:
            sumarray[j] += dp[i][j]
        else:
            sumarray[j] = dp[i][j]



# for i in dp:print(*i)
# print(*sumarray)

curr = 1
for i in l:curr *= (1 - i)

print(sum(j * curr for j in sumarray[:- mihe]))


### FIXED CODE ###

from decimal import *
from bisect import bisect_left as bl
from bisect import bisect_right as br
from heapq import heappush,heappop
import math
from collections import *
from functools import reduce,cmp_to_key
import sys
input = sys.stdin.readline

M = mod = 998244353
def factors(n):return sorted(set(reduce(list.__add__, ([i, n//i] for i in range(1, int(n**0.5) + 1) if n % i == 0))))
def inv_mod(n):return pow(n, mod - 2, mod)

def li():return [int(i) for i in input().rstrip('\n').split()]
def st():return input().rstrip('\n')
def val():return int(input().rstrip('\n'))
def li2():return [i for i in input().rstrip('\n')]
def li3():return [int(i) for i in input().rstrip('\n')]
def li4():return [float(i) for i in input().rstrip('\n').split(' ')]

n = val()
l = li4()
mihe = n//2 + 1


curr = 1
for i in l:curr *= (1 - i)
dp = [0 for i in range(n + 1)]
dp[0] = 1

for i in range(n):

    for j in range(i + 1,-1,-1):
        if not j:dp[j] *= 1 - l[i]
        else:dp[j] = dp[j-1] * l[i] + dp[j] *(1 - l[i])

ans = 0
for i in dp[-mihe:]:
    ans += i

print(round(ans,10))
### BUGGY CODE ###

from sys import stdin, setrecursionlimit


def main():
    input = stdin.buffer.readline
    n = int(input())
    a = list(map(int, input().split()))
    ans = 1
    for ai in a:
        ans *= ai

    if ans > 10 ** 18:
        print(-1)
    else:
        print(ans)


if __name__ == "__main__":
    setrecursionlimit(10000)
    main()


### FIXED CODE ###

from sys import stdin, setrecursionlimit


def main():
    input = stdin.buffer.readline
    n = int(input())
    a = list(map(int, input().split()))
    a.sort()
    ans = 1
    for ai in a:
        ans *= ai
        if ans == 0:
            print(0)
            exit()
        elif ans > 10 ** 18:
            print(-1)
            exit()
    print(ans)


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

import bisect

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

MAX=L[-1]
count=0
for i in range(N-2):
    for  j in range(i+1,N-1):
        # print(i,j)
        # print(L[i+1:-1])
        minInd=j+1
        # print(minInd)
        
        # if L[minInd]> L[i]+L[j]:
        #     continue
        # if MAX<L[i]+L[j]:
        #     count+=N-1-minInd+1
        # else:
        #     ind = bisect.bisect_left(L[minInd:], L[i]+L[j]) # number of < a+b
        #     count+=ind
        
        count+= bisect.bisect_left(L[minInd:], L[i]+L[j]) # number of < a+b
print(count)

### FIXED CODE ###

import bisect
 
N = int(input())
L = list(map(int, input().split()))
L.sort()
 
c = 0
for i in range(N-2):
  for j in range(i+1, N-1):
    c += bisect.bisect_right(L, L[i]+L[j]-1) - j - 1
 
 
print(c)
### BUGGY CODE ###

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

ans=0
total=0

while True:
  total+=A
  ans+=A
  if total>=N:
    ans-=total-N
    break
  total+=B
  if total>=N:
    break
print(ans)

### FIXED CODE ###

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

ans=0

times=N//(A+B)
rest=N%(A+B)

ans=times*A
if rest>A:
  a=A
else:
  a=rest

print(ans+a)
### BUGGY CODE ###

R,G,B,N = [int(c) for c in input().split()]
cnt = 0
for r in range(N//R+1):
    for g in range((N-r*R)//G+1):
        for b in range((N-r*R-g*G)//B+1):
            if r*R+g*G+b*B == N:
                cnt+=1

print(cnt)

### FIXED CODE ###

import sys
import copy
import math
import itertools
import numpy as np
import re

R,G,B,N = [int(c) for c in input().split()]
cnt = 0
for r in range(N//R+1):
    for g in range((N-r*R)//G+1):
        if r*R+g*G <= N and (N-r*R-g*G)%B == 0:
            cnt += 1
print(cnt)
### BUGGY CODE ###

# coding: utf-8

import sys
input = sys.stdin.readline

# N = int(input())
N, K = map(int, input().split())
D = [int(x) for x in input().split()]
# S = input()

ans = 0
for l in range(N + 1):
    if l > K:
        break

    for r in range(N - l + 1):
        if l + r > K:
            break

        l_list = sorted(D[0 : l])
        r_list = sorted(D[N - r : N])

        for discard_l in range(K - (l + r) + 1):
            if l + r + discard_l > K:
                break
                
            for discard_r in range(K - (l + r + discard_l) + 1):
                if l + r + discard_l + discard_r > K:
                    break
                    
                value = sum(l_list[discard_l:])
                value += sum(r_list[discard_r:])

                ans = max(ans, value)
        
print(ans)


### FIXED CODE ###

# coding: utf-8

import sys
input = sys.stdin.readline

# N = int(input())
N, K = map(int, input().split())
D = [int(x) for x in input().split()]
# S = input()

ans = 0
for l in range(N + 1):
    if l > K:
        break

    for r in range(N - l + 1):
        if l + r > K:
            break

        value_list = D[0 : l] + D[N - r : N]
        value_list.sort()
        
        for i in range(K - (l + r) + 1):
            ans = max(ans, sum(value_list[i:]))
        
print(ans)
### BUGGY CODE ###

N = int(input())

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

Q = int(input())

for _ in range(Q):
  B,C = map(int,input().split())
  for i,v in enumerate(A):
    if v == B:
      A[i] = C
  
  print(sum(A))

### FIXED CODE ###

from collections import Counter

N = int(input())

A = [int(x) for x in input().split()]
T = sum(A)
Z = Counter(A)

Q = int(input())

for _ in range(Q):
  B,C = map(int,input().split())
  x = Z[B]
  y = Z[C]
  Z.pop(B,0)
  Z[C] = x+y
  T = T-(B*x)+(C*x)
  print(T)
### BUGGY CODE ###

import sys

input = sys.stdin.readline

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

magics = []
max_cost = 0
for _ in range(n):
    at, cost = map(int, input().split())
    max_cost = max(max_cost, cost)
    magics.append((at, cost))

dp = [float('inf')] * (h+max_cost)
dp[0] = 0
for i in range(len(dp)):
    for at, cost in magics:
        if at <= i:
            dp[i] = min(dp[i], dp[i-at] + cost)
print(min(dp[h:]))



### FIXED CODE ###

h, n = map(int, input().split())
magics = sorted(list(map(int, input().split())) for _ in range(n))
max_cost = max(magic[1] for magic in magics)

dp = [float('inf')] * (h+max_cost)
dp[0] = 0
for i in range(h+max_cost):
    for at, cost in magics:
        if at <= i:
            dp[i] = min(dp[i], dp[i-at] + cost)
        else:
            break
print(min(dp[h:]))
### BUGGY CODE ###

s = input()
nq = int(input())
flg = 0
front = []
back = []
for i in range(nq):
    q = input()
    if len(q) == 1:
        #flg += 1
        flg = (flg+1)%2
    else:
        if flg == 0:
            if q[2] == '1':
                front = [q[-1]] + front
            else:
                back = back + [q[-1]]
        else:
            if q[2] == '1':
                back = back + [q[-1]]
            else:
                front = [q[-1]] + front
                
s = ''.join(front) + s + ''.join(back)
if flg % 2 == 1:
    s = s[::-1]
print(s)

### FIXED CODE ###

from sys import stdin
 
def main():
    S = list(stdin.readline().rstrip())
    Q = int(input())
    rev = 0
    head = []
    tail = []
 
    for _ in range(Q):
        q = stdin.readline()
        if q[0] == "1":
            rev = (rev+1)%2
        else:
            if q[2] == "1":
                if rev == 0:
                    head.append(q[4])
                else:
                    tail.append(q[4])
            else:
                if rev ==0:
                    tail.append(q[4])
                else:
                    head.append(q[4])
 
    if rev == 0:
        ans = "".join(head[::-1] + S + tail)
    else:
        ans = "".join(tail[::-1] + S[::-1] + head)
    
    print(ans)
    
main()
### BUGGY CODE ###

N, M = map(int, input().split())
A = list(map(int, input().split()))
for _ in range(M):
    b, c = map(int, input().split())
    A += [c] * b

A.sort()

print(sum(A[-N:]))

### FIXED CODE ###

from operator import itemgetter

N, M = map(int, input().split())
A = list(map(int, input().split()))
BC = []
for _ in range(M):
    BC.append(tuple(map(int, input().split())))

A.sort(reverse=True)
BC.sort(key=itemgetter(1), reverse=True)

n = 0
ans = 0
while True:
    if not BC:
        ans += sum(A[: N - n])
        break
    tgt = BC[0][1]
    a = A[0]
    if a >= tgt:
        ans += A.pop(0)
        n += 1
        if n == N:
            break
    else:
        tgt_n = BC[0][0]
        if n + tgt_n < N:
            ans += tgt * tgt_n
            n += tgt_n
            _ = BC.pop(0)
        else:
            ans += tgt * (N - n)
            break

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

n = int(input())
a = list(map(int, input().split()))
answer = sorted(a)[1]
if n == 2:
    answer = max(a)
else:
    for b in reversed(range(answer)):
        cnt = 2
        flag = True
        for i in range(n):
            if a[i] % answer != 0:
                cnt -= 1
            if cnt == 0:
                flag = False
        if flag:
            break
        answer -= 1
print(answer)

### FIXED CODE ###

n = int(input())
a = list(map(int, input().split()))
answer = sorted(a)[1]
if n == 2:
    pass
else:
    for b in reversed(range(answer)):
        cnt = 2
        flag = True
        for i in range(n):
            if a[i] % answer != 0:
                cnt -= 1
            if cnt == 0:
                flag = False
                break
        if flag:
            break
        answer -= 1
print(answer)
### BUGGY CODE ###

x = int(input())
ans = 0
count = 0

while 1:
    count += 6
    ans += 1
    if count >= x:
        print(ans)
        exit()
    count += 5
    ans += 1
    if count >= x:
        print(ans)
        exit()

### FIXED CODE ###

x = int(input())
a = x % 11
b = x // 11

if a == 0:
    c = 0
elif a <= 6:
    c = 1
else:
    c = 2

print(b * 2 + c)
### BUGGY CODE ###

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

new_ans = 0

for i in range(n):
    ans = a[0]
    if i == 0:
        ans = a[1]
        
    for j in range(n):
        if j == i:
            continue
        else:
            ans = fractions.gcd(ans,a[j])
            if new_ans > ans:
                break
    else:
        new_ans = ans
print(new_ans)

### FIXED CODE ###

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

new_ans = 0
li = [0]*n
li2 = [0]*n

li[0] = a[0]
li2[n-1] = a[n-1]
for i in range(1,n):
    li[i] =fractions.gcd(li[i-1], a[i])

for i in range(1,n)[::-1]:
    li2[i-1] =fractions.gcd(li2[i], a[i-1])

ans =0
for i in range(1,n-1):
    tmp = fractions.gcd(li[i-1],li2[i+1])
    if ans < tmp:
        ans = tmp
ans = max(ans, li[n-2], li2[1])
print(ans)
### BUGGY CODE ###

N = int(input())

buttons = {}
for i in range(N):
    buttons[i+1] = int(input())
    
pushed = []

b = 1
cnt = 0
flag = False
for i in range(N):
    cnt += 1
    next_button = buttons[b]
    if next_button == 2:
        flag = True
        break
    pushed.append(b)
    b = next_button
    if b in pushed:
        flag = False
        break
        
if flag:
    print(cnt)
else :
    print(-1)

### FIXED CODE ###

N = int(input())

buttons = {}
for i in range(N):
    buttons[i+1] = int(input())
    
pushed = []

b = 1
cnt = 0
flag = False
for i in range(N):
    cnt += 1
    next_button = buttons[b]
    if next_button == 2:
        flag = True
        break
    b = next_button
        
if flag:
    print(cnt)
else :
    print(-1)
### BUGGY CODE ###

def main():
    from collections import deque
    s = deque(input())
    q = int(input())
    for i in range(q):
        l = input().split()
        if int(l[0]) == 1:
            s.reverse()
        else:
            if int(l[1]) == 1:
                s.appendleft(l[2])
            else:
                s.append(l[2])
    print("".join(s))

if __name__ == "__main__":
    main()

### FIXED CODE ###

from collections import deque
s = deque(input().split())
q = int(input())
rev = False
for _ in range(q):
    qu = input()
    if qu == "1":
        rev = not rev
    else:
        _, f, c = qu.split()
        if (f != "1") == rev:
            s.appendleft(c)
        else:
            s.append(c)

s = "".join(s)
if rev:
    s = reversed(s)
print("".join(s))
### BUGGY CODE ###

T = input()
 
w0 = "dream"
w1 = "dreamer"
w2 = "erase"
w3 = "eraser"
 
dict_sen = {0:w0,1:w1,2:w2,3:w3}
 
dp = ""
 
while(len(dp) < len(T)):
  for i in range(4):
    if T[len(dp):len(dp)+len(dict_sen[i])] == dict_sen[i]:
      dp = dp + dict_sen[i]
      break
if dp == T :
  print("YES")
else :
  print("NO")

### FIXED CODE ###

S=str(input()) #Sの入力
Smojisuu=len(S)
c=S.count("eraser")
S=S.replace("eraser","xxxxxx",c)
d=S.count("erase")
S=S.replace("erase","xxxxx",d)
e=S.count("dreamer")
S=S.replace("dreamer","xxxxxxx",e)
f=S.count("dream")
S=S.replace("dream","xxxxx",f)
g=S.count("x")
if len(S)>g:
  print("NO")
elif len(S)==g:
  print("YES")
else:
  print("error")
### BUGGY CODE ###

num = int(input())
input_line=input().rstrip().split(" ")
num_line=[]

for i in range(num):
    moji=str(i+1)
    a=input_line.index(moji)
    num_line.append(a+1)

for i in range(num):    
    print(num_line[i],end=" ")

### FIXED CODE ###

num = int(input())
str_line = input().split(" ")
num_line = [int(n) for n in str_line]

rank_line = [0 for i in range(num)]

for i in range(num):
    rank_line[num_line[i] - 1] = i+1

for i in range(num):
    print(rank_line[i],end="")
    if(i != num-1):
        print(" ",end="")
### BUGGY CODE ###

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

ans = 1
for a in a_nums:
  ans *= a
if ans > 10**18:
  ans = -1
print(ans)

### FIXED CODE ###

N = int(input())
A = map(int, input().split())
 
res = 1
 
for a in sorted(A):
    res *= a
    if res > 10 ** 18:
        print("-1")
        exit()
print(res)
### BUGGY CODE ###

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

seq = []

if s[0] == '1':
    seq.append(0)

prev = s[0]
seq_val = 1
last_seq_length = n
for i in range(1, n):
    if s[i] == prev:
        seq_val += 1
    else:
        last_seq_length -= seq_val
        seq.append(seq_val)
        seq_val = 1
        prev = s[i]

seq += [last_seq_length]

ans = 0
for i in range(len(seq)):
    if i % 2 == 0:
        ans = max(ans, sum(seq[i:i+2*k]))
    else:
        ans = max(ans, sum(seq[i:i+2*k+1]))

print(ans)

### FIXED CODE ###

import itertools

n, k = map(int,input().split())
s = input()
seq = []

if s[0] == '0':
    seq.append(0)

i = 1
seq_cnt = 1
while i != n:
    if s[i] != s[i-1]:
        seq.append(seq_cnt)
        seq_cnt = 1
    else:
        seq_cnt += 1
    i += 1

seq.append(seq_cnt)
if s[-1] == '0':
    seq.append(0)

b = [0] + list(itertools.accumulate(seq))

ans = 0
for left in range(0, len(b), 2):
    right = left + 2*k + 1
    if right >= len(b):
        right = len(b)-1

    ans = max(ans, b[right] - b[left])

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

h,w = map(int,input().split())
l = [input() for x in range(h)]
lis = [[x for x in S]for S in l]
ans=0
bk_lis=[]
def lis_Serch(lis):
    global bk_lis
    for x in range(h):
        for y in range(w):
            if lis[x][y] == '#' and not([x,y] in bk_lis):
                bk_lis.append([x,y])

def m_bfs(lis):
    ans = 0
    while True:
        for x in bk_lis:
            chc(x)
        if len(bk_lis)==h*w:
            return ans
        lis_Serch(lis)
        ans+=1

            
def chc(fili):
    vy = [0,0,1,-1]
    vx = [1,-1,0,0]
    for vx,vy in zip(vx,vy):
        now=[fili[0]+vy,fili[1]+vx]
        if 0<=now[0]<h and 0<=now[1]<w:
            lis[now[0]][now[1]] = '#'
lis_Serch(lis)
print(m_bfs(lis))


### FIXED CODE ###

#bfs 
#0#000  1#100 1#120 1#123
#00000  01010 21212 21212
#000#0  001#1 021#1 321#1
#000#0  001#1 021#1 321#1

from collections import deque

h,w = map(int,input().split())
lis = [input() for x in range(h)]

vy = [0,0,1,-1]
vx = [1,-1,0,0]

reached = [[-1]*w for x in range(h)]
def bfs(bk_lis):
    q = deque()
    for i in bk_lis:
        q.append(i)
        reached[i[0]][i[1]]=0
    while q:
        y,x = q.popleft()
        for dy,dx in zip(vy,vx):
            ny,nx = y+dy,x+dx
#                print(ny,nx)
            if not(0<=ny<h and 0<=nx<w):
                continue#範囲の確認
            if  reached[ny][nx]==-1 or reached[ny][nx]>reached[y][x]+1:
                reached[ny][nx] = reached[y][x]+1
                q.append([ny,nx])
#        print(reached)
bk_lis = []
ans=0
for y in range(h):
    for x in range(w):
        if lis[y][x] == '#':
            bk_lis.append([y,x])
#print(bk_lis)
bfs(bk_lis)
for y in reached:
    ans = max(max(y),ans)
#for x in reached:
#    print(x)
print(ans)
### BUGGY CODE ###

n,m = map(int, input().split())
p = list(map(int, input().split()))

l = [[] for j in range(n)]

for i in range(m):
    x,y = map(int, input().split())
    l[x-1].append(y-1)
    l[y-1].append(x-1)

connect = []
v = []

for i in range(n):
    if i not in v:
        connect.append([i])
        v.append(i)
        stack =[i]
        visited = [i]
        while stack:
            q = stack.pop()
            for j in range(len(l[q])):
                if l[q][j] not in visited:
                    connect[-1].append(l[q][j])
                    visited.append(l[q][j])
                    stack.append(l[q][j])
                    v.append(l[q][j])

a = []
for i in range(len(connect)):
    a.append([])
    for j in connect[i]:
        a[-1].append(p[j]-1)

ans = 0

for i in range(len(connect)):
    ans += len(set(a[i]) & set(connect[i]))

print(ans)


### FIXED CODE ###

n,m = map(int, input().split())
p = list(map(int, input().split()))

l = [[] for j in range(n)]

for i in range(m):
    x,y = map(int, input().split())
    l[x-1].append(y-1)
    l[y-1].append(x-1)

connect = []
a = []
v = [0 for i in range(n)]

for i in range(n):
    if v[i] == 0:
        connect.append([i])
        a.append([p[i]-1])
        v[i]=1
        stack =[i]
        while stack:
            q = stack.pop()
            for j in range(len(l[q])):
                if v[l[q][j]]==0:
                    connect[-1].append(l[q][j])
                    a[-1].append(p[l[q][j]]-1)
                    stack.append(l[q][j])
                    v[l[q][j]]=1

ans = 0

for i in range(len(connect)):
    ans += len(set(a[i]) & set(connect[i]))

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

n = int(input())
a = [int(i) for i in input().split()]
print(a.count(1))
b = []
for i in range(2, n + 1):
    if i not in b:
        print(a.count(i))
        b.append(i)
    else:
        print(0)

### FIXED CODE ###

n = int(input())
a = [int(i) for i in input().split()]
b = [0] * n
for i in a:
    b[i - 1] += 1
for i in b:
    print(i)