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

import sys

sys.setrecursionlimit(50000)
ERROR_INPUT = 'input is invalid'
ERROR_INPUT_NOT_UNIQUE = 'input is not unique'


def main():
    S = get_input1()
    T = get_input2()

    count = 0
    for t in T:
        if binary_search(S, t, 0, len(S), 0):
            count += 1

    print(count)


def binary_search(li, key, left, right, mid):
    mid = (left + right) // 2
    if li[mid] == key:
        return True
    elif li[mid] < key:
        left = mid + 1
    elif li[mid] > key:
        right = mid

    if left >= right:
        return False
    return binary_search(li, key, left, right, mid)


def get_input1():
    n = int(input())
    if n > 100000:
        print(ERROR_INPUT)
        sys.exit(1)

    li = []
    for x in input().split(' '):
        if int(x) < 0 or int(x) > 10 ** 9:
            print(ERROR_INPUT)
            sys.exit(1)
        li.append(int(x))

    return li


def get_input2():
    n = int(input())
    if n > 50000:
        print(ERROR_INPUT)
        sys.exit(1)

    li = []
    for x in input().split(' '):
        if int(x) < 0 or int(x) > 10 ** 9:
            print(ERROR_INPUT)
            sys.exit(1)
        elif int(x) in li:
            print(ERROR_INPUT_NOT_UNIQUE)
            sys.exit(1)
        li.append(int(x))

    return li


main()

### FIXED CODE ###

import array

def main():
    n1 = int(input())
    li1 = array.array('l', [int(x) for x in input().split()])
    n2 = int(input())
    li2 = array.array('l', [int(x) for x in input().split()])
    count = 0

    for l in li2:
        if binary_search(li1, l):
            count += 1

    print(count)


def binary_search(li, x):
    if len(li) == 0:
        return False
    
    mid = len(li)//2
    
    k = li[mid]
    if k == x:
        return True
    elif k > x:
        li = li[:mid]
    else:
        li = li[mid+1:]
        
    return binary_search(li, x)

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

n,m=list(map(int,input().split(" ")))
al=[0 for i in range(n)]
bl=[0 for i in range(n)]
for i in range(n):
    al[i],bl[i]=list(map(int,input().split(" ")))
have=0
yen=0
while have<m:
    k=al.index(min(al))
    pri=al.pop(k)
    num=bl.pop(k)
    have+=num
    yen+=pri*num
if have>m:
    yen-=(have-m)*pri
print(yen)

### FIXED CODE ###

n,m=list(map(int,input().split(" ")))
l=[]
l=[list(map(int,input().split(" "))) for i in range(n)]
have=0
yen=0
i=0
l.sort(key=lambda x: x[0])
while have<m:
    pri=l[i][0]
    num=l[i][1]
    i+=1
    have+=num
    yen+=pri*num
if have>m:
    yen-=(have-m)*pri
print(yen)
### BUGGY CODE ###

# coding: utf-8

S = input()
Q = int(input())
# print("S:{}".format(S))
# print("Q:{}".format(Q))
query = []

for i in range(Q):
    query.append(input().split())
# for i in query:
#     print(i)

# for i in query:
#     if len(i) == 1:
#         S = S[::-1]
#     else:
#         if i[1]=="1":
#             S = i[2]+S
#         else:
#             S += i[2]
# print(S)
left = True
for i in query:
    if len(i) == 1:
        left = not left
        # print(left)
    else:
        if i[1]=="1":
            if left:
                S = i[2]+S
            else:
                S += i[2]
        else:
            if left:
                S += i[2]
            else:
                S = i[2]+S
if left:
    print(S)
else:
    print(S[::-1])


### FIXED CODE ###

# coding: utf-8

S = input()
Q = int(input())

query = []

for i in range(Q):
    query.append(input().split())


bool = True
pre =''
suf =''

for i in query:
    if len(i) == 1:
        bool = not(bool)

    else:
        if i[1]=="1":
            if bool:
                pre = i[2]+pre
            else:
                suf += i[2]
        else:
            if bool:
                suf += i[2]
            else:
                pre = i[2]+pre

S = pre+ S +suf
print(S) if bool else print(S[::-1])
### BUGGY CODE ###

N, Q = map(int, input().split())
S = input()
LR = [list(map(int, input().split())) for i in range(Q)]

ans_cnt = 0
ans_idx = []
for i in range(1, N):
    if S[i - 1] + S[i] == 'AC':
        ans_cnt += 1
        ans_idx.append(i)

#print(ans_idx)
for lr in LR:
    cnt = 0
    for idx in ans_idx:
        if lr[0] <= idx < lr[1]:
            cnt += 1
        if lr[1] <= idx:
            break
    print(cnt)


### FIXED CODE ###

N, Q = map(int, input().split())
S = input()
t = [0] * (N + 1)
for i in range(N):
    t[i + 1] = t[i] + (1 if S[i : i + 2] == 'AC' else 0)
#print(t)
for i in range(Q):
    l, r = map(int, input().split())
    print(t[r-1] - t[l-1])
### BUGGY CODE ###

n=int(input())
S=input()
R=[]
G=[]
B=[]
for i in range(n):
	if S[i]=='R':
		R.append(i)
	elif S[i]=='G':
		G.append(i)
	else:
		B.append(i)
r=len(R)
g=len(G)
b=len(B)

c=0
for i in R:
	for j in G:
		d=abs(i-j)
		min_n=min(i,j)
		max_n=max(i,j)
		if max_n+d in B:
			c+=1
		if (i+j)%2==0 and (i+j)//2 in B:
			c+=1
		if min_n-d in B:
			c+=1

print(r*g*b-c)

### FIXED CODE ###

n=int(input())
S=input()
R=[]
G=[]
B=[]
for i in range(n):
	if S[i]=='R':
		R.append(i)
	elif S[i]=='G':
		G.append(i)
	else:
		B.append(i)
r=len(R)
g=len(G)
b=len(B)

c=0
for i in range(n):
	for j in range(i+1,n):
		k=2*j-i
		if k<n:
			if len(set([S[i],S[j],S[k]]))==3:
				c+=1

print(r*g*b-c)
### BUGGY CODE ###

mod = 1000000007
n = int(input())
num = list(map(int,input().split()))
sum = 0
for i in range(n-1):
  for j in range(i+1,n):
    sum += num[i]^num[j]
print(sum%mod)

### FIXED CODE ###

import numpy as np
mod = 10 ** 9 + 7

n = int(input())
x = np.array([int(a) for a in input().split()])

answer = 0
for d in range(61):
    x, r = x // 2, x % 2
    s = int(r.sum())
    b = (2 ** d) % mod
    answer += (b * s * (n - s)) % mod
print(answer%mod)
### BUGGY CODE ###

N = int(raw_input())
lis = []
for i in xrange(N):
	num = int(raw_input())
	try:
		lis.remove(num)
	except ValueError:
		lis.append(num)
print len(lis)

### FIXED CODE ###

from collections import Counter
N = int(raw_input())
lis = []
for i in xrange(N):
	lis.append(int(raw_input()))
lis.sort()
lister = dict(Counter(lis)).items()
count = 0
for item in lister:
	if item[1] % 2 == 1:
		count += 1
print count
### BUGGY CODE ###

n = int(input())
a = sorted(list(map(int, input().split())))[::-1]

ans = 0
while(len(a)):
    a_min = a.pop()
    if len(a) == 0:
        ans += 1
        break
    if a_min == a[-1]:
       ans -= 1 
    a = [el for el in a if el % a_min != 0]
    ans += 1
    
print(ans)

### FIXED CODE ###

n = int(input())
a = sorted(list(map(int, input().split())))
max_a = a[-1]

q = [0] * (max_a + 1)
for i in a:
    if q[i] == 1 or q[i] == -1:
        q[i] = -1
        continue
    for j in range(2*i, max_a+1, i):
        q[j] = -1
    q[i] = 1

total = 0
for i in q:
    if i == 1:
        total += 1
print(total)
### BUGGY CODE ###

import sys
def func(w,result):
   list = [1,2,4,8,16,32,64,128,256,512]
   for i in range(len(list)):
       if w == list[i]:
           result.append(list[i])
           w = w - list[i]
           break
       else:
           if list[i] > w :
               result.append(list[i-1])
               w = w - list[i-1]
               break

   return w
def sort1(num):
   i = 0
   j = 0
   for i in range(0,len(num)):
        for j in range(0,len(num)-i-1):
            if num[j] < num[j+1]:
               temp = num[j]
               num[j] = num[j+1]
               num[j+1]=temp
   return num
for line in sys.stdin.readlines():
   result = []
   w = int(line)
   while w > 0 :
       w = func(w,result)
   i = len(result)-1
   while i > 0:
       print(result[i],end=' ')
       i -= 1
   print(result[0])
   del(result)

### FIXED CODE ###

import sys
def func(w,result):
   list = [1,2,4,8,16,32,64,128,256,512]
   for i in range(len(list)):
       if w == list[i]:
           result.append(list[i])
           w = w - list[i]
           break
       else:
           if list[i] > w :
               result.append(list[i-1])
               w = w - list[i-1]
               break
           elif w > 512:
               result.append(512)
               w = w - 512
               break

   return w
for line in sys.stdin.readlines():
   result = []
   w = int(line)
   while w > 0 :
       w = func(w,result)
   i = len(result)-1
   while i > 0:
       print(result[i],end=' ')
       i -= 1
   print(result[0])
   del(result)
### BUGGY CODE ###

N = int(input())
A = [int(input()) for _ in range(N)]

O = sorted(A)[::2]
E = sorted(A)[1::2]

ans = 0
for i in range(N):
    if i % 2 == 0 and A[i] not in O:
        ans += 1
    elif i % 2 == 1 and A[i] not in E:
        ans += 1
print(ans//2)


### FIXED CODE ###

import bisect
N = int(input())
A = [int(input()) for _ in range(N)]

eo = [0]*2

As = sorted(A)
for i in range(N):
    if i % 2 != bisect.bisect_left(As, A[i]) % 2:
        eo[i % 2] += 1

print(max(eo))
### BUGGY CODE ###

N,X=map(int,input().split())
above=[0]*N
now=0
data=[0]*N
for i in range(N):
    b,l,u=map(int,input().split())
    above[i]=(i,b*l+(X-b)*u)
    data[i]=(b,l,u)
    now-=l*b
above.sort(key=lambda x:x[1],reverse=True)
used=set()
ans=0
idx=0
for i in range(N):
    if now+above[i][1]<0:
        now+=above[i][1]
        used|={above[i][0]}
        ans+=X
        idx=i+1
    else:
        break
base=ans
ans+=X
now*=-1
for i in range(N):
    b,l,u=data[i]
    if i in used:
        now0=now+b*l+(X-b)*u
        M=base-X
    else:
        now0=now
        M=base
    for i in range(idx,N):
        if now0+above[i][1]<0:
            now+=above[i][1]
    if now0<=b*l:
        ans=min(ans,M+(now0+l-1)//l)
    elif now0<=b*l+(X-b)*u:
        ans=min(ans,M+b+(now0-b*l+u-1)//u)
print(ans)

### FIXED CODE ###

N,X=map(int,input().split())
data=[0]*N
A=[0]*N
zero=0
for i in range(N):
    b,l,u=map(int,input().split())
    zero-=l*b
    data[i]=(b,l,u)
    A[i]=(i,(X-b)*u+b*l)
A.sort(key=lambda x:x[1],reverse=True)
S=[0]*N
idx=[0]*N
for i,a in enumerate(A):
    S[i]=S[i-1]+a[1]
    idx[a[0]]=i
def check(k):
    q=k//X
    r=k-q*X
    for i in range(N):
        b,l,u=data[i]
        if q==0:
            now=zero
        elif idx[i]<q:
            now=zero+S[q]-A[idx[i]][1]
        else:
            now=zero+S[q-1]
        if r<=b:
            now+=r*l
        else:
            now+=(r-b)*u+b*l
        if now>=0:
            return True
    return False
Mincan=N*X
Maxcant=-1
c=(1,2)
while True:
    if Maxcant+1==Mincan:
        ans=Mincan
        break
    x=N*X*c[0]//c[1]
    if check(x):
        if Mincan>x:
            Mincan=x
            c=(c[0]*2-1,c[1]*2)
    else:
        if Maxcant<x:
            Maxcant=x
            c=(c[0]*2+1,c[1]*2)
print(ans)
### BUGGY CODE ###

# 20/5/28
import sys
sys.setrecursionlimit(3 * 10 ** 5)
# input = sys.stdin.readline

def bfs(root, parent):
    global AL, cnt
    for v in AL[root]:
        if v != parent:
            cnt[v] += cnt[root]
            bfs(v, root)

N, Q = [int(x) for x in input().split()]
AL = [[] for _ in range(N + 1)]
for i in range(1, N):
    a, b = [int(x) for x in input().split()]
    AL[a].append(b)
    AL[b].append(a)

cnt = [0] * (N + 1)
for j in range(Q):
    p, x = [int(x) for x in input().split()]
    cnt[p] += x

bfs(1, -1)
print(*cnt[1:])

### FIXED CODE ###

# 20/5/28
from collections import deque

N, Q = [int(x) for x in input().split()]
AL = [[] for _ in range(N + 1)]
for i in range(1, N):
    a, b = [int(x) for x in input().split()]
    AL[a].append(b)
    AL[b].append(a)

cnt = [0] * (N + 1)
for j in range(Q):
    p, x = [int(x) for x in input().split()]
    cnt[p] += x

visited = [False] * (N + 1)
stk = deque([1])
while stk:
    root = stk.pop()
    visited[root] = True
    for v in AL[root]:
        if not visited[v]:
            cnt[v] += cnt[root]
            stk.append(v)

s = " ".join(map(str, cnt[1:]))
print(s)
### BUGGY CODE ###

# input()
# int(input())
# map(int, input().split())
# list(map(int, input().split()))
import sys
inf = 10**9+7
mod = 10**9+7
import bisect
n = int(input())
a = list(map(int, input().split()))
b = list(map(int, input().split()))
c = list(map(int, input().split()))
b.sort()
c.sort()
b_len = len(b)
c_len = len(c)
count = 0
b_list = [0 for i in range(b_len)]

for i,num in enumerate(b):
    ind_c = bisect.bisect_left(c, num)
    if c_len == ind_c:
        continue
    else:
        if c[ind_c] == num:
            while ind_c != c_len and c[ind_c] == num:
                ind_c+=1
            if ind_c != c_len:
                b_list[i] = c_len-ind_c
        else:
            b_list[i] = c_len-ind_c

# 累積和
a2 = [0]
for i in b_list:a2.append(a2[-1]+i)
def SumArea(l, r):
    return a2[r]-a2[l]


for num in a:
    ind_b = bisect.bisect_left(b, num)
    if b_len == ind_b:
        continue
    else:
        if b[ind_b] == num:
            while ind_b != b_len and b[ind_b] == num:
                ind_b += 1
            if ind_b != b_len:
                count += SumArea(ind_b, b_len)
        else:
            count += SumArea(ind_b, b_len)
print(count)


### FIXED CODE ###

# input()
# int(input())
# map(int, input().split())
# list(map(int, input().split()))
import sys
inf = 10**9+7
mod = 10**9+7
import bisect
n = int(input())
a = list(map(int, input().split()))
b = list(map(int, input().split()))
c = list(map(int, input().split()))
b.sort()
c.sort()
b_len = len(b)
c_len = len(c)
count = 0
b_list = [0 for i in range(b_len)]

for i,num in enumerate(b):
    ind_c = bisect.bisect_left(c, num)
    if c_len == ind_c:
        continue
    else:
        if c[ind_c] == num:
            ind_c = bisect.bisect_left(c, num+1)
            if c_len == ind_c:
                continue
            else:
                b_list[i] = c_len - ind_c
        else:
            b_list[i] = c_len-ind_c

# 累積和
a2 = [0]
for i in b_list:a2.append(a2[-1]+i)
def SumArea(l, r):
    return a2[r]-a2[l]


for num in a:
    ind_b = bisect.bisect_left(b, num)
    if b_len == ind_b:
        continue
    else:
        if b[ind_b] == num:
            ind_b = bisect.bisect_left(b, num+1)
            if b_len == ind_b:
                continue
            else:
                count += SumArea(ind_b, b_len)
        else:
            count += SumArea(ind_b, b_len)
print(count)
### BUGGY CODE ###

N, X, Y = map(int,input().split())
X -= 1
Y -= 1

nallpath = N*(N-1)//2
distance = [0] * nallpath

indx = 0
for j in range(N-1):
    for i in range(j+1,N):
        if i <= X:
            distance[indx] = i - j
        elif j >= Y:
            distance[indx] = i - j
        elif j <= X and Y<= i:
            distance[indx] = i - j - (Y-X-1)
        elif  X <= j < i <= Y:
            distance[indx] = min(i-j, (j-X)+(Y-i)+1)
        elif j <= X and X < i <= Y:
            distance[indx] = (X-j) + min(i-X, Y-i+1)
        else:
            distance[indx] = (i-Y) + min(Y-j, j-X+1)
        indx += 1
for i in range(N-1):print(distance.count(i+1))

### FIXED CODE ###

N, X, Y = map(int,input().split())
X -= 1
Y -= 1

npath = [0] * (N-1)

indx = 0
for j in range(N-1):
    for i in range(j+1,N):
        if i <= X:
            distance = i - j
        elif j >= Y:
            distance = i - j
        elif j <= X and Y<= i:
            distance = i - j - (Y-X-1)
        elif  X <= j < i <= Y:
            distance = min(i-j, (j-X)+(Y-i)+1)
        elif j <= X and X < i <= Y:
            distance = (X-j) + min(i-X, Y-i+1)
        else:
            distance = (i-Y) + min(Y-j, j-X+1)
        npath[distance-1] +=1
for i in range(N-1):print(npath[i])
### BUGGY CODE ###

N=int(input())
X=[[0]*10 for i in range(10)]
for i in range(1,10):
    for j in range(1,10):
        c=0
        for k in range(1,N+1):
            if((str(k)[0]==str(i))and(str(k)[-1]==str(j))):
                c+=1
        X[i][j]=c
Ans=0
for i in range(1,10):
    for j in range(1,10):
        Ans+=X[i][j]*X[j][i]
    
print(Ans)

### FIXED CODE ###

n=int(input())
ans=0
X=[[0]*10 for i in range(10)]
for i in range(1,n+1):
    t=(int)(str(i)[0])
    b=(int)(str(i)[-1])
    X[t][b]+=1

for i in range(1,10):
    for j in range(1,10):
        ans+=X[i][j]*X[j][i]

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

from bisect import bisect_right
n = int(input())
d = {}
for a in map(int, input().split()):
  if a in d:
    d[a] += 1
  else:
    d[a] = 1
alist = list(sorted(d.keys(), reverse = True))
amax = alist[0]
t = 1
power_of_two = []
while t < 2 * amax:
  t *= 2
  power_of_two.append(t)
result = 0
for a in alist:
  if d[a] == 0:
    continue
  t = power_of_two[bisect_right(power_of_two, a)] - a
  while True:
    if t not in d or d[t] == 0:
      break
    if a != t:
      i = min(d[a], d[t])
    else:
      i = d[a] // 2
    result += i
    d[a] -= i
    d[t] -= i
    if d[a] == 0:
      break
print(result)


### FIXED CODE ###

from bisect import bisect_right
n = int(input())
d = {}
for a in map(int, input().split()):
  if a in d:
    d[a] += 1
  else:
    d[a] = 1
t = 1
valids = []
while t < 2 * 10 ** 9:
  t *= 2
  valids.append(t)
result = 0
while True:
  prev = result
  keys = list(d.keys())
  keys.sort(reverse = True)
  for x in keys:
    if x not in d:
      continue
    t = valids[bisect_right(valids, x)] - x
    while True:
      if t not in d:
        break
      if x == t and d[x] == 1:
        break
      result += 1
      if d[x] == 1:
        del d[x]
      else:
        d[x] -= 1
      if d[t] == 1:
        del d[t]
      else:
        d[t] -= 1
      if x not in d:
        break
  if prev == result:
    break
print(result)
### BUGGY CODE ###

def solve(n, a, b): 
    E = {(i+1): [] for i in range(n)}
    G = {}
    for i in range(n-1):
        u, v = a[i], b[i]
        E[u].append(v)
        E[v].append(u)
        G[u, v] = 0 
        G[v, u] = 0 
    k = max(map(len, E.values()))
    V = {v: set() for v in E.keys()}
    for u, vs in E.items():
        for v in vs: 
            if G[u, v] != 0:
                continue
            for c in range(1, k+1):
                if (not c in V[u]) and (not c in V[v]):
                    V[u].add(c)
                    V[v].add(c)
                    G[u, v] = c 
                    G[v, u] = c 
                    break
    res = [k] 
    for i in range(n-1):
        res.append(G[a[i], b[i]])
    return "\n".join(map(str, res))

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

### FIXED CODE ###

from collections import deque

def solve(n, a, b):
    E = {(i+1): [] for i in range(n)}
    G = {}
    for i in range(n-1):
        u, v = a[i], b[i]
        E[u].append(v)
        E[v].append(u)
        G[u, v] = 0
        G[v, u] = 0
    k = max(map(len, E.values()))
    V = {v: set() for v in E.keys()}
    que = deque(range(1,k+1))
    for u, vs in E.items():
        for v in vs:
            if G[u, v] != 0:
                continue
            while que:
                c = que.popleft()
                que.append(c)
                if (not c in V[u]) and (not c in V[v]):
                    V[u].add(c)
                    V[v].add(c)
                    G[u, v] = c
                    G[v, u] = c
                    break
    res = [k]
    for i in range(n-1):
        res.append(G[a[i], b[i]])
    return "\n".join(map(str, res))

n = int(input())
a = [0] * n
b = [0] * n
for i in range(n-1):
    a[i], b[i] = map(int, input().split())
print(solve(n, a, b))
### BUGGY CODE ###

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

exp={}

ans=0
cnt=0
for i in range(1,1001):
    sum=0
    for j in range(1,i+1):
        sum+=j
    exp[i]=sum/i

while cnt<=n-k:
    tmp=0
    for i in range(k):
        tmp+=exp[p[i+cnt]]
    if ans < tmp:
        ans=tmp
    cnt += 1

print(ans)

### FIXED CODE ###

from itertools import accumulate

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

exp={}
cum=[]

ans=0
cnt=0
for i in range(1,1001):
    sum=0
    for j in range(1,i+1):
        sum+=j
    exp[i]=sum/i

for i in p:
    cum.append(exp[i])

cumsum=list(accumulate(cum))
cumsum.insert(0,0)

for i in range(n-k+1):
    tmp = cumsum[i+k] - cumsum[i]
    if ans <= tmp:
        ans = tmp

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

from collections import deque
n, m = map(int, input().split())
d = {}
ans = [0] * (n)
for _ in range(m):
    a, b = map(int, input().split())
    if not a in d.keys():
        d[a] = [b]
    elif not b in d[a]:
        d[a].append(b)
    if not b in d.keys():
        d[b] = [a]
    elif not a in d[b]:
        d[b].append(a)

q = deque([1])
while not len(q) == 0:
    x = q.popleft()
    for i in d[x]:
        if ans[i-1] == 0:
            ans[i-1] = x
            q.append(i)

if 0 in ans:
    print('No')
else:
    print('Yes')
    for j in ans[1:]:
        print(j)

### FIXED CODE ###

from collections import deque
n, m = map(int, input().split())
d = [[] for _ in range(n+1)]
ans = [0] * (n)
for _ in range(m):
    a, b = map(int, input().split())
    d[a].append(b)
    d[b].append(a)

q = deque([1])
while not len(q) == 0:
    x = q.popleft()
    for i in d[x]:
        if ans[i-1] == 0:
            ans[i-1] = x
            q.append(i)

if 0 in ans:
    print('No')
else:
    print('Yes')
    s  = "\n".join(map(str, ans[1:]))
    print(s)
### BUGGY CODE ###

import copy, collections, itertools
H, W = [int(_) for _ in input().split()]
S_ = [['#'] * (W + 2)] + [['#'] + list(input()) + ['#']
                          for _ in range(H)] + [['#'] * (W + 2)]
ans = 0
for i, j in itertools.product(range(1, H + 1), range(1, W + 1)):
    if S_[i][j] == '.':
        S = copy.deepcopy(S_)
        q = collections.deque([(i, j, 0)])
        while q:
            x, y, d = q.popleft()
            S[x][y] = ','
            for dx, dy in [[-1, 0], [1, 0], [0, -1], [0, 1]]:
                if S[x + dx][y + dy] == '.':
                    X, Y = x + dx, y + dy
                    q += [(X, Y, d + 1)]
        ans = max(d, ans)
print(ans)


### FIXED CODE ###

import copy, collections, itertools
H, W = [int(_) for _ in input().split()]
S_ = [['#'] * (W + 2)] + [['#'] + list(input()) + ['#']
                          for _ in range(H)] + [['#'] * (W + 2)]
ans = 0
for i, j in itertools.product(range(1, H + 1), range(1, W + 1)):
    if S_[i][j] == '.':
        S = copy.deepcopy(S_)
        S[i][j] = '#'
        q = collections.deque([(i, j, 0)])
        while q:
            x, y, d = q.popleft()
            for dx, dy in [[-1, 0], [1, 0], [0, -1], [0, 1]]:
                if S[x + dx][y + dy] == '.':
                    X, Y = x + dx, y + dy
                    S[X][Y] = '#'
                    q += [(X, Y, d + 1)]
        ans = max(d, ans)
print(ans)
### BUGGY CODE ###

import sys
N = int(input())
sum = 0
A = list(map(int,input().split()))
flag = 0
if 0 in A:
    print(0)
    sys.exit()
Asum = 1
for i in A:
    Asum = Asum * int(i)
if Asum > 10**18:
    flag = 1

if flag == 0 :
    print(Asum)
else:
    print(-1)

### FIXED CODE ###

import sys
N = int(input())
sum = 0
A = list(map(int,input().split()))
flag = 0
if 0 in A:
    print(0)
    sys.exit()
Asum = 1
for i in A:
    Asum = Asum * int(i)
    if Asum > 10**18:
        flag = 1
        break

if flag == 0 :
    print(Asum)
else:
    print(-1)
### BUGGY CODE ###

n=int(input())
a=[int(i) for i in input().split()]
s=0
for i in range(1,n):
  for j in range(i):
    s+=a[j]^a[i]
print(s%(10**9+7))



### FIXED CODE ###

mod=int(1e9)+7

n=int(input())
a=[int(i) for i in input().split()]
ans=0
for b in range(60)[::-1]:
  ans<<=1
  c=sum(a[i]>>b & 1 for i in range(n))
  ans = (ans + c*(n-c)) % mod
print(ans)
### BUGGY CODE ###

import heapq

list = []
n = int(input())
for i in range(n):
    list.append(int(input()))
maxsize = max(list)

for j in range(n):
    a = list[j]
    if a == maxsize:
        list2 = heapq.nlargest(2, list)
        print(list2[1])
    else:
        print(maxsize)

### FIXED CODE ###

import copy
list = []
n = int(input())
for i in range(n):
    list.append(int(input()))
list2 = copy.deepcopy(list)
maxsize = max(list)
list2.sort(reverse=True)
max_second = list2[1]
maxsecond = list2[1]
for j in range(n):
    a = list[j]
    if a == maxsize:
        print(maxsecond)
    else:
        print(maxsize)
### BUGGY CODE ###

n = int(input())
a = list(map(int, input().split()))
b = [0] * (n + 1)
for i in range(1, n):
    print(a.count(i))
print(0)


### FIXED CODE ###

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