#include <bits/stdc++.h>
using namespace std;
int main() {
  ios::sync_with_stdio(false);
  int n;
  cin >> n;
  vector<int> a(n);
  for (int &e : a) {
    cin >> e;
  }
  vector<int> p(n, -1);
  vector<vector<int>> g(n);
  for (int i = 1; i < n; i++) {
    cin >> p[i];
    p[i]--;
    g[p[i]].push_back(i);
    g[i].push_back(p[i]);
  }
  int leaf = -1;
  for (int i = 1; i < n; i++) {
    if (g[i].size() == 1) {
      leaf = i;
    }
  }
  queue<int> q;
  vector<int> us(n, -1);
  vector<int> es[2];
  q.push(leaf);
  us[leaf] = 0;
  while (!q.empty()) {
    int v = q.front();
    es[us[v]].push_back(a[v]);
    q.pop();
    for (int u : g[v]) {
      if (us[u] == -1) {
        us[u] = us[v] ^ 1;
        q.push(u);
      }
    }
  }
  int G = accumulate(begin(es[0]), end(es[0]), 0, std::bit_xor<int>());
  map<int, long long> cnts[2];
  long long cnt[2] = {};
  for (int i = 0; i < 2; i++) {
    for (auto e : es[i]) {
      cnts[i][e]++;
      cnt[i]++;
    }
  }
  long long answer = 0;
  for (int i = 0; i < 2; i++) {
    for (auto e : es[i]) {
      answer += cnts[i ^ 1][e ^ G];
      if (G == 0) answer += cnt[i] - 1;
    }
  }
  answer /= 2;
  cout << answer << "\n";
  return 0;
}
