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 ll;
const int MAXN = 2010;
const ll MOD = 1000000007;

inline int read() {
	int x = 0, f = 1;
	char ch = getchar();
	for(; !isdigit(ch); ch = getchar()) if(ch=='-') f=-1;
	for(; isdigit(ch); ch = getchar()) x = (x*10)+(ch^48);
	return x * f;
}

inline ll qpow(ll a, ll b) {
	ll res = 1;
	while(b) {
		if(b & 1LL) res = res * a % MOD;
		b >>= 1, a = a * a % MOD;
	}
	return res;
}

int e, st[MAXN], to[MAXN];
int nxt[MAXN];
inline void Add(int u, int v) {
	to[++e] = v, nxt[e] = st[u];
	st[u] = e;
}

int n, fa[MAXN], size[MAXN];
ll dp[MAXN][MAXN][3], inv2;
ll tmp[MAXN][3];
ll fac[MAXN], ans;

inline void update(ll &cur, ll val) {
	cur = cur+val;
	if(cur >= MOD) cur -= MOD;
}

void dfs(int u) {
	int i, j, k;
	dp[u][1][0] = 1, size[u] = 1;
	for(i = st[u]; i; i = nxt[i]) {
		int v = to[i];
		dfs(v), size[u] += size[v];
	}
	if(size[u] == 1) return;
	for(i = st[u]; i; i = nxt[i]) {
		for(k = size[u]; k >= 1; k--) {
			tmp[k][0] = dp[u][k][0];
			tmp[k][1] = dp[u][k][1];
			tmp[k][2] = dp[u][k][2];
			dp[u][k][0] = dp[u][k][1] = dp[u][k][2] = 0;
		}
		int v = to[i];
		for(k = size[u]-size[v]+1; k >= 1; k--) {
			for(j = size[v]; j >= 1; j--) {
				if(j+k-1 != size[u]) {
					update(dp[u][j+k][0], dp[v][j][0]*tmp[k][0]%MOD);
					update(dp[u][j+k][1], dp[v][j][0]*tmp[k][1]%MOD);
					update(dp[u][j+k][2], dp[v][j][0]*tmp[k][2]%MOD);
					update(dp[u][j+k][0], dp[v][j][1]*tmp[k][0]%MOD);
					update(dp[u][j+k][1], dp[v][j][1]*tmp[k][1]%MOD);
					update(dp[u][j+k][2], dp[v][j][1]*tmp[k][2]%MOD);
					update(dp[u][j+k][0], dp[v][j][2]*tmp[k][0]%MOD);
					update(dp[u][j+k][1], dp[v][j][2]*tmp[k][1]%MOD);
					update(dp[u][j+k][2], dp[v][j][2]*tmp[k][2]%MOD);
				}
				update(dp[u][j+k-1][2], dp[v][j][0]*tmp[k][1]%MOD);
				update(dp[u][j+k-1][2], dp[v][j][1]*tmp[k][1]%MOD*inv2%MOD);
				update(dp[u][j+k-1][1], dp[v][j][0]*tmp[k][0]%MOD*2%MOD);
				update(dp[u][j+k-1][1], dp[v][j][1]*tmp[k][0]%MOD);
			}
		}
		/*if(u == 1) {
			printf(":");
			for(k = 1; k <= size[u]; k++)
				printf("(%lld,%lld,%lld) ", dp[u][k][0], dp[u][k][1], dp[u][k][2]);
			printf("\n");
		}*/
	}
	/*for(k = 1; k <= size[u]; k++)
		printf("(%lld,%lld,%lld) ", dp[u][k][0], dp[u][k][1], dp[u][k][2]);
	printf("\n");*/
}

int main() {
	int i;

	n = read();
	for(i = 2; i <= n; i++) Add(read(), i);

	inv2 = qpow(2, MOD-2);
	dfs(1);
	//printf("%lld\n", dp[4][1][0]);
	//printf("%lld\n", dp[3][1][1]);
	//printf("%lld\n", dp[3][2][0]);

	fac[0] = 1;
	for(i = 1; i <= n; i++) fac[i] = fac[i-1]*i%MOD;
	for(i = 0; i < n; i++) {
		int f = i & 1 ? MOD-1 : 1;
		update(ans, f*fac[n-i]%MOD*((dp[1][n-i][0]+dp[1][n-i][1]+dp[1][n-i][2])%MOD)%MOD);
	}
	printf("%lld\n", ans);
	return 0;
}