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>
const int N = 2005;
const int mod = 1e9 + 7;
using namespace std;

vector <int> G[N];
int n, dp[N][N][3], g[N][3], c[N], ans;

void add(int&a, int b){
    a += b; if (a >= mod) a -= mod; if (a < 0) a += mod;
}

void dfs(int u){
    c[u] = 0;
    dp[u][0][0] = 1;
    for (auto v : G[u]){
        dfs(v);
        for (int i = 0; i <= c[u]+c[v]+1; i++) g[i][0] = g[i][1] = g[i][2] = 0;
        for (int i = 0; i <= c[u]; i++) for (int j = 0; j <= c[v]; j++){
            add(g[i+j][0], 1LL * dp[u][i][0] * dp[v][j][0] % mod);
            add(g[i+j][1], 1LL * dp[u][i][1] * dp[v][j][0] % mod);
            add(g[i+j+1][1], 1LL * dp[u][i][0] * dp[v][j][1] % mod);
            add(g[i+j][2], 1LL * dp[u][i][2] * dp[v][j][0] % mod);
            add(g[i+j+1][2], 1LL * dp[u][i][1] * dp[v][j][1] % mod);
        }
        for (int i = 0; i <= c[u]+c[v]+1; i++) dp[u][i][0] = g[i][0], dp[u][i][1] = g[i][1], dp[u][i][2] = g[i][2];
        c[u] += c[v] + 1;
    }
    for (int i = 0; i <= c[u]; i++){
        int a = dp[u][i][0], b = dp[u][i][1], c = dp[u][i][2];
        dp[u][i][0] = a; add(dp[u][i][0], 2LL * b % mod); add(dp[u][i][0], 2LL * c % mod);
        dp[u][i][1] = a; add(dp[u][i][1], b);
    }
}

int main(){
    ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0);
    cin >> n;
    for (int i = 2; i <= n; i++){
        int x; cin >> x;
        G[x].push_back(i);
    }
    dfs(1); int f = 1;
    for (int i = n-1; i >= 0; i--){
        f = 1LL * f * (n - i) % mod;
        if (i&1) add(ans, -1LL * f * dp[1][i][0] % mod);
        else add(ans, 1LL * f * dp[1][i][0] % mod);
    }
    cout << ans;
}