#include <bits/stdc++.h>
using namespace std;
long long maxe;
map<long long, long long> m1, m2;
vector<long long> adj[100050];
long long ans;
long long cost[100050];
void dfs(long long x, long long p, long long ok) {
  if (ok % 2 == 0)
    m1[cost[x]]++;
  else
    m2[cost[x]]++;
  maxe = max(ok, maxe);
  for (auto c : adj[x]) {
    if (c != p) dfs(c, x, ok + 1);
  }
}
int main() {
  long long n;
  cin >> n;
  for (long long i = 1; i <= n; i++) cin >> cost[i];
  for (long long i = 2; i <= n; i++) {
    long long x;
    cin >> x;
    adj[x].push_back(i);
  }
  dfs(1, 1, 0);
  if (maxe % 2 != 0) {
    long long r = 0, a1 = 0, a2 = 0;
    for (auto c : m2) {
      if (c.second % 2 != 0) r ^= c.first;
      a1 += c.second;
    }
    if (r == 0) {
      ans += a1 * (a1 - 1) / 2;
      a2 = 0;
      for (auto c : m1) a2 += c.second;
      ans += (a2 * (a2 - 1)) / 2;
    }
    for (auto c : m2) {
      long long u = r ^ c.first;
      ans += (c.second * m1[u]);
    }
  } else {
    long long r = 0, a1 = 0, a2 = 0;
    for (auto c : m1) {
      a1 += c.second;
      if (c.second % 2 != 0) r ^= c.first;
    }
    if (r == 0) {
      ans += a1 * (a1 - 1) / 2;
      a2 = 0;
      for (auto c : m2) a2 += c.second;
      ans += (a2 * (a2 - 1)) / 2;
    }
    for (auto c : m1) {
      long long u = r ^ c.first;
      ans += (c.second * m2[u]);
    }
  }
  cout << ans;
  return 0;
}
