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;

const int N = 2005;
const int mod = 1e9 + 7;
const int half = 5e8 + 4;

int n;
int sz[N]; // number of edges
int prd[N];
int f[N][N][3]; // (i, j, k) subtree i, number of edges: j, number of edges connect to i: k
int g[N][N][3]; // knapsack
vector<int> G[N];

// a fixed set of edges has number of edges: i and number of components: j
// number of ways *= (2 ^ j) * (n - i)! * ((-1) ^ i)

void add(int &x, int y) {
	x = (x + y) >= mod ? (x + y - mod) : (x + y);
}

void dfs(int u) {
	for (auto v : G[u]) dfs(v);
	int id = 0;
	g[0][0][0] = 1;
	for (auto v : G[u]) {
		++id;
		// reset
		for (int i = 0; i <= sz[u] + sz[v] + 1; ++i) {
			for (int j = 0; j <= 2; ++j) g[id][i][j] = 0;
		}
		for (int i = 0; i <= sz[u]; ++i) {
			for (int j = 0; j <= sz[v]; ++j) {
				for (int k = 0; k <= 2; ++k) {
					// do not use u-v edge
					for (int l = 0; l <= 2; ++l) {
						add(g[id][i + j][k], 1LL * g[id - 1][i][k] * f[v][j][l] % mod); 
					}
					// use u-v edge
					if (k == 0) {
						add(g[id][i + j + 1][k + 1], 2LL * g[id - 1][i][k] * f[v][j][0] % mod);
						add(g[id][i + j + 1][k + 1], 1LL * g[id - 1][i][k] * f[v][j][1] % mod);
					}
					if (k == 1) {
						add(g[id][i + j + 1][k + 1], 1LL * g[id - 1][i][k] * f[v][j][0] % mod);
						add(g[id][i + j + 1][k + 1], 1LL * g[id - 1][i][k] * f[v][j][1] % mod * half % mod);
					}
				}
			}
		}
		sz[u] += sz[v] + 1;
	}
	// cout << "At " << u << '\n';
	for (int i = 0; i <= sz[u]; ++i) {
		for (int j = 0; j <= 2; ++j) {
			f[u][i][j] = g[id][i][j];
			// cout << f[u][i][j] << ' ' << i << ' ' << j << '\n';
 		}
 	}
}

int main() {
	ios::sync_with_stdio(false);
	cin >> n;
	for (int i = 2; i <= n; ++i) {
		int p; cin >> p, G[p].push_back(i);
	}
	dfs(1);
	prd[0] = 1; 
	for (int i = 1; i <= n; ++i) prd[i] = 1LL * prd[i - 1] * i % mod;
	int res = 0;
	for (int i = 0; i < n; ++i) {
		int tmp = 0;
		for (int j = 0; j <= 2; ++j) add(tmp, f[1][i][j]);
		// inclusion-exclusion
		if (i & 1) tmp = mod - tmp;
		add(res, 1LL * tmp * prd[n - i] % mod);
	}
	cout << res;
}