PHƯỚC HƯNG OJ · THỬ THÁCH THUẬT TOÁN

#LCA0000001. Đếm nhân viên cấp dưới (Subordinates)

HỌC THEO LỘ TRÌNH

Bài tập thuộc lộ trình

1 lộ trình

Đếm nhân viên cấp dưới (Subordinates)

Subordinates

Source: CSES

Version: Phuoc Hung OJ Extended

Problem Statement

A company employs nn people numbered from 11 to nn. Employee 11 is the director. Every other employee has exactly one immediate manager, and the management hierarchy forms a rooted tree.

An employee is a subordinate of uu if following immediate managers one or more times leads to uu. Employee uu is not their own subordinate.

Determine the number of direct and indirect subordinates of every employee.

Input

  • The first line contains nn.
  • The second line contains n−1n-1 integers p2,p3,…,pnp_2,p_3,\ldots,p_n; pip_i is the immediate manager of employee ii.

Output

Print nn integers in employee order 1,2,…,n1,2,\ldots,n. The ii-th integer is the number of subordinates of employee ii.

Subtasks

  • Subtask 1 (20 points): n≤30n\le30; 1≤n≤2⋅1051\le n\le 2\cdot10^5; 1≤pi<i1\le p_i<i.
  • Subtask 2 (30 points): n≤1000n\le1000; 1≤n≤2⋅1051\le n\le 2\cdot10^5; 1≤pi<i1\le p_i<i.
  • Subtask 3 (50 points): 1≤n≤2⋅1051\le n\le 2\cdot10^5; 1≤pi<i1\le p_i<i.

Examples

Input

5
1 1 2 3

Output

4 1 1 0 0

Explanation

Employee 11 supervises the other four employees. Employee 22 supervises 44, and employee 33 supervises 55. Employees 44 and 55 supervise nobody.