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<stdio.h>
#include<math.h>
#include<algorithm>
#include<queue>
#include<deque>
#include<string>
#include<string.h>
#include<vector>
#include<set>
#include<map>
#include<bitset>
#include<stdlib.h>
#include<cassert>
using namespace std;
const long long mod=1000000007;
const long long inf=mod*mod;
const long long d2=500000004;
const double EPS=1e-6;
const double PI=acos(-1.0);
int ABS(int a){return max(a,-a);}
long long ABS(long long a){return max(a,-a);}
vector<int> g[2100];
int sz[2100];
long long dp[3][2100][2100];
long long dp2[4][2100][4100];
long long fact[3100];
void solve(int a){
//		printf("%d\n",a);fflush(stdout);
	int n=g[a].size();
	dp2[0][0][0]=1;
	for(int i=0;i<g[a].size();i++){
		solve(g[a][i]);
	}
	for(int i=0;i<g[a].size();i++){
		int T=sz[a];
		sz[a]+=sz[g[a][i]];
		int to=g[a][i];
		for(int j=0;j<=sz[a]+10;j++){
			dp2[0][i+1][j]=dp2[1][i+1][j]=dp2[2][i+1][j]=dp2[3][i+1][j]=0;
		}
		for(int j=0;j<=T;j++){
		//	if(a==1&&j<2)printf("%d %d: %lld %lld %lld\n",i,j,dp2[0][i][j],dp2[1][i][j],dp2[2][i][j]);

			for(int k=0;k<=sz[g[a][i]]+1;k++){
				dp2[0][i+1][j+k]=(dp2[0][i+1][j+k]+dp2[0][i][j]*dp[0][to][k])%mod;
				dp2[1][i+1][j+k]=(dp2[1][i+1][j+k]+dp2[0][i][j]*dp[1][to][k])%mod;
				dp2[1][i+1][j+k]=(dp2[1][i+1][j+k]+dp2[1][i][j]*dp[0][to][k])%mod;
				dp2[2][i+1][j+k]=(dp2[2][i+1][j+k]+dp2[2][i][j]*dp[0][to][k])%mod;
				dp2[2][i+1][j+k]=(dp2[2][i+1][j+k]+dp2[0][i][j]*dp[2][to][k])%mod;
				dp2[3][i+1][j+k]=(dp2[3][i+1][j+k]+dp2[1][i][j]*dp[2][to][k])%mod;
				dp2[3][i+1][j+k]=(dp2[3][i+1][j+k]+dp2[2][i][j]*dp[1][to][k])%mod;
				dp2[3][i+1][j+k]=(dp2[3][i+1][j+k]+dp2[3][i][j]*dp[0][to][k])%mod;
				
			}
		}
	}

	//if(a==1)printf("%d %d: %lld %lld %lld\n",4,0,dp2[0][4][0],dp2[1][4][0],dp2[2][4][0]);
	//if(a==1)printf("%d %d: %lld %lld %lld\n",4,1,dp2[0][4][1],dp2[1][4][1],dp2[2][4][1]);

	//	printf("AA\n");fflush(stdout);
	for(int i=0;i<=sz[a];i++){
		dp[0][a][i]=(dp2[0][n][i]+dp2[1][n][i]+dp2[2][n][i]+dp2[3][n][i])%mod;
		dp[1][a][i+1]=(dp2[0][n][i]+dp2[1][n][i])%mod;
		dp[2][a][i+1]=(dp2[0][n][i]+dp2[2][n][i])%mod;
//		if(i<=1)printf("%d %d: %lld %lld\n",a,i,dp[0][a][i],dp[1][a][i]);

	}
//	if(sz[a]+1==1)printf("%d %d: %lld %lld\n",a,sz[a]+1,dp[0][a][sz[a]+1],dp[1][a][sz[a]+1]);
	sz[a]++;
}
int main(){
	int a;scanf("%d",&a);
	for(int i=0;i<a-1;i++){
		int p;scanf("%d",&p);
		p--;
	//	printf("%d %d\n",i+1,p);fflush(stdout);
		g[p].push_back(i+1);
	}
	solve(0);
	long long ret=0;
	fact[0]=1;
	for(int i=1;i<3100;i++)fact[i]=fact[i-1]*i%mod;

	for(int i=0;i<=a;i++){
	//	printf("%d: %lld\n",i,dp[0][0][i]);
		if(i%2==0)ret=(ret+dp[0][0][i]*fact[a-i]%mod)%mod;
		else ret=(ret+mod-dp[0][0][i]*fact[a-i]%mod)%mod;
	}
	printf("%lld\n",ret);
}