#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;
}
