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 <algorithm>  
#include <iostream>  
#include <sstream>  
#include <string>  
#include <cstring>
#include <vector>  
#include <queue>  
#include <set>  
#include <map>  
#include <cstdio>  
#include <cstdlib>  
#include <cctype>  
#include <cmath>  
#include <list>  
#include <cassert>
#include <ctime>
#include <climits>
using namespace std;  

#define PB push_back  
#define MP make_pair  
#define SZ(v) ((int)(v).size())  
#define FOR(i,a,b) for(int i=(a);i<(b);++i)  
#define REP(i,n) FOR(i,0,n)  
#define FORE(i,a,b) for(int i=(a);i<=(b);++i)  
#define REPE(i,n) FORE(i,0,n)  
#define FORSZ(i,a,v) FOR(i,a,SZ(v))  
#define REPSZ(i,v) REP(i,SZ(v))  
typedef long long ll;
typedef unsigned long long ull;
ll gcd(ll a,ll b) { return b==0?a:gcd(b,a%b); }

const int MAXN = 2000;
const int MOD = 1000000007;
const int INV2 = (MOD + 1) / 2;

int n;
int par[MAXN];

int fac[MAXN + 1];

int sz[MAXN];
int ways[MAXN][MAXN + 1][3]; // ways[i][j][k] = the number of ways to make directed paths in the subtree of i with total length j, with the root connected to k childs

void run() {
	fac[0] = 1; FORE(i, 1, MAXN) fac[i] = (ll)fac[i - 1] * i%MOD;

	scanf("%d", &n); par[0] = -1; FOR(i, 1, n) scanf("%d", &par[i]), --par[i];

	REP(i, n) sz[i] = 1;
	memset(ways, 0, sizeof(ways));
	REP(i, n) ways[i][0][0] = 1;
	for (int a = n - 1; a >= 0; --a) if(par[a]!=-1) {
		int b = par[a];
		for (int bk = 2; bk >= 0; --bk) for (int bj = sz[b] - 1; bj >= 0; --bj) if (ways[b][bj][bk] != 0) {
			int bways = ways[b][bj][bk]; ways[b][bj][bk] = 0;
			REPE(ak, 2) REPE(aj, sz[a] - 1) if (ways[a][aj][ak] != 0) REP(use, 2) {
				if (use == 1 && (ak == 2 || bk == 2)) continue;
				int aways = ways[a][aj][ak], nbk = bk + use, nbj = bj + aj + use, mlt = use == 0 ? 1 : ak == 1 && bk == 1 ? INV2 : ak == 1 || bk == 1 ? 1 : 2;
				ways[b][nbj][nbk] = (ways[b][nbj][nbk] + (ll)bways*aways%MOD*mlt) % MOD;
			}
		}
		sz[b] += sz[a];
		//REPE(j, sz[b] - 1) REPE(k, 2) if (ways[b][j][k] != 0) printf("ways[%d][%d][%d]=%d\n", b + 1, j, k, ways[b][j][k]);
	}
	//REP(i, n) REPE(j, sz[i] - 1) REPE(k, 2) if (ways[i][j][k] != 0) printf("ways[%d][%d][%d]=%d\n", i + 1, j, k, ways[i][j][k]);

	int ret = 0;
	REPE(j, sz[0] - 1) REPE(k, 2) if (ways[0][j][k] != 0) {
		int cur = (ll)ways[0][j][k] * fac[n - j] % MOD;
		if (j % 2 == 1) cur = cur == 0 ? 0 : MOD - cur;
		ret = (ret + cur) % MOD;
	}
	printf("%d\n", ret);
}

int main() {
	run();
	return 0;
}