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 <iostream>
#include <cstdio>
#include <cmath>
#include <ctime>
#include <cstdlib>
#include <cassert>
#include <vector>
#include <list>
#include <stack>
#include <queue>
#include <deque>
#include <map>
#include <set>
#include <bitset>
#include <string>
#include <algorithm>
#include <utility>
#define llint long long
#define inf 1e18
#define rep(x, s, t) for(llint (x) = (s); (x) < (t); (x)++)
#define Rep(x, s, t) for(llint (x) = (s); (x) <= (t); (x)++)
#define chmin(x, y) (x) = min((x), (y))
#define chmax(x, y) (x) = max((x), (y))
#define mod 1000000007

using namespace std;
typedef pair<llint, llint> P;

llint n;
vector<llint> G[2005];
llint size[2005];
llint dp[2005][2005][3];
llint dp2[2005][2005][3];

const int FACT_MAX = 200005;
llint fact[FACT_MAX], fact_inv[FACT_MAX];

llint modpow(llint a, llint n)
{
	if(n == 0) return 1;
	if(n % 2){
		return ((a%mod) * (modpow(a, n-1)%mod)) % mod;
	}
	else{
		return modpow((a*a)%mod, n/2) % mod;
	}
}

void make_fact()
{
	llint val = 1;
	fact[0] = 1;
	for(int i = 1; i < FACT_MAX; i++){
		val *= i;
		val %= mod;
		fact[i] = val;
	}
	fact_inv[FACT_MAX-1] = modpow(fact[FACT_MAX-1], mod-2);
	for(int i = FACT_MAX-2; i >= 0; i--){
		fact_inv[i] = fact_inv[i+1] * (i+1) % mod;
	}
}

llint dfs(int v)
{
	size[v] = 1;
	for(int i = 0; i < G[v].size(); i++){
		size[v] += dfs(G[v][i]);
	}
	
	llint m = G[v].size();
	for(int i = 0; i <= m; i++){
		for(int j = 0; j <= size[v]; j++){
			for(int k = 0; k < 3; k++){
				dp2[i][j][k] = 0;
			}
		}
	}
	dp2[0][0][0] = 1;
	
	llint sum = 0;
	for(int i = 0; i < m; i++){
		llint u = G[v][i];
		for(int j = 0; j <= sum; j++){
			for(int k = 0; k < 3; k++){
				for(int s = 0; s <= size[u]; s++){
					for(int t = 0; t < 3; t++){
						llint mul = 1;
						if(t == 1) mul = 2;
						(dp2[i+1][j+s][k] += dp2[i][j][k] * dp[u][s][t] % mod * mul % mod) %= mod;
						
						if(k < 2 && t != 2){
							(dp2[i+1][j+s+1][k+1] += dp2[i][j][k] * dp[u][s][t] % mod) %= mod;
						}
					}
				}
			}
		}
		sum += size[u];
	}
	
	for(int j = 0; j <= size[v]; j++){
		for(int k = 0; k < 3; k++){
			dp[v][j][k] = dp2[m][j][k];
			if(k == 2) dp[v][j][k] *= 2, dp[v][j][k] %= mod;
		}
	}
	
	return size[v];
}

int main(void)
{
	ios::sync_with_stdio(0);
	cin.tie(0);
	make_fact();
	
	cin >> n;
	llint p;
	for(int i = 2; i <= n; i++){
		cin >> p;
		G[p].push_back(i);
	}
	
	dfs(1);
	
	llint ans = 0;
	for(int i = 0; i <= n; i++){
		llint sum = 0;
		for(int j = 0; j < 3; j++){
			if(j == 1) dp[1][i][j] *= 2, dp[1][i][j] %= mod;
			sum += dp[1][i][j], sum %= mod;
		}
		llint tmp = fact[n-i] * sum % mod;
		if(i % 2) ans += mod - tmp, ans %= mod;
		else ans += tmp, ans %= mod;
	}
	cout << ans << endl;
	
	return 0;
}