#include <bits/stdc++.h>
using namespace std;
const int MAXN = 2000005;
int n, f, a[MAXN], b[MAXN], v[MAXN], dep[MAXN], sa, sb, xornum, na, nb,
    co[(1 << 24) + 5], maxd;
long long ans;
struct node {
  int v;
  node *next;
} * head[MAXN];
void ad(int u, int v) {
  node *p = new node;
  p->v = v;
  p->next = head[u];
  head[u] = p;
}
void dfs(int u, int d) {
  dep[u] = d;
  maxd = max(maxd, d);
  for (node *p = head[u]; p; p = p->next) {
    if (!dep[p->v]) dfs(p->v, d + 1);
  }
}
int main() {
  cin >> n;
  for (int i = 1; i <= n; i++) scanf("%d", &v[i]);
  for (int i = 2; i <= n; i++) {
    scanf("%d", &f);
    ad(f, i);
  }
  dfs(1, 0);
  for (int i = 1; i <= n; i++)
    if (!((maxd - dep[i]) & 1))
      a[++sa] = v[i];
    else
      b[++sb] = v[i];
  for (int i = 1; i <= sa; i++) xornum ^= a[i];
  for (int i = 1; i <= sa; i++) a[i] ^= xornum, co[a[i]]++;
  for (int i = 1; i <= sb; i++) ans += 1ll * co[b[i]];
  if (!xornum) ans += 1ll * sa * (sa - 1) / 2 + 1ll * sb * (sb - 1) / 2;
  cout << ans;
  return 0;
}
