#include <bits/stdc++.h>
using namespace std;
const long long maxn = 100005;
long long n;
long long a[maxn];
vector<long long> G[maxn], N[2];
long long note;
void dfs(long long u, long long fa, long long deep) {
  if (G[u].size() == 1) note = deep % 2;
  N[deep % 2].push_back(a[u]);
  for (long long i = 0; i < G[u].size(); i++) {
    long long v = G[u][i];
    if (v == fa) continue;
    dfs(v, u, deep + 1);
  }
}
long long comb2(long long n) {
  if (n < 2) return 0;
  return n * (n - 1) / 2;
}
int main() {
  while (scanf("%I64d", &n) == 1) {
    for (long long i = 0; i < 2; i++) N[i].clear();
    for (long long i = 1; i <= n; i++) G[i].clear();
    for (long long i = 1; i <= n; i++) scanf("%I64d", &a[i]);
    for (long long u = 2; u <= n; u++) {
      long long v;
      scanf("%I64d", &v);
      G[u].push_back(v);
      G[v].push_back(u);
    }
    dfs(1, -1, 0);
    long long tmp = 0;
    for (long long i = 0; i < N[note].size(); i++) tmp ^= N[note][i];
    if (tmp == 0) {
      long long ans = comb2(N[0].size()) + comb2(N[1].size());
      map<long long, long long> cnt;
      cnt.clear();
      for (long long i = 0; i < N[note ^ 1].size(); i++) cnt[N[note ^ 1][i]]++;
      for (long long i = 0; i < N[note].size(); i++) ans += cnt[N[note][i]];
      printf("%I64d\n", ans);
    } else {
      long long ans = 0;
      map<long long, long long> cnt;
      cnt.clear();
      for (long long i = 0; i < N[note].size(); i++) cnt[N[note][i]]++;
      for (long long i = 0; i < N[note ^ 1].size(); i++)
        ans += cnt[tmp ^ (N[note ^ 1][i])];
      printf("%I64d\n", ans);
    }
  }
  return 0;
}
