#CF17EXHIBITIONA. Awkward

Awkward

Score : 10001000 points

Problem Statement

ButCoder Inc. is a startup company whose main business is the development and operation of the programming competition site "ButCoder".

There are NN members of the company including the president, and each member except the president has exactly one direct boss. Each member has a unique ID number from 11 to NN, and the member with the ID ii is called Member ii. The president is Member 11, and the direct boss of Member ii (2iN)(2 \leq i \leq N) is Member bib_i (1bi<i)(1 \leq b_i < i).

All the members in ButCoder have gathered in the great hall in the main office to take a group photo. The hall is very large, and all NN people can stand in one line. However, they have been unable to decide the order in which they stand. For some reason, all of them except the president want to avoid standing next to their direct bosses.

How many ways are there for them to stand in a line that satisfy their desires? Find the count modulo 109+710^9+7.

Constraints

  • 2N20002 \leq N \leq 2000
  • 1bi<i1 \leq b_i < i (2iN)(2 \leq i \leq N)

Input

Input is given from Standard Input in the following format:

NN

b2b_2

b3b_3

::

bNb_N

Output

Print the number of ways for the NN members to stand in a line, such that no member except the president is next to his/her direct boss, modulo 109+710^9+7.

4
1
2
3
2

Below, we will write ABA \to B to denote the fact that Member AA is the direct boss of Member BB.

In this case, the hierarchy of the members is 12341 \to 2 \to 3 \to 4. There are two ways for them to stand in a line that satisfy their desires:

  • 2,4,1,32, 4, 1, 3
  • 3,1,4,23, 1, 4, 2

Note that the latter is the reverse of the former, but we count them individually.

3
1
2
0

The hierarchy of the members is 1231 \to 2 \to 3. No matter what order they stand in, at least one of the desires of Member 22 and 33 is not satisfied, so the answer is 00.

5
1
1
3
3
8

The hierarchy of the members is shown below:

There are eight ways for them to stand in a line that satisfy their desires:

  • 1,4,5,2,31, 4, 5, 2, 3
  • 1,5,4,2,31, 5, 4, 2, 3
  • 3,2,4,1,53, 2, 4, 1, 5
  • 3,2,4,5,13, 2, 4, 5, 1
  • 3,2,5,1,43, 2, 5, 1, 4
  • 3,2,5,4,13, 2, 5, 4, 1
  • 4,1,5,2,34, 1, 5, 2, 3
  • 5,1,4,2,35, 1, 4, 2, 3
15
1
2
3
1
4
2
7
1
8
2
8
1
8
2
97193524