#include <bits/stdc++.h>
using namespace std;
int arahbar[8] = {0, 1, 0, -1, 1, 1, -1, -1};
int arahkol[8] = {1, 0, -1, 0, 1, -1, -1, 1};
int kudabar[8] = {-2, -1, 1, 2, 2, 1, -1, -2};
int kudakol[8] = {1, 2, 2, 1, -1, -2, -2, -1};
template <typename T>
T getNum() {
  T res = 0;
  char c;
  while (1) {
    c = getchar();
    if (c == ' ' || c == '\n')
      continue;
    else
      break;
  }
  bool negatif;
  if (c == '-') {
    negatif = true;
    res = 0;
  } else {
    res = c - '0';
    negatif = false;
  }
  while (1) {
    c = getchar();
    if ('0' <= c && c <= '9')
      res = res * 10 + c - '0';
    else
      break;
  }
  if (negatif) res *= -1;
  return res;
}
inline void boost() {
  ios_base::sync_with_stdio(0);
  cin.tie(NULL);
}
int apel[100005];
vector<int> AdjList[100005];
int xorS = 0;
bool penting[100005];
vector<int> dp;
map<int, int> frek;
void rek(int x) {
  if (!AdjList[x].size()) {
    penting[x] = true;
    xorS ^= apel[x];
    dp.push_back(x);
    return;
  }
  for (int i = 0; i < (int)AdjList[x].size(); i++) {
    int v = AdjList[x][i];
    rek(v);
  }
  int v = AdjList[x][0];
  if (penting[v]) {
    penting[x] = false;
    frek[apel[x]]++;
  } else {
    penting[x] = true;
    xorS ^= apel[x];
    dp.push_back(x);
  }
  return;
}
int main() {
  int n;
  scanf("%d", &n);
  for (int i = (int)1; i <= (int)n; i++) scanf("%d", &apel[i]);
  for (int i = (int)2; i <= (int)n; i++) {
    int x;
    scanf("%d", &x);
    AdjList[x].push_back(i);
  }
  rek(1);
  long long ans = 0;
  if (!xorS) {
    long long wew = (long long)dp.size();
    ans += wew * (wew - 1) / 2;
    wew = (long long)n - wew;
    ans += wew * (wew - 1) / 2;
  }
  for (int i = 0; i < (int)dp.size(); i++) {
    int v = xorS ^ apel[dp[i]];
    ans += (long long)frek[v];
  }
  cout << ans << endl;
  return 0;
}
