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 int64_t MOD = 1e9+7;
void add(int64_t& a, int64_t b){
    a = (a+b) % MOD;
}
void mul(int64_t& a, int64_t b){
    a = a*b % MOD;
}

vector<int64_t> fact, seq_inv, fact_inv;

void create_fact_mod(int num){
    fact[0] = 1;
    fact[1] = 1;
    for(int i=2; i<=num; i++){
        fact[i] = fact[i-1] * i % MOD;
    }
}

void create_seq_inv_mod(int num){
    seq_inv[0] = 1;
    seq_inv[1] = 1;
    for(int i=2; i<=num; i++){
        seq_inv[i] = (MOD - MOD/i) * seq_inv[MOD%i] % MOD;
    }
}

void create_fact_inv_mod(int num){
    fact_inv[0] = 1;
    fact_inv[1] = 1;
    for(int i=2; i<=num; i++){
        fact_inv[i] = fact_inv[i-1] * seq_inv[i] % MOD;
    }
}

void create_mod_tables(int num){
    fact.resize(num+1);
    seq_inv.resize(num+1);
    fact_inv.resize(num+1);
    create_fact_mod(num);
    create_seq_inv_mod(num);
    create_fact_inv_mod(num);
}

int64_t comb_mod(int n, int k){
    return fact[n] * fact_inv[n-k] % MOD * fact_inv[k] % MOD;
}

int64_t perm_mod(int n, int k){
    return fact[n] * fact_inv[n-k] % MOD;
}

int64_t power_mod(int64_t num, int64_t power){
    int64_t prod = 1;
    num %= MOD;
    while(power > 0){
        if(power&1) prod = prod * num % MOD;
        num = num * num % MOD;
        power >>= 1;
    }
    return prod;
}

int64_t extgcd(int64_t a, int64_t b, int64_t& x, int64_t& y){
    int64_t d = a;
    if(b != 0){
        d = extgcd(b, a%b, y, x);
        y -= (a/b) * x;
    }else{
        x = 1; y = 0;
    }
    return d;
}

int64_t inv_mod(int64_t a){
    int64_t x, y;
    extgcd(a, MOD, x, y);
    return (MOD + x%MOD) % MOD;
}

int nth_bit(int64_t num, int n){
    return (num >> n) & 1;
}

vector<int> edges[2000];

int64_t dp[2001][2001][4], sub[2001][4];
int sz[2001];

void dfs(int i1){
    sz[i1] = 1;
    dp[i1][0][0] = 1;
    for(int i2 : edges[i1]){
        dfs(i2);
        memset(sub, 0, sizeof(sub));
        for(int j1=0; j1<sz[i1]; j1++){
            for(int j2=0; j2<sz[i2]; j2++){
                for(int k1=0; k1<4; k1++){
                    for(int k2=0; k2<4; k2++){
                        int64_t res = dp[i1][j1][k1] * dp[i2][j2][k2] % MOD;
                        add(sub[j1+j2][k1], res);
                        if(nth_bit(k1, 0) == 0 && nth_bit(k2, 1) == 0){
                            add(sub[j1+j2+1][k1+1], res);
                        }
                        if(nth_bit(k1, 1) == 0 && nth_bit(k2, 0) == 0){
                            add(sub[j1+j2+1][k1+2], res);
                        }
                    }
                }
            }
        }
        sz[i1] += sz[i2];
        for(int j=0; j<sz[i1]; j++) for(int k=0; k<4; k++) dp[i1][j][k] = sub[j][k];
    }
}

int main(){
    int N;
    cin >> N;
    for(int i=1; i<N; i++){
        int p;
        cin >> p;
        edges[p-1].push_back(i);
    }

    dfs(0);

    create_mod_tables(2000);
    int64_t ans = 0;
    for(int j=0; j<N; j++){
        int64_t res = 0;
        for(int k=0; k<4; k++) add(res, dp[0][j][k]);
        mul(res, fact[N-j]);
        add(ans, j%2 ? (MOD - res) : res);
    }
    cout << ans << endl;
    return 0;
}