#include <bits/stdc++.h>
using namespace std;
long long INV2 = 500000004;
long long INV6 = 166666668;
long long power(long long a, long long b, long long c) {
  long long x = 1, y = a;
  while (b > 0) {
    if (b & 1) x = (x * y) % c;
    y = (y * y) % c;
    b /= 2;
  }
  return x % c;
}
int dx[] = {0, -1, 0, 1};
int dy[] = {-1, 0, 1, 0};
int dr[] = {1, 1, 0, -1, -1, -1, 0, 1};
int dc[] = {0, 1, 1, 1, 0, -1, -1, -1};
const int N = 1e5 + 5;
long long a[N], level[N], mx;
vector<int> v[N];
map<long long, long long> hasw, hasb;
bool vis[N];
void dfs(int i, long long depth) {
  vis[i] = 1;
  level[i] = depth;
  mx = max(mx, depth);
  for (int j = 0; j < v[i].size(); ++j) {
    int idx = v[i][j];
    if (!vis[idx]) {
      dfs(idx, depth + 1);
    }
  }
  return;
}
int main() {
  int n;
  scanf("%d", &n);
  for (int i = 1; i <= n; ++i) {
    scanf("%lld", &a[i]);
  }
  for (int i = 2; i <= n; ++i) {
    long long x;
    scanf("%lld", &x);
    v[x].push_back(i);
    v[i].push_back(x);
  }
  dfs(1, 0);
  int parity = mx % 2;
  long long xo = 0;
  long long cw = 0, cb = 0;
  for (int i = 1; i <= n; ++i) {
    int par = level[i] % 2;
    if (par == parity) {
      hasw[a[i]]++;
      xo ^= a[i];
      cw++;
    } else {
      hasb[a[i]]++;
      cb++;
    }
  }
  long long ans = 0;
  if (xo) {
    auto it = hasw.begin();
    while (it != hasw.end()) {
      long long val = xo ^ ((*it).first);
      ans += (hasb[val] * hasw[(*it).first]);
      ++it;
    }
  } else {
    auto it = hasw.begin();
    while (it != hasw.end()) {
      ans += (hasb[(*it).first] * hasw[(*it).first]);
      ++it;
    }
    ans += ((cw * (cw - 1)) / 2);
    ans += ((cb * (cb - 1)) / 2);
  }
  printf("%lld\n", ans);
  return 0;
}
