Problem:
Score : 300 points

Problem Statement

A company has N members, who are assigned ID numbers 1, ..., N.

Every member, except the member numbered 1, has exactly one immediate boss with a smaller ID number.

When a person X is the immediate boss of a person Y, the person Y is said to be an immediate subordinate of the person X.

You are given the information that the immediate boss of the member numbered i is the member numbered A_i. For each member, find how many immediate subordinates it has.

Constraints

2 \leq N \leq 2 \times 10^5

1 \leq A_i < i

Input

Input is given from Standard Input in the following format:

N
A_2 ... A_N

Output

For each of the members numbered 1, 2, ..., N, print the number of immediate subordinates it has, in its own line.

Sample Input 1

5
1 1 2 2

Sample Output 1

2
2
0
0
0

The member numbered 1 has two immediate subordinates: the members numbered 2 and 3.

The member numbered 2 has two immediate subordinates: the members numbered 4 and 5.

The members numbered 3, 4, and 5 do not have immediate subordinates.

Sample Input 2

10
1 1 1 1 1 1 1 1 1

Sample Output 2

9
0
0
0
0
0
0
0
0
0

Sample Input 3

7
1 2 3 4 5 6

Sample Output 3

1
1
1
1
1
1
0

Solution in C++ (Clang 10.0.0) (judge verdict: Time Limit Exceeded)

#include <iostream>
#include <string.h>
#include <algorithm>
#include <stdio.h>
#include <vector>
#include <math.h>
#include <queue>
using namespace std;
typedef long long ll;
int a[200010],b[200010],v[200010];
bool cmp(int x,int y)
{
    return x<y;
}
int main()
{
    int n;
    cin>>n;
    for(int i=2;i<=n;i++)scanf("%d",&a[i]);
    sort(a+2,a+1+n,cmp);
    a[1]=0;
    memset(b,0,sizeof(b));
    memset(v,0,sizeof(v));
    int k=0,f=0;
    for(int i=1;i<=n;i++)
    {
        k=0;
        for(int j=i+1;j<=n;j++)
        {
            if(a[i]<a[j]&&v[j]==0&&k==0)
            {
                k=a[j];
                v[j]=1;
                b[i]++;
                continue;
            }
            if(a[j]==k&&v[j]==0)
            {
                b[i]++;
                v[j]=1;
                continue;
            }
            if(a[j]>k&&k!=0)break;
        }
    }
    for(int i=1;i<=n;i++)printf("%d\n",b[i]);
	return 0;
}