#include <bits/stdc++.h>
using namespace std;
const int N = 1e5;
int D, a[N], d[N];
vector<int> adj[N];
unordered_map<int, int> cnt;
void dfs(int u) {
  D = max(D, d[u]);
  for (auto v : adj[u]) d[v] = d[u] + 1, dfs(v);
}
int main() {
  int n, s = 0;
  scanf("%d", &n);
  for (int i = (0), i_end = (n); i < i_end; ++i) scanf("%d", a + i);
  for (int i = (1), i_end = (n); i < i_end; ++i) {
    int p;
    scanf("%d", &p);
    adj[p - 1].push_back(i);
  }
  dfs(0);
  D &= 1;
  long long t = 0;
  for (int i = (0), i_end = (n); i < i_end; ++i) {
    d[i] &= 1;
    if (d[i] == D) {
      s ^= a[i];
      ++cnt[a[i]];
      ++t;
    }
  }
  long long ans = s ? 0 : 1LL * n * (n - 1) / 2 - t * (n - t);
  for (int i = (0), i_end = (n); i < i_end; ++i)
    if (d[i] != D)
      if (cnt.count(s ^ a[i])) ans += cnt[s ^ a[i]];
  printf(
      "%"
      "I64"
      "d\n",
      ans);
  return 0;
}
