Harryxun/stf_run huggingface dataset:
N=map(int, input())
list=list(map(str, input().split()))
answer=[]
for i in range(1, N):
	answer.append(str(list.count(str(i))))
a_s='\n'.join(answer)
print(a_s)

### FIXED CODE ###

N=int(input())
A=list(map(int, input().split()))
ans=[0]*N
for a in A:
  ans[a-1]+=1
for n in ans:
  print(n)
n=int(input())
l=list(int,input())
ans=0
for i in range(0,len(l)):
  for j in range(i+1,len(l)):
    for k in range(j+1,len(l)):
      if i>=j and i>=k:
        if i>j+k:
          ans+=1
        else:
          ans+=0
      if j>=i and j>=k:
        if j>i+k:
          ans+=1
        else:
          ans+=0
      if k>=i and k>=j:
        if k>i+j:
          ans+=1
        else:
          ans+=0   
print(ans)          

### FIXED CODE ###

import bisect
n=int(input())
l=list(map(int,input().split()))
l.sort()
ans=0
for i in range(0,n-1):
  for j in range(i+1,n):
    x=l[i]+l[j]
    y=bisect.bisect_left(l,x)-1
    ans+=max((y-j),0)
    
print(ans)
s=int(input())
l=[]
def func(a):
    if a%2==0:
        return a/2
    else:
        return 3*a+1

while (s not in l):
    l.append(s)
    s=func(s)

print(len(l)+1)

### FIXED CODE ###

s=list(input())
a=s.count("0")
b=s.count("1")

print(2*min(a,b))
a,b = (int(x) for x in input().split())
if a == b:
  print(2*a)
elif else a < b:
  print(2*b - 1)
else:
  print(2*a - 1)

### FIXED CODE ###

a,b = (int(x) for x in input().split())
if a == b:
  print(2*a)
elif a < b:
  print(2*b - 1)
else:
  print(2*a - 1)
print((int(input())+int(input()))%24)

### FIXED CODE ###

a,b=map(int,input().split())
print((a+b)%24)
N=int(input())
S=input()
if S[0:len(N)//2-1]==S[len(N)//2:-1]:
  print("Yes")
else:
  print("No")

### FIXED CODE ###

N=int(input())
S=input()
if S[:N//2]==S[N//2:]:
  print("Yes")
else:
  print("No")
n, q = list(map(int, input().split()))
adjacent_list = [[] for i in range(n+1)]
for i in range(n - 1):
    a, b = map(int, input().split())
    adjacent_list[a].append(b)
    adjacent_list[b].append(a)
tree_value = [0]*(n+1)
for i in range(q):
    p, x = map(int, input().split())
    tree_value[p] += x
searched = set()
def dfs(node, count):
    searched.add(node)
    tree_value[node] += count
    for i in adjacent_list[node]:
        if i not in searched:
            dfs(i, tree_value[node])
dfs(1,0)
for i in range(1,n):
    print(tree_value[i])


### FIXED CODE ###

import sys
from queue import *
import sys
input = sys.stdin.readline
sys.setrecursionlimit(10**7)

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

adjacent_list = [[] for i in range(n+1)]
for i in range(n - 1):
    a, b = map(int, input().split())
    adjacent_list[a].append(b)
    adjacent_list[b].append(a)
tree_value = [0]*(n+1)
for i in range(q):
    p, x = map(int, input().split())
    tree_value[p] += x
searched = set()
"""
def dfs(node, count):
    searched.add(node)
    tree_value[node] += count
    for i in adjacent_list[node]:
        if i not in searched:
            dfs(i, tree_value[node])
"""
used = [0 for i in range(n+1)]
que = Queue()
que.put(1)
while que.qsize() != 0:
    m = que.get()
    used[m] = 1
    for i in adjacent_list[m]:
        if not used[i]:
            tree_value[i] += tree_value[m]
            que.put(i)
for i in range(1,n+1):
    print("{} ".format(tree_value[i]), end = "")
# coding: utf-8
# Your code here!
from collections import Counter

S = input()
S = list(S)


c1 = Counter(S).most_common(2)[0][1]
c2 = Counter(S).most_common(2)[1][1]

if(c1==c2):
    if(c1==2):
        print("Yes")
    else:
        print("No")
else:
    print("No")

### FIXED CODE ###

# coding: utf-8
# Your code here!
from collections import Counter

S = input()
S = list(S)


if(Counter(S).most_common(2)[0][1]!=4):
    c1 = Counter(S).most_common(2)[0][1]
    c2 = Counter(S).most_common(2)[1][1]
    if(c1==c2):
        if(c1==2):
            print("Yes")
        else:
            print("No")
    else:
        print("No")
else:
    print("No")
import itertools

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

r = list(itertools.permutations(range(1,n+1)))
r.sort()

for i in range(len(r)):
    if r[i] == p:
        a = i+1
    elif r[i] == q:
        b = i+1

print(abs(a-b))

### FIXED CODE ###

import itertools

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

r = list(itertools.permutations(range(1,n+1)))

print(abs(r.index(p)-r.index(q)))
if and(A<C, C<B):
  print("Yes")
elif and(B<C, C<A):
  print("Yes")
else:
  print("No)

### FIXED CODE ###

A, B, C= map(int, input().split())
if A<C and C<B:
  print("Yes")
elif B<C and C<A:
  print("Yes")
else:
  print("No")
import math
N,K = list(map(int,input().split(" ")))


ans = 0

for p in range(1,N+1): # p 目
    if p >= K:
        ans += 1
    else:
        temp = K/p
        n = math.ceil(math.log2(temp))
        ans += (1/2)**n

ans /= N
print(ans)


### FIXED CODE ###

import math
N,K = list(map(int,input().split(" ")))


ans = 0

for p in range(1,N+1): # p 目
    if p >= K:
        ans += 1
    else:
        temp = K/p
        n = math.ceil(math.log2(temp))
        ans += (1/2)**n

ans /= N
print(ans)
N,M,K = list(map(int,input().split()))

# DFSテンプレ、計算量=O(N+M)
# N:頂点の数
# M:辺の数

G = [[] for _ in range(N)]
# graphの入力
for _ in range(M):
    a,b = list(map(int,input().split()))
    G[a-1].append(b-1)
    G[b-1].append(a-1)
print("G:",G)

KG = [[] for _ in range(N)]
# block graphの入力
for _ in range(K):
    a,b = list(map(int,input().split()))
    KG[a-1].append(b-1)
    KG[b-1].append(a-1)
print("KG:",KG)

def dfs(G,v):
    global l
    # nを訪問済みにする
    seen[v] = 1
    l += 1
    # print(v+1)
    seenV.append(v)
    # vから行ける各頂点next_vについて
    for next_v in G[v]:
        if seen[next_v] == 1:
            continue
        else:
            dfs(G,next_v)

Adj_size = [0]*N
# 全頂点を未訪問に初期化。
Adj = [0]*N
seen = [0]*N
Y = []
for v in range(N):
    l = 0
    seenV = []
    if seen[v] == 0:
        dfs(G,v)
        print("dfs done !!!")
    print("v=",v+1,"seen:",seen)
    print("l=",l)
    print(seenV)
    for sv in seenV:
        Adj_size[sv] = l
        Adj[sv] = seenV
    # print("Adj_size:",Adj_size)
    
    # 出力
    y = Adj_size[v] - len(G[v])-1
    for k in KG[v]:
        if k in Adj[v]:
            y += -1
    print("v=",v+1,"y=",y)
    Y.append(str(y))

print("ADj",Adj)
print("Y",Y)
print("G",G)

print(" ".join(Y))



### FIXED CODE ###

def find(x):
    if par[x]<0:
        return x
    else:
        par[x]=find(par[x])
        return par[x]
 
def unite(x,y):
  x,y=find(x),find(y)
  if x!=y:
    if x>y:
        x,y=y,x
    par[x]+=par[y]
    par[y]=x
    
def same(x,y):
  return find(x)==find(y)
 
def size(x):
  return-par[find(x)]
 
N,M,K = map(int,input().split())
par=[-1]*N
B = [set() for _ in range(N)]
FF = [0]*N
for _ in range(M):
    a,b = map(int,input().split())
    unite(a-1,b-1)
    FF[a-1] += 1
    FF[b-1] += 1
# print(F)
for j in range(K):
    a,b = map(int,input().split())
    B[a-1].add(b-1)
    B[b-1].add(a-1)

Y = []
for i in range(N):
    y = size(i) - FF[i] -1
    for b in B[i]:
        if same(i,b):
            y += -1
    Y.append(str(y))
print(" ".join(Y))
N = input()
nums = input().split()
 
return 1 / sum(1 / int(num) for num in nums)

### FIXED CODE ###

N = input()
nums = map(int, input().split())
 
print(1 / sum(1 / num for num in nums))
n,m=map(int,input().split())
print(n*pow(n-1,k-1))

### FIXED CODE ###

n,k=map(int,input().split())
print(k*pow(k-1,n-1))
S =input()
print(S.count(R))

### FIXED CODE ###

Q =input()
if Q.count('R')==3:
    print(3)
elif Q.count('R')==0:
    print(0)
elif Q.count('R')==1:
    print(1)
elif Q.count('R')==2:
    if Q[1] =='S':
        print(1)
    else :
        print(2)
a=int(input())
b=int(input())
print(a*b,(a+b)*2)

### FIXED CODE ###

a,b=map(int,input().split())
print(a*b,(a+b)*2)
h,a=map(input(int()))
if h%a==0:
  print(h//a)
else:
  print(h//a+1)

### FIXED CODE ###

h,a=map(int,input().split())
if h%a==0:
  print(h//a)
else:
  print(h//a+1)
n, k, q = map(int,input().split())

A = [int,input() for i in range(q)]

a = q-k+1

for i in range(1,n+1):
    v = A.count(i)
    if v >= a:
        print('Yes')
    else:
        print('No')

### FIXED CODE ###

N, K, Q = map(int, input().split())
A = [int(input()) for _ in range(Q)]
n = [K - Q] * N
for i in range(Q):
    n[A[i]-1] += 1
for i in range(N):
    if n[i] > 0:
        print('Yes')
    else:
        print('No')
s = list(input())
n = len(s)
s = s+['z','z']
mem = []
c = 0
run = 0
i=0
while(i<n):
    if s[i]=='A' and s[i+1]=='B' and s[i+2]=='C':
        c+=1
        s[i] = 'B'
        s[i + 1] = 'C'
        s[i + 2] = 'A'
        mem.append(i+2)
        run=1
        i+=3
    else:
        i+=1
        if s[i]=='A':
            mem.append(i)
while(run):
    run = 0
    for i in range(len(mem)):
        idex = mem[i]
        if s[idex] == 'A' and s[idex + 1] == 'B' and s[idex + 2] == 'C':
            c += 1
            s[idex] = 'B'
            s[idex + 1] = 'C'
            s[idex + 2] = 'A'
            mem.append(i + 2)
            run = 1
            mem[i]= idex+2
print(c)

### FIXED CODE ###

s = input()
s= s.replace('BC','D')
a=0
d=0
ans=0
t=''
for i in range(len(s)):
    if s[i] =='A':
        a+=1
    elif s[i]=='D':
        ans+=a
    else:
        a=0
print(ans)
n,a,b,c=map(int,input().split())
s=[]
for i in range(n):
    s.append(input())

ans=[]

flag=True

for i in range(n):
    if s[i]=='AB':
        if a==0 and b==0:
            flag=False
            break
        if a==1 and b==1 and s[i+1]=='AC' or a==0:
            ans.append('A')
            a+=1
            b-=1
        else:
            ans.append('B')
            a-=1
            b+=1
    elif s[i]=='AC':
        if a==0 and c==0:
            flag=False
            break
        if a==1 and c==1 and s[i+1]=='AB' or a==0:
            ans.append('A')
            a+=1
            c-=1
        else:
            ans.append('C')
            a-=1
            c+=1
    else:
        if c==0 and b==0:
            flag=False
            break
        if c==1 and b==1 and s[i+1]=='AC' or c==0:
            ans.append('C')
            c+=1
            b-=1
        else:
            ans.append('B')
            c-=1
            b+=1
if flag:
    print("Yes")
    for i in ans:
        print(i)
else:
    print("No")

### FIXED CODE ###

n,a,b,c=map(int,input().split())
s=[]
for i in range(n):
    s.append(input())
s.append('EOF')

ans=[]
 
flag=True
 
for i in range(n):
    if s[i]=='AB':
        if a==0 and b==0:
            flag=False
            break
        if a==0 or (b!=0 and a==1 and s[i+1]=='AC'):
            ans.append('A')
            a+=1
            b-=1
        else:
            ans.append('B')
            a-=1
            b+=1
    elif s[i]=='AC':
        if a==0 and c==0:
            flag=False
            break
        if a==0 or (c!=0 and a==1 and s[i+1]=='AB'):
            ans.append('A')
            a+=1
            c-=1
        else:
            ans.append('C')
            a-=1
            c+=1
    else:
        if c==0 and b==0:
            flag=False
            break
        if c==0 or (b!=0 and c==1 and s[i+1]=='AC'):
            ans.append('C')
            c+=1
            b-=1
        else:
            ans.append('B')
            c-=1
            b+=1

if flag:
    print("Yes")
    for i in ans:
        print(i)
else:
    print("No")
import numpy as np

N, K = map(int, input().split())
P_exp = np.array([(1+i)/2 for i in map(int, input().split())])
E_sum = np.cumsum(P_exp)

print((E_sum[K:]-E_sum[:-K]).max())


### FIXED CODE ###

import numpy as np

N, K = map(int, input().split())
P_exp = np.array([0] + [(1+i)/2 for i in map(int, input().split())])
E_sum = np.cumsum(P_exp)

print((E_sum[K:]-E_sum[:-K]).max())
# -*- coding: utf-8 -*-

# 関数定義
def dfs(now_p, visited, comb_p, p_num):
    # N頂点と同じ数のルートを通ったら有効なパスとして1を返す
    if len(visited) == p_num - 1:
        return 1

    ans = 0

    # now_pの検索
    for tmp_p in comb_p:
        if tmp_p[0] == now_p and tmp_p[0] not in visited and tmp_p[1] not in visited:
            # comb_pのtmp
            tmp_comb = comb_p[:]
            tmp_comb.remove(tmp_p)
            # visitedのtmp
            tmp_visited = visited[:]
            tmp_visited.append(tmp_p[0])
            next_p = tmp_p[1]
            # dfsの再起呼び出し
            ans += dfs(next_p, tmp_visited, tmp_comb, p_num)

    return ans

## 入力読み取り
N, M = map(int, input().split())
a_b = []
tmp = []
tmp_r = []

# 辺読み取り
for i in range(N):
    tmp = list(map(int, input().split()))
    tmp_r = [tmp[1], tmp[0]]
    a_b.append(tmp)
    a_b.append(tmp_r)

visited = []

# 再起関数の実施
pass_num = dfs(1, visited, a_b, N)
print(pass_num)

### FIXED CODE ###

# -*- coding: utf-8 -*-

# 関数定義
def dfs(now_p, visited, comb_p, p_num):
    # N頂点と同じ数のルートを通ったら有効なパスとして1を返す
    if len(visited) == p_num:
        return 1

    ans = 0

    # now_pの検索
    for tmp_p in comb_p:
        if tmp_p[0] == now_p and tmp_p[1] not in visited:
            # visitedのtmp
            tmp_visited = visited[:]
            tmp_visited.append(tmp_p[1])
            #print(*tmp_visited)
            # 次の頂点
            next_p = tmp_p[1]
            #print('next_p: ', next_p)
            # comb_pのtmp
            tmp_comb = comb_p[:]
            tmp_comb.remove(tmp_p)
            # 往復対象の削除
            tmp_p_r = [tmp_p[1], tmp_p[0]]
            tmp_comb.remove(tmp_p_r)
            #print(*tmp_comb)
            # dfsの再起呼び出し
            ans += dfs(next_p, tmp_visited, tmp_comb, p_num)

    return ans

## 入力読み取り
N, M = map(int, input().split())
a_b = []
tmp = []
tmp_r = []

# 辺読み取り
for i in range(M):
    tmp = list(map(int, input().split()))
    tmp_r = [tmp[1], tmp[0]]
    a_b.append(tmp)
    a_b.append(tmp_r)

visited = [1]

# 再起関数の実施
pass_num = dfs(1, visited, a_b, N)
print(pass_num)
S = input()

def kaibunn_boolean(s):
  return s == s[::-1]

ans = true

if kaibunn_boolean(S) and kaibunn_boolean(S[:3]):
  ans = kaibunn_boolean(S)

if ans:
  print('Yes')
else:
  print('No')



### FIXED CODE ###

S = input()
ans = True
def isP(s):
    return s == s[::-1]

if not isP(S):
    ans = False
if not isP(S[:(len(S)//2)]):
    ans = False

if ans:
    print("Yes")
else:
    print("No")
k=int(input())  
odd=1
even=0
for i in range(2,k+1) 
     if i%2==0:
        even+=1
     else:
           odd+=1
print(odd*even)

### FIXED CODE ###

n=int(input())
e=int(n/2)
if n%2:
	o=int(n/2+1)
else:
	o=int(n/2)
	
print (o*e)
N,K=list(map(int, input().split()))
AB = [list(map(int, input().split())) for _ in range(N-1)]
MOD = 10**9+7

counted = [0]* (N+1) #counted[i]: ノードiはカウント済み

adjucent_dict = {}
for a,b in AB:
  adjucent_dict.setdefault(a, set()).add(b)
  adjucent_dict.setdefault(b, set()).add(a)
  
from collections import deque

dq = deque([])

for i in range(1,N+1):
  if len(adjucent_dict[i])==1:
    dq.append(i)
    
#print(dq)

ans = 1
while dq:
  v = dq.popleft()
  # assert(len(adjucent_dict[v])==1)
  parent = adjucent_dict[v].pop() #かならずlen(~)=1のはず
  adjucent_dict[parent].remove(v)
  #print(v, K - (len(adjucent_dict[parent])+1))
  ans *= K - (len(adjucent_dict[parent])+1)
  ans %= MOD
  
  if len(adjucent_dict[parent])==1:
    dq.append(parent)
  if len(adjucent_dict[parent])==0:
    ans *= K
    ans %= MOD
    break
  
print(ans)

### FIXED CODE ###

N,K=list(map(int, input().split()))
AB = [list(map(int, input().split())) for _ in range(N-1)]
MOD = 10**9+7

if N==1:
  print(K)
  exit()

counted = [0]* (N+1) #counted[i]: ノードiはカウント済み

adjucent_dict = {}
for a,b in AB:
  adjucent_dict.setdefault(a, set()).add(b)
  adjucent_dict.setdefault(b, set()).add(a)
  
from collections import deque

dq = deque([])

for i in range(1,N+1):
  if len(adjucent_dict[i])==1:
    dq.append(i)
    
#print(dq)

ans = K
while dq:
  v = dq.popleft()
  # assert(len(adjucent_dict[v])==1)
  parent = adjucent_dict[v].pop() #かならずlen(~)=1のはず
  adjucent_dict[parent].remove(v)
  #print(v, K - (len(adjucent_dict[parent])+1))
  ans *= max(0, K - (len(adjucent_dict[parent])+1))
  ans %= MOD
  
  if len(adjucent_dict[parent])==1:
    dq.append(parent)
  if len(adjucent_dict[parent])==0:
    break
  
print(ans)
X , N = map(int, input().split())
p = list(map(int,input().split()))
ans = []
if N == 0:
    print(X)
elif X not in  p:
    print(X)
else:
    p = sorted(p)
    p2 = [abs(i-X) for i in p]

    for i in range(p[p2.index(min(p2))],101):
        if i not in p:
            ans.append(i)
            break
    for i in range(p[p2.index(min(p2))], 0, -1):
        if i not in p:
            ans.append(i)
            
    
    ans = sorted(ans)
    ans2 = [abs(i-X) for i in ans]
    #ans2 = sorted(ans2)
    print(ans[ans2.index(min(ans2))])
   # print(min(ans))


### FIXED CODE ###

X , N = map(int, input().split())
p = list(map(int,input().split()))
ans = []
if N == 0:
    print(X)
elif X not in  p:
    print(X)
else:
    p = sorted(p)
    p2 = [abs(i-X) for i in p]

    for i in range(p[p2.index(min(p2))],102):
        if i not in p:
            ans.append(i)
            break
    for i in range(p[p2.index(min(p2))], -100, -1):
        if i not in p:
            ans.append(i)
            break
    
    ans = sorted(ans)
    ans2 = [abs(i-X) for i in ans]
    print(ans[ans2.index(min(ans2))])
a,b,c,d=map(int,input().split())
if A <= X <= A + B:
  print('YES')
else:
  print('No')

### FIXED CODE ###

A, B, X=map(int,input().split())
if A <= X <= A + B:
  print('YES')
else:
  print('NO')
s,w=map(int.input().split())
if s<=w:
  print(unsafe)
else:
  print(safe)

### FIXED CODE ###

def issafe(S,W):
    if S > W:
        return "safe"
    return "unsafe"

S,W = map(int,input().split())
print(issafe(S,W))
n = int(input())
B = list(map(int, input().split()))
ans = 0
ans += B[0]
for i in range(n - 2):
    if B[i] > B[i + 1]:
        ans += B[i + i]
    else:
        ans += B[i]
ans += B[-1]
print(ans)


### FIXED CODE ###

n = int(input())
B = list(map(int, input().split()))
ans = 0
ans += B[0]
for i in range(n - 2):
    if B[i] > B[i + 1]:
        ans += B[i + 1]
    else:
        ans += B[i]
ans += B[-1]
print(ans)
import copy
class Dice(object):
  def __init__(self, List):
    self.face = List

  def n_spin(self, a_List):
    List = copy.copy(a_List)
    temp = List[0]
    List[0] = List[1]
    List[1] = List[5]
    List[5] = List[4]
    List[4] = 
    return List

  def s_spin(self, a_List):
    List = copy.copy(a_List)
    temp = List[0]
    List[0] = List[4]
    List[4] = List[5]
    List[5] = List[1]
    List[1] = temp
    return List

  def e_spin(self, a_List):
    List = copy.copy(a_List)
    temp = List[0]
    List[0] = List[3]
    List[3] = List[5]
    List[5] = List[2]
    List[2] = temp
    return List

  def w_spin(self, a_List):
    List = copy.copy(a_List)
    temp = List[0]
    List[0] = List[2]
    List[2] = List[5]
    List[5] = List[3]
    List[3] = temp
    return List

dice = Dice(map(int, raw_input().split()))
emer = copy.copy(dice.face)
face_storage = []
face_storage.append(emer)
q = input()
for a in range(q):
  question = map(int, raw_input().split())
  for a in range(24):
    face_storage.append(dice.n_spin(face_storage[a]))
    face_storage.append(dice.s_spin(face_storage[a]))
    face_storage.append(dice.w_spin(face_storage[a]))
    face_storage.append(dice.e_spin(face_storage[a]))
  for c in face_storage:
    if c[0] == question[0] and c[1] == question[1]:
      print c[2]
      break

### FIXED CODE ###

import copy
class Dice(object):
  def __init__(self, List):
    self.face = List

  def n_spin(self, a_List):
    List = copy.copy(a_List)
    temp = List[0]
    List[0] = List[1]
    List[1] = List[5]
    List[5] = List[4]
    List[4] = temp
    return List

  def s_spin(self, a_List):
    List = copy.copy(a_List)
    temp = List[0]
    List[0] = List[4]
    List[4] = List[5]
    List[5] = List[1]
    List[1] = temp
    return List

  def e_spin(self, a_List):
    List = copy.copy(a_List)
    temp = List[0]
    List[0] = List[3]
    List[3] = List[5]
    List[5] = List[2]
    List[2] = temp
    return List

  def w_spin(self, a_List):
    List = copy.copy(a_List)
    temp = List[0]
    List[0] = List[2]
    List[2] = List[5]
    List[5] = List[3]
    List[3] = temp
    return List

dice = Dice(map(int, raw_input().split()))
emer = copy.copy(dice.face)
face_storage = []
face_storage.append(emer)
q = input()
for a in range(q):
  question = map(int, raw_input().split())
  for a in range(24):
    face_storage.append(dice.n_spin(face_storage[a]))
    face_storage.append(dice.s_spin(face_storage[a]))
    face_storage.append(dice.w_spin(face_storage[a]))
    face_storage.append(dice.e_spin(face_storage[a]))
  for c in face_storage:
    if c[0] == question[0] and c[1] == question[1]:
      print c[2]
      break
N, M = (int(i) for i in input().split()) 
 
outs = [[] for i in range(N)]
ins = [0] * N
 
for _ in range(M):
    x, y = (int(i) for i in input().split())
    x -= 1
    y -= 1
    outs[x].append(y)
    ins[y] += 1
 
q = []
for i in range(N):
    if ins[i] == 0:
        q.append(i)
 
last = [0] * N
while q != []:
    qn = q.poplef()
    for v in outs[qn]:
        ins[v] -= 1
        last[v] = max(last[v], last[qn] + 1)
        if ins[v] == 0:
            q.append(v)
 
print(max(last))

### FIXED CODE ###

N, M = (int(i) for i in input().split()) 

outs = [[] for i in range(N)]
ins = [0] * N


for _ in range(M):
    x, y = (int(i) for i in input().split())
    x -= 1
    y -= 1
    outs[x].append(y)
    ins[y] += 1

q = []
for i in range(N):
    if ins[i] == 0:
        q.append(i)

result = []
while q != []:
    qn = q.pop()
    result.append(qn)
    for v in outs[qn]:
        ins[v] -= 1
        if ins[v] == 0:
            q.append(v)


last = [0] * N
# last[i] = iが最後だったときに最長のパス
for sq in result:
    for v in outs[sq]:
        last[v] = max(last[v], last[sq] + 1)

print(max(last))
import sys
sys.setrecursionlimit=10**12

def modinv(a,m=10**9+7):
    if a==0: return 1
    else:
        b=m
        (x, lastx) = (0, 1)
        (y, lasty) = (1, 0)
        while b != 0:
            q = a // b
            (a, b) = (b, a % b)
            (x, lastx) = (lastx - q * x, x)
            (y, lasty) = (lasty - q * y, y)
        return lastx % m

def cur(p):
    for x in neighbor[p]:
        try:
            par[x]=p
            neighbor[x].remove(p)
        except: sys.exit()
        descend[p]+=cur(x)
    try:
        return descend[p]
    except: sys.exit()
def cur2(p):
    for x in neighbor[p]:
        ans[x]=ans[p]*descend[x]*modinv(n-descend[x])
        ans[x]%=mod
        cur2(x)

mod=10**9+7
n=int(input())
neighbor=[set()  for _ in range(n+2)]
descend=[1]*(n+2)
par=[-1]+[0]*(n+1)

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


ans=[1]*(n+1)
ans1=1
for i in range(1,n+1):
    ans1=ans1*i*modinv(descend[i])
    ans1%=mod
ans[1]=ans1

cur2(1)

for i in range(1,n+1):
    print(ans[i])

### FIXED CODE ###

import sys
sys.setrecursionlimit(10**7)

def modinv(a,m=10**9+7):
    if a==0: return 1
    else:
        b=m
        (x, lastx) = (0, 1)
        (y, lasty) = (1, 0)
        while b != 0:
            q = a // b
            (a, b) = (b, a % b)
            (x, lastx) = (lastx - q * x, x)
            (y, lasty) = (lasty - q * y, y)
        return lastx % m

def cur(p):
    if neighbor[p]==[]: return
    for x in neighbor[p]:
        par[x]=p
        neighbor[x].remove(p)
        cur(x)
    descend[par[p]]+=descend[p]

def cur2(p):
    for x in neighbor[p]:
        ans[x]=ans[p]*descend[x]*modinv(n-descend[x])
        ans[x]%=mod
        cur2(x)

mod=10**9+7
n=int(input())
neighbor=[set()  for _ in range(n+2)]
descend=[1 for i in range(n+1)]
par=[0]+[0]*(n+1)

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

cur(1)


ans=[1]*(n+1)
ans1=1
for i in range(1,n+1):
    ans1=ans1*i*modinv(descend[i])
    ans1%=mod
ans[1]=ans1

cur2(1)

for i in range(1,n+1):
    print(ans[i])