#include <bits/stdc++.h>
using namespace std;
const long long MX = 1e5 + 10, MOD = 1e9 + 7;
const long double pi = 3.14159265359;
long long n, sib[MX], ans, odd1, even1;
vector<long long> child[MX];
map<long long, long long> even, odd;
bool parr[MX];
long long dfs(long long v) {
  if (child[v].size() == 0) {
    parr[v] = 0;
    return 0;
  }
  for (long long i : child[v]) dfs(i);
  parr[v] = parr[child[v][0]] ^ 1;
  return parr[v];
}
int32_t main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  cin >> n;
  for (long long i = 0; i < n; i++) cin >> sib[i];
  for (long long i = 1; i < n; i++) {
    long long p;
    cin >> p;
    child[p - 1].push_back(i);
  }
  dfs(0);
  long long sum = 0;
  for (long long i = 0; i < n; i++) {
    if (parr[i])
      odd[sib[i]]++, odd1++;
    else {
      even[sib[i]]++;
      even1++;
      sum ^= sib[i];
    }
  }
  if (!sum) {
    ans = odd1 * (odd1 - 1) / 2;
    ans += even1 * (even1 - 1) / 2;
    for (auto it : odd) {
      long long a = it.first;
      ans += (it.second) * (even[a]);
    }
  } else {
    for (auto it : odd) {
      long long a = it.first;
      long long b = sum ^ a;
      ans += (it.second) * (even[b]);
    }
  }
  if (!ans) return cout << 0, 0;
  cout << ans;
}
