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 <cstdio>
#include <cstring>
#include <vector>

const int N = 2000;
const int MOD = (int)1e9 + 7;

int n, fact[N + 1], size[N], dp[N][3][N];
std::vector<int> children[N];

void update(int& x, int a)
{
    x += a;
    if (x >= MOD) {
        x -= MOD;
    }
}

void dfs(int u)
{
    static int tmp[3][N];

    size[u] = 1;
    dp[u][0][0] = 1;
    for (auto v : children[u]) {
        dfs(v);
        int ns = size[u] + size[v];
        for (int t = 0; t < 3; ++ t) {
            memset(tmp[t], 0, sizeof(int) * ns);
        }
        for (int t = 0; t < 3; ++ t) {
            for (int x = 0; x < size[u]; ++ x) {
                if (!dp[u][t][x]) {
                    continue;
                }
                for (int y = 0; y < size[v]; ++ y) {
                    for (int tt = 0; tt < 3; ++ tt) {
                        if (!dp[v][tt][y]) {
                            continue;
                        }
                        auto pd = 1LL * dp[u][t][x] * dp[v][tt][y] % MOD;
                        if (t < 2 && tt < 2) {
                            update(tmp[t + 1][x + y + 1], pd);
                        }
                        if (tt == 0) {
                            pd = 500000004LL * pd % MOD;
                        }
                        update(tmp[t][x + y], pd);
                    }
                }
            }
        }
        for (int t = 0; t < 3; ++ t) {
            memcpy(dp[u][t], tmp[t], sizeof(int) * ns);
        }
        size[u] += size[v];
    }
}

int main()
{
#ifdef LOCAL_JUDGE
    freopen("A.in", "r", stdin);
#endif
    scanf("%d", &n);
    fact[0] = 1;
    for (int i = 1; i <= n; ++ i) {
        fact[i] = 2LL * fact[i - 1] * i % MOD;
    }
    for (int i = 1, p; i < n; ++ i) {
        scanf("%d", &p);
        children[p - 1].push_back(i);
    }
    memset(dp, 0, sizeof(dp));
    dfs(0);
    int result = 0;
    for (int i = 0; i < n; ++ i) {
        int add = 1LL * fact[n - i] * (500000004LL * dp[0][0][i] % MOD + dp[0][1][i] + dp[0][2][i]) % MOD;
        if (i & 1) {
            add = MOD - add;
        }
        update(result, add);
    }
    printf("%d\n", result);
}