#include <bits/stdc++.h>
using namespace std;
long long gcd(long long a, long long b) { return b == 0 ? a : gcd(b, a % b); }
const int MAXN = 100000;
int n;
int val[MAXN];
int par[MAXN];
int chead[MAXN], cnxt[MAXN];
int d[MAXN];
map<int, int> cnt;
void dfs(int at) {
  d[at] = par[at] == -1 ? 0 : d[par[at]] + 1;
  for (int to = chead[at]; to != -1; to = cnxt[to]) dfs(to);
}
void run() {
  scanf("%d", &n);
  for (int i = (0); i < (n); ++i) scanf("%d", &val[i]);
  par[0] = -1;
  for (int i = (1); i < (n); ++i) scanf("%d", &par[i]), --par[i];
  for (int i = (0); i < (n); ++i) chead[i] = -1;
  for (int i = n - 1; i >= 0; --i)
    if (par[i] != -1) cnxt[i] = chead[par[i]], chead[par[i]] = i;
  dfs(0);
  int fstleaf = -1;
  for (int i = (0); i < (n); ++i)
    if (chead[i] == -1) {
      fstleaf = i;
      break;
    }
  assert(fstleaf != -1);
  cnt.clear();
  int sum = 0, nsame = 0, ndiff = 0;
  for (int i = (0); i < (n); ++i)
    if (d[i] % 2 == d[fstleaf] % 2)
      sum ^= val[i], ++nsame;
    else
      cnt[val[i]]++, ++ndiff;
  long long ret = 0;
  if (sum == 0) ret += (long long)nsame * (nsame - 1) / 2;
  if (sum == 0) ret += (long long)ndiff * (ndiff - 1) / 2;
  for (int i = (0); i < (n); ++i)
    if (d[i] % 2 == d[fstleaf] % 2) ret += cnt[sum ^ val[i]];
  printf("%lld\n", ret);
}
int main() {
  run();
  return 0;
}
