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 long double llf;
typedef pair<lint, lint> pi;
const int MAXN = 2005, N = MAXN;
const int mod = 1e9 + 7, inv2 = (mod + 1) / 2;
int dp[MAXN][3][MAXN], odp[3][MAXN], sz[MAXN];
vector<int> adj[N];
void sadd(int &x, int y) {
	x += y;
	while (x >= mod) x -= mod;
}
void dfs(int v, int p = -1) {
	dp[v][0][1] = 1;
	sz[v] = 1;
	for (int u : adj[v]) {
		if (u != p) {
			dfs(u, v);
			memcpy(odp, dp[v], sizeof dp[v]);
			memset(dp[v], 0, sizeof dp[v]);
			for (int dv = 0; dv <= 2; ++dv) {
				for (int du = 0; du <= 2; ++du) {
					for (int use = 0; use <= 1; ++use) {
						if (use == 1 && (du > 1 || dv > 1)) continue;
						for (int cv = 1; cv <= sz[v]; ++cv)
							for (int cu = 1; cu <= sz[u]; ++cu) {
								int ways = (use == 1 ? mod - 1 : 1);
								if (use) {
									if (du == 0 && dv == 0) 
										ways = (long long) ways * 2 % mod;
									if (du == 1 && dv == 1)
										ways = (long long) ways * inv2 % mod;
								}
								sadd(dp[v][dv + use][cv + cu - use], 
										odp[dv][cv] * (long long) dp[u][du][cu] % mod * ways % mod);
							}

					}
				}
			}
			sz[v] += sz[u];
		}
	}
	
}
int f[N];
int main(){
	f[0] =1 ;
	for (int j = 1; j < N; ++j) f[j] = (long long) f[j - 1] * j % mod;
	int n;
	cin >> n;
	for (int j = 1; j < n; ++j) {
		int p;
		cin >> p;
		adj[--p].push_back(j);
	}
	dfs(0);
	int res = 0;
	for (int j = 0; j < N; ++j)

		for (int d = 0; d <= 2; ++d) if (dp[0][d][j]) {
			sadd(res, dp[0][d][j] * (long long) f[j] % mod);
		//	cout << " hi " << d << ' ' << j << ' ' << dp[0][d][j] << endl;
		}
	cout << res << endl;
	
}