#include <bits/stdc++.h>
using namespace std;
int n, A[100005], Osum, Xsum;
vector<int> v[100005];
map<int, int> O, X;
int dfs(int now) {
  if (v[now].empty()) {
    O[A[now]]++;
    ++Osum;
    return 1;
  }
  int k = -1;
  for (int i = 0; i < v[now].size(); i++) {
    int nxt = v[now][i];
    k = dfs(nxt);
  }
  if (k == 1) {
    X[A[now]]++;
    ++Xsum;
  } else {
    O[A[now]]++;
    ++Osum;
  }
  return (k ^ 1);
}
int main() {
  scanf("%d", &n);
  for (int i = 1; i <= n; i++) scanf("%d", &A[i]);
  for (int p, i = 2; i <= n; i++) {
    scanf("%d", &p);
    v[p].push_back(i);
  }
  dfs(1);
  int key = 0;
  auto it = O.begin();
  while (it != O.end()) {
    if (it->second & 1) key ^= it->first;
    ++it;
  }
  long long ans = 0;
  if (key == 0) {
    ans += (long long)Osum * (Osum - 1) / 2;
    ans += (long long)Xsum * (Xsum - 1) / 2;
    it = O.begin();
    while (it != O.end()) {
      auto it2 = X.find(it->first);
      if (it2 != X.end()) {
        ans += (long long)it->second * it2->second;
      }
      ++it;
    }
  } else {
    it = O.begin();
    while (it != O.end()) {
      auto it2 = X.find(key ^ it->first);
      if (it2 != X.end()) {
        ans += (long long)it->second * it2->second;
      }
      ++it;
    }
  }
  cout << ans << endl;
}
