#include <bits/stdc++.h>
using ld = double;
using namespace std;
const double eps = (1e-12);
const int INF = 2e9 + 9;
const int logn = 21;
const double pi = acos(-1.0);
long long dep[200005];
long long father[200005];
long long vis[200005];
vector<vector<long long> > g(200005);
long long flag = 0;
map<long long, long long> mp;
void dfs(long long u) {
  if (vis[u]) return;
  vis[u] = true;
  bool leaf = true;
  for (long long i = 0; i < g[u].size(); i++) {
    long long v = g[u][i];
    if (!vis[v]) {
      dep[v] = dep[u] + 1;
      dfs(v);
      leaf = false;
    }
  }
  if (leaf) {
    flag = dep[u] % 2;
  }
}
long long nums[200005];
signed main() {
  long long n;
  scanf("%lld", &n);
  for (long long i = 1; i <= n; i++) scanf("%lld", &nums[i]);
  for (long long i = 2; i <= n; i++) {
    long long p;
    scanf("%lld", &p);
    father[i] = p;
    g[i].push_back(p);
    g[p].push_back(i);
  }
  dfs(1);
  long long sum = 0;
  long long cnt = 0;
  for (long long i = 1; i <= n; i++) {
    if (dep[i] % 2 == flag) {
      sum = sum ^ nums[i];
      cnt++;
    } else {
      mp[nums[i]]++;
    }
  }
  long long ans = 0;
  if (sum == 0) ans += cnt * (cnt - 1) / 2 + (n - cnt) * (n - cnt - 1) / 2;
  for (long long i = 1; i <= n; i++) {
    if (dep[i] % 2 == flag) {
      sum = sum ^ nums[i];
      ans += mp[sum];
      sum = sum ^ nums[i];
    }
  }
  printf("%lld", ans);
  return 0;
}
