#include <bits/stdc++.h>

#define N 105
#define Mo 998244353

#define pb push_back
#define mk make_pair
#define fi first
#define se second

using namespace std;

int dp[N][N][N * N], n, a[N], fac[N];

int main()
{
	scanf("%d", &n); fac[0] = 1; for (int i = 1; i <= n; ++i) fac[i] = 1ll * fac[i - 1] * i % Mo;
	for (int i = 1; i <= n; ++i) scanf("%d", &a[i]), a[0] += a[i];
	dp[0][0][0] = 1;
	for (int i = 0; i < n; ++i)
		for (int j = 0; j < n; ++j)
			for (int k = 0; k <= 100 * n; ++k)
				(dp[i + 1][j][k] += dp[i][j][k]) %= Mo,
				(dp[i + 1][j + 1][k + a[i + 1]] += dp[i][j][k]) %= Mo;
	int ans = 0;
	if (a[0] % 2 == 0)
	for (int j = 1; j <= n; ++j)
		(ans += 1ll * fac[j] * fac[n - j] % Mo * dp[n][j][a[0] / 2] % Mo) %= Mo;
	printf("%d\n", ans);
}
#include <bits/stdc++.h>
using namespace std;
typedef long long LL;
typedef unsigned long long ULL;

const int MAXN = 100005;
int f[MAXN], sz[MAXN], n;
vector<int> son[MAXN];
struct Data {
	int a, b;
	bool operator<(const Data &d) const {
		return a - b < d.a - d.b;
	}
};

void dfs(int u) {
	sz[u] = 1;
	vector<Data> v0, v1;
	for (int v : son[u]) {
		dfs(v);
		sz[u] += sz[v];
		if (sz[v] & 1) v1.push_back(Data { f[v], sz[v] - f[v] });
		else v0.push_back(Data { f[v], sz[v] - f[v] });
	}
	for (const Data &d : v0) {
		if (d.a <= d.b) f[u] += d.a;
	}
	sort(v1.begin(), v1.end());
	for (int i = 0; i < (int)v1.size(); i++) {
		if (i & 1) f[u] += v1[i].b;
		else f[u] += v1[i].a;
	}
	if (v1.size() & 1) {
		for (const Data &d : v0) {
			if (d.a > d.b) f[u] += d.b;
		}
	} else {
		for (const Data &d : v0) {
			if (d.a > d.b) f[u] += d.a;
		}
	}
	++f[u];
}

int main() {
	scanf("%d", &n);
	for (int i = 2; i <= n; i++) {
		int p; scanf("%d", &p);
		son[p].push_back(i);
	}
	dfs(1);
	printf("%d\n", f[1]);
	return 0;
}