#include <bits/stdc++.h>
using namespace std;
int ton[2][25000001], n;
int h[200005], to[200005], ne[200005], en = 0, dep[200005], a[200005], cnt;
void add(int a, int b) {
  to[en] = b;
  ne[en] = h[a];
  h[a] = en++;
}
void dfs(int o) {
  dep[o] = 1;
  for (int i = h[o]; i >= 0; i = ne[i]) {
    dfs(to[i]);
    dep[o] = dep[to[i]] ^ 1;
  }
  if (dep[o] == 1) cnt++;
  ton[dep[o] & 1][a[o]]++;
}
int main() {
  memset(h, -1, sizeof h);
  scanf("%d", &n);
  for (int i = 1; i <= n; ++i) scanf("%d", &a[i]);
  for (int i = 2; i <= n; ++i) {
    int x;
    scanf("%d", &x);
    add(x, i);
  }
  dfs(1);
  int Xor = 0;
  long long ans = 0;
  for (int i = 1; i <= 10000000; ++i)
    if (ton[1][i] & 1) Xor ^= i;
  for (int i = 1; i <= 10000000; ++i)
    if (ton[1][i] > 0) {
      int tmp = Xor ^ i;
      ans += (long long)ton[1][i] * ton[0][tmp];
    }
  if (Xor == 0)
    ans += (long long)cnt * (cnt - 1) / 2,
        ans += (long long)(n - cnt) * (n - cnt - 1) / 2;
  printf("%I64d\n", ans);
}
