Subordinates

Subordinates
CSES easy

A company has n employees numbered 1..n. Employee 1 is the general director.

For every employee 2..n, you are given the number of their direct boss. This defines the company hierarchy (a boss can have many direct employees).

Your task is to compute, for each employee 1..n, how many subordinates they have in total (both direct and indirect).

Input:

  • First line: integer n — number of employees.
  • Second line: n-1 integers p2 p3 ... pn where pi is the direct boss of employee i.

Output:

  • Print n integers: for each employee 1..n, the number of their subordinates.

Constraints:

  • 1 ≤ n ≤ 2 · 10^5

Example:

Input:

5
1 1 2 3

Output:

4 1 1 0 0