#include <bits/stdc++.h>
using namespace std;
int n, arr[100005], p, x, root, XOR, parity[100005];
map<int, int> cnt;
long long ans;
vector<int> to[100005];
void DFS(int u = 1, int par = 0) {
  parity[u] = par;
  if (to[u].empty()) root = par;
  for (int i : to[u]) DFS(i, !par);
}
void F(int u = 1, int par = 0) {
  if (par == root)
    XOR ^= arr[u];
  else {
    ++x;
    ++cnt[arr[u]];
  }
  for (int i : to[u]) F(i, !par);
}
int main() {
  scanf("%d", &n);
  for (int i = 1; i <= n; i++) scanf("%d", arr + i);
  for (int i = 2; i <= n; i++) {
    scanf("%d", &p);
    to[p].push_back(i);
  }
  DFS();
  F();
  if (!XOR) {
    ans = (n - x) * (long long)(n - x - 1) / 2;
    ans += x * (long long)(x - 1) / 2;
  }
  for (int i = 1; i <= n; i++) {
    if (parity[i] != root) continue;
    int f = XOR ^ arr[i];
    ans += cnt[f];
  }
  printf("%lld", ans);
  return 0;
}
