#include <bits/stdc++.h>
using namespace std;
inline void Rd(int &res) {
  char c;
  res = 0;
  while (c = getchar(), c < '0')
    ;
  do {
    res = (res << 1) + (res << 3) + (c ^ 48);
  } while (c = getchar(), c >= '0');
}
const int M = (int)1e5 + 5;
struct Node {
  int to, nxt;
} Edge[M];
int Head[M], tot;
int n, p, A[M], P[M], S;
map<int, int> mp1, mp2;
inline void Addedge(int a, int b) {
  Edge[tot] = (Node){b, Head[a]};
  Head[a] = tot++;
}
void dfs(int x, int f, int d) {
  bool leaf = true;
  P[x] = d & 1;
  for (int i = Head[x]; ~i; i = Edge[i].nxt) {
    int to = Edge[i].to;
    if (to == f) continue;
    leaf = false;
    dfs(to, x, d + 1);
  }
  if (leaf) p = d & 1;
}
int main() {
  Rd(n);
  memset(Head, -1, sizeof(Head));
  for (int i = 1; i <= n; i++) Rd(A[i]);
  for (int i = 2; i <= n; i++) {
    int x;
    Rd(x);
    Addedge(x, i);
  }
  dfs(1, 0, 1);
  long long ans = 0;
  for (int i = 1; i <= n; i++)
    if (P[i] == p) S ^= A[i];
  for (int i = 1; i <= n; i++) {
    if (P[i] == p) {
      ans += mp2[S ^ A[i]];
      mp1[A[i]]++;
    } else {
      ans += mp1[S ^ A[i]];
      mp2[A[i]]++;
    }
  }
  if (!S) {
    int cnt1 = 0, cnt2 = 0;
    for (int i = 1; i <= n; i++) {
      if (P[i] == p)
        cnt1++;
      else
        cnt2++;
    }
    ans += (long long)cnt1 * (cnt1 - 1) / 2;
    ans += (long long)cnt2 * (cnt2 - 1) / 2;
  }
  cout << ans << endl;
  return 0;
}
