#include <bits/stdc++.h>
using namespace std;
const int M = 1e5 + 10;
map<int, int> num;
vector<int> vc[M];
int ans, val[M], deep[M], maxdeep;
void dfs(int u, int pre, int d) {
  int len = vc[u].size();
  deep[u] = d;
  maxdeep = max(maxdeep, d);
  for (int i = 0; i < len; i++) {
    int v = vc[u][i];
    if (v == pre) continue;
    dfs(v, u, d + 1);
  }
}
int main() {
  int n;
  scanf("%d", &n);
  num.clear();
  for (int i = 0; i <= n; i++) vc[i].clear();
  for (int i = 1; i <= n; i++) {
    int gg;
    scanf("%d", &gg);
    val[i] = gg;
    num[gg]++;
  }
  for (int i = 1; i < n; i++) {
    int gg;
    scanf("%d", &gg);
    vc[gg].push_back(i + 1);
    vc[i + 1].push_back(gg);
  }
  maxdeep = 0;
  dfs(1, -1, 1);
  for (int i = 1; i <= n; i++) {
    if ((maxdeep % 2) == (deep[i] % 2)) {
      num[val[i]]--, ans ^= val[i];
    }
  }
  long long count = 0;
  if (ans == 0) {
    long long sum = 0;
    for (int i = 1; i <= n; i++) {
      if ((maxdeep % 2) == (deep[i] % 2)) {
        count += num[val[i]];
      } else
        sum++;
    }
    count += (sum * (sum - 1) / 2 + (n - sum) * (n - sum - 1) / 2);
  } else {
    for (int i = 1; i <= n; i++) {
      if ((maxdeep % 2) == (deep[i] % 2)) {
        count += num[(ans ^ val[i])];
      }
    }
  }
  printf("%lld\n", count);
  return 0;
}
