Looking Up
After working as a junior problemsetter AUCPL.inc for a while, you start to wonder when your next promotion will be. You decide to take a look at the corporate hierarchy, to figure out the relationships each of the employees have with their subordinates.
AUCPL.inc has employees, numbered from
to
. The company hierarchy forms a rooted tree. Every employee has exactly one direct manager, except for the CEO (employee
), who has no manager and is the root of the tree.
For some employee , the 'chain of managers' of
is the unique path obtained by repeatedly following the manager relationship from
up to the CEO.
The 'common manager' of a group of employees
is the deepest employee that lies on every path from each employee to the CEO. In other words, it is their lowest common ancestor.
For each employee , determine how many groups of
distinct employees have
as their common manager.
Input
The first line of the input contains two integers
, the number of employees in AUCPL.inc, and the size of the groups we are looking for.
The next line contains integers
, where
is the direct manager of employee
(
). Remember that employee
is the CEO, and does not have any manager.
Output
Output integers
, where
is the number of ways to choose a group of
distinct employees whose common manager is
. Since these counts may be very large, output them modulo
.
Example
Input 1
6 2
1 1 2 2 3
Output 1
11 3 1 0 0 0
There are groups of
employees that have employee
as their common manager:
,
,
,
,
,
,
,
,
,
and
.

There are groups of
employees that have employee
as their common manager:
,
and
.
There is group of
employees that have employee
as their common manager:
.

Input 3
4 3
1 1 1 1
Output 3
4 0 0 0
There are groups of
employees that have employee
as their common manager:
,
,
and
.

Comments