#include <bits/stdc++.h>
using namespace std;
const int MAX = 1e5 + 5;
vector<int> adj[MAX];
int cnt[2], x[2], arr[MAX], app[(int)1e7 + 1][2];
int n, leaves_parity;
void dfs(int source, int par) {
  app[arr[source]][par]++;
  cnt[par]++;
  x[par] ^= arr[source];
  for (auto &each : adj[source]) {
    dfs(each, !par);
  }
  if (adj[source].empty()) {
    leaves_parity = par;
  }
}
int main() {
  scanf("%d", &n);
  for (int i = int(1); i < int(n + 1); i++) {
    scanf("%d", arr + i);
  }
  for (int i = int(2); i < int(n + 1); i++) {
    int p;
    scanf("%d", &p);
    adj[p].push_back(i);
  }
  dfs(1, 0);
  long long ans = 0;
  if (x[leaves_parity] == 0) {
    ans = ((1LL * cnt[0] * (cnt[0] - 1)) / 2LL) +
          ((1LL * cnt[1] * (cnt[1] - 1)) / 2LL);
    for (int i = int(1); i < int((int)1e7 + 1); i++) {
      ans += 1LL * app[i][0] * app[i][1];
    }
  } else {
    for (int i = int(1); i < int((int)1e7 + 1); i++) {
      if ((x[leaves_parity] ^ i) <= (int)1e7) {
        ans += 1LL * app[i][leaves_parity] *
               app[x[leaves_parity] ^ i][!leaves_parity];
      }
    }
  }
  printf("%lld\n", ans);
  return 0;
}
