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>
#define syosu(x) fixed<<setprecision(x)
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int,int> P;
typedef pair<double,double> pdd;
typedef pair<ll,ll> pll;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<double> vd;
typedef vector<vd> vvd;
typedef vector<ll> vl;
typedef vector<vl> vvl;
typedef vector<string> vs;
typedef vector<P> vp;
typedef vector<vp> vvp;
typedef vector<pll> vpll;
typedef pair<int,P> pip;
typedef vector<pip> vip;
const int inf=1<<30;
const ll INF=1ll<<60;
const double pi=acos(-1);
const double eps=1e-10;
const ll mod=1e9+7;
const int dx[4]={0,1,0,-1},dy[4]={1,0,-1,0};

int n;
vvi g;
vl F;
vvl DP,dp[3];

int dfs(int v){
	int S=1;
	dp[0][v][0]++;
	vp b;
	for(int i=0;i<g[v].size();i++){
		int u=g[v][i];
		b.push_back({dfs(u),u});
	}
	sort(b.rbegin(),b.rend());
	for(int i=0;i<b.size();i++){
		int T=b[i].first,u=b[i].second;
		S+=T;
		vl a[3];
		a[0]=a[1]=a[2]=vl(n);
		a[0][0]++;
		if(!i){
			a[0]=DP[u];
			for(int j=1;j<S;j++) a[1][j]=(dp[0][u][j-1]*2+dp[1][u][j-1])%mod;
		}
		else{
			for(int j=0;j<3;j++) for(int k=1;k<S;k++) for(int l=max(0,k-T);l<=k;l++){
				(a[j][k]+=dp[j][v][l]*DP[u][k-l])%=mod;
				if(j&&l<k) (a[j][k]+=dp[j-1][v][l]*(dp[0][u][k-l-1]*(3-j)+dp[1][u][k-l-1]*(j==1?1:mod/2+1)%mod))%=mod;
			}
		}
		dp[0][v]=a[0];
		dp[1][v]=a[1];
		dp[2][v]=a[2];
	}
	for(int i=0;i<3;i++) for(int j=0;j<S;j++) (DP[v][j]+=dp[i][v][j])%=mod;
	return S;
}

int main(){
	cin>>n;
	g=vvi(n);
	F=vl(n+1,1);
	DP=dp[0]=dp[1]=dp[2]=vvl(n,vl(n));
	for(int i=1;i<n;i++){
		int v;
		cin>>v;
		g[v-1].push_back(i);
	}
	dfs(0);
	ll res=0;
	for(int i=1;i<=n;i++) F[i]=F[i-1]*i%mod;
	for(int i=0;i<n;i++){
		ll tmp=F[n-i]*DP[0][i]%mod;
		if(i%2==1) tmp=(mod-tmp)%mod;
		(res+=tmp)%=mod;
	}
	cout<<res<<endl;
}