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

There are N 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 1 to N, and the member with the ID i is called Member i. The president is Member 1, and the direct boss of Member i (2 ≤ i ≤ N) is Member b_i (1 ≤ 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 N 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 10^9+7.

Constraints

* 2 ≤ N ≤ 2000
* 1 ≤ b_i < i (2 ≤ i ≤ N)

Input

Input is given from Standard Input in the following format:


N
b_2
b_3
:
b_N


Output

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

Examples

Input

4
1
2
3


Output

2


Input

3
1
2


Output

0


Input

5
1
1
3
3


Output

8


Input

15
1
2
3
1
4
2
7
1
8
2
8
1
8
2


Output

97193524

Solution (in CPP):

Solution:
#include <bits/stdc++.h>
using namespace std;
typedef long long lint;
typedef pair<int, int> pi;
const int MAXN = 2005;
const int mod = 1e9 + 7;

int n, sz[MAXN], p[MAXN];
vector<int> gph[MAXN];

lint dp[MAXN][MAXN][2];
lint fact[MAXN];
lint aux[MAXN][3], nxt[MAXN][3];

int main(){
	fact[0] = 1;
	for(int i=1; i<MAXN; i++) fact[i] = fact[i-1] * i % mod;
	cin >> n;
	for(int i=2; i<=n; i++){
		cin >> p[i];
		gph[p[i]].push_back(i);
	}
	for(int i=n; i; i--){
		memset(aux, 0, sizeof(aux));
		aux[0][0] = 1;
		for(auto &j : gph[i]){
			memset(nxt, 0, sizeof(nxt));
			for(int k=0; k<=sz[j]; k++){
				for(int l=0; l<=sz[i]; l++){
					for(int m=0; m<3; m++){
						nxt[k + l][m] += dp[j][k][0] * aux[l][m] % mod;
						if(m < 2) nxt[k + l + 1][m+1] += dp[j][k][1] * aux[l][m] % mod;
					}
				}
			}
			sz[i] += sz[j];
			for(int j=0; j<=sz[i]; j++){
				for(int k=0; k<3; k++) aux[j][k] = nxt[j][k] % mod;
			}
		}
		for(int j=0; j<=sz[i]; j++){
			dp[i][j][0] = aux[j][0] + aux[j][1] * 2 + aux[j][2] * 2;
			dp[i][j][1] = aux[j][0] + aux[j][1];
			dp[i][j][0] %= mod;
			dp[i][j][1] %= mod;
		}
		sz[i]++;
	}
	lint ret = 0;
	for(int i=0; i<=n; i++){
		lint cur = dp[1][i][0] * fact[n - i] % mod;
		if(i & 1) cur = mod - cur;
		ret += cur;
	}
	cout << ret % mod << endl;
}